Skip to content

Generate a Kotlin SDK for your API

Octri generates a Kotlin client for your API with data classes and named arguments on OkHttp or Ktor, publishes it to Maven Central under your own coordinates, and regenerates it whenever your API changes.

Start from scratch

Or upload a file: OpenAPI 3.0 or 3.1, Swagger 2.0, Postman or AsyncAPI.

Install from Maven Central
dependencies {
    implementation("com.acme:acme-api-kotlin:1.0.0")
}

The Kotlin API client your users get

What your users write once the Kotlin package is installed.

Two call styles come out of the same generator. class-namespaced is the default: one client object with operations grouped by resource, the shape most popular SDKs use and the one your API reference already shows. functions is the alternative: no client object, one configure call, and each operation imported on its own. It is one setting per language, and nothing else about the client changes with it.

Optional parameters are Kotlin default arguments, so callers name only what they set. On the default OkHttp engine the calls block; pick Ktor and every operation becomes a suspend function.

Same coordinates and the same groupId check as Java, since both land on Maven Central. Most teams publish the two under one groupId with different artifactIds.

Kotlin
import acmeapi.*

val acme = Acme(ClientConfig(
    baseUrl = "https://api.acme.com/v1",
    auth = ClientAuthConfig(bearer = System.getenv("ACME_TOKEN")),
))

// The trailing lambda gets each item. Return false to stop paging.
acme.users.listPaginated(limit = 100) { user ->
    println(user.id)
    true
}

val invoice = acme.invoices.create(customerId = "cus_123", amountCents = 4900)

The Kotlin SDK at a glance

What a developer checks before adding the Kotlin package to a project.

Runs on
The JVM, built with a Java 21 toolchain
Transport
OkHttp by default, Ktor CIO as an option
Runtime dependencies
OkHttp or Ktor, plus jackson-module-kotlin
Models
Data classes with nullable optional fields
Pagination
Trailing lambda that returns false to stop
Ships to
Maven Central, consumed from Gradle or Maven

When a call fails

SdkError is a sealed class, so a when over it is exhaustive and the compiler tells your users about a case they skipped. Declared error models arrive decoded on e.data, ready for an is check.

Typed errors
try {
    val invoice = acme.invoices.create(customerId = "cus_123", amountCents = 4900)
} catch (e: SdkRateLimitError) {
    // 429 after the built-in retries. Schedule it for later.
} catch (e: SdkHttpError) {
    logger.error("acme failed: status=${e.statusCode} request=${e.requestId}")
}

Configure your Kotlin SDK

Kotlin and TypeScript are the two languages with an HTTP engine choice, and on Kotlin it also decides whether calls suspend.

  • HTTP engine

    okhttp (default), ktor

    OkHttp is already on the classpath of most Android apps and JVM services, and its calls block. Ktor brings kotlinx-coroutines, and with it every operation, including the paginated ones, becomes a suspend function.

  • Client style

    class-namespaced (default), class, namespaced, functions

    A client class with a property per resource. The functions style emits an object per resource, Users.listUsers(), for teams that prefer no client instance.

  • Argument style

    positional (default), object

    Named, defaulted parameters, which is the Kotlin idiom and keeps call sites readable without a builder. Object wraps them in a request class.

  • Doc comments

    full (default), minimal

    Full carries your API’s descriptions into KDoc, which Android Studio and IntelliJ show on hover.

Method naming and namespacing work the same in every language: operations are grouped by your API’s tags or by path, and the namespace word is dropped from the method name unless you ask to keep the operationId whole.

Publishing to Maven Central: give Kotlin its own artifactId

Java and Kotlin both publish to Maven Central, usually under the same verified groupId, and two packages cannot share one set of coordinates. Set a Kotlin package name such as com.acme:acme-api-kotlin before the first release. Coordinates on Maven Central are permanent, and a release there can never be deleted or replaced.

Maven Central coordinates
com.acme:acme-api-kotlin
  • Not possible: Share coordinates with the Java SDK
  • Not possible: Delete or replace a release
  • Still possible: Relocate users to new coordinates

Retries, pagination and typed errors, built in

The parts nobody wants to hand-write, and the parts a hand-written client usually skips.

  • Retries with exponential backoff and jitter, on the statuses that mean "try again", with a per-attempt timeout.
  • Idempotency keys on the methods that need them, so a retried write does not become two.
  • Auth wired in from your API’s security schemes, read from wherever your users keep secrets.
  • Typed errors split by cause: a failed constraint, an HTTP status, a network failure and a timeout are four different things.
  • Pagination that follows whichever style your API uses, cursor, offset, page number or next URL, without prefetching the collection.
  • Server-sent events as a native stream, for the operations that stream.
  • Error reporting to Octri’s monitoring, pre-wired and switched off until a consumer opts in.
  1. Add your API

    Upload an OpenAPI or Swagger file, paste a URL, connect the repository it lives in, or add endpoints in the editor.

  2. Read the audit

    Octri scores your API out of 10 on what a generator can do with it and names every missing schema and clashing operationId. 8 of the 14 rules come with a button that writes the fix.

  3. Shape the client

    Client style, argument style, namespacing, auth, retries and pagination, set once for the project and overridden per language or per endpoint.

  4. Generate and read it

    The package is generated, compiled and handed to you as source you can read before anyone installs it.

  5. Publish, then keep publishing

    Release to the registry under your own account. Every later change to your API regenerates the client, and the version number follows the version your API declares.

Kotlin SDK generator questions

OpenAPI Generator’s Kotlin client defaults to OkHttp with Moshi and also offers Ktor, Retrofit and multiplatform variants. Fabrikt generates data classes, clients and server controllers from OpenAPI 3. Both leave building and publishing to you. Octri generates a Kotlin client on OkHttp or Ktor, publishes it to Maven Central under your coordinates, and regenerates it when your API changes.