Kotlin
Generate production-ready Kotlin SDKs from your OpenAPI specification
The Stainless Kotlin SDK generator creates idiomatic, type-safe Kotlin client libraries from your OpenAPI specification.
Example repositories:
- dodopayments/dodopayments-kotlin
- lithic-com/lithic-kotlin
- Modern-Treasury/modern-treasury-kotlin
- Finch-API/finch-api-kotlin
Configuration
Section titled “Configuration”To generate a Kotlin SDK, add the kotlin target to your Stainless configuration file:
targets: kotlin: reverse_domain: com.example.api edition: kotlin.2025-10-08Common configuration options
Section titled “Common configuration options”targets: kotlin: reverse_domain: com.example.api
# Specify the edition edition: kotlin.2025-10-08
# Configure publishing publish: maven: sonatype_platform: portal # or: ossrhFor a complete list of configuration options, see the Kotlin target reference.
Editions
Section titled “Editions”Editions allow Stainless to make improvements to SDKs that aren’t backwards-compatible. You can explicitly opt in to new editions when you’re ready. See the SDK and config editions reference for more information.
kotlin.2025-10-08
- Initial edition for Kotlin (used by default if no edition is specified)
Publishing to Maven Central
Section titled “Publishing to Maven Central”Publish your Kotlin SDK to Sonatype Maven Central for distribution. Sonatype has both a legacy (OSSRH) publishing flow and a new Central Portal publishing flow. (The Java target uses the same Maven Central publishing process.)
If you do not already publish to OSSRH, use the new Central Portal publishing flow. If you are already publishing to OSSRH, you can continue to do so.
Update your Stainless config (Central Portal only)
For backwards compatibility, the default sonatype_platform is ossrh. If you are using the Central Portal, update the Stainless config to portal:
targets: kotlin: reverse_domain: com.example.api publish: maven: sonatype_platform: portalRegister a namespace (Central Portal only)
A namespace uniquely identifies your organization and becomes the prefix of the Maven packages (groupId) you publish.
It must be the reverse-DNS form of a domain you own (e.g., the domain api.example.com becomes the namespace com.example.api).
The namespace must match the domain exactly and in a future step, Sonatype will verify your ownership of the domain.
For more details, see the Sonatype documentation.
-
Log in or sign up at Sonatype Central Portal.
-
Navigate to Publish > Namespaces.
-
Register a new namespace by clicking the Register New Namespace button and setting the namespace.
-
Copy the Verification Key
Sonatype provides a verification key that you’ll use to prove ownership of the domain backing your namespace.
Verify domain ownership
Central Portal flow: Use the verification key provided by Sonatype as the TXT record value.
OSSRH (JIRA-based) flow:
Use the JIRA ticket ID (e.g., OSSRH-12345) as the TXT record value.
-
Add a temporary DNS TXT record on the domain that corresponds to the reverse-DNS namespace you registered. This DNS record proves you control the domain your namespace (and
groupId) is based on. -
From the Publish > Namespaces page, click on your namespace and verify that the TXT record is set.
Generate user token and add to GitHub secrets (Central Portal only)
-
From the Sonatype Central Portal dashboard, generate a user token. Set the token name and expiration date as appropriate.
-
Copy the Username and Password values.
-
In your production repo, navigate to Secrets and variables > Actions > New repository secret. The URL should look like
https://github.com/<org>/<repo>/settings/secrets/actions/new. -
Add the following secrets:
-
SONATYPE_USERNAME: Paste the username you copied. -
SONATYPE_PASSWORD: Paste the password (user token) you copied.
Generate a PGP key
-
Install GnuPG.
-
In a terminal, run
gpg --gen-key. Enter your name, email, and a passphrase for the keypair.
-
Run
gpg --list-keys --keyid-format short:Terminal window % gpg --list-keys --keyid-format short[keyboxd]---------pub ed25519/7FAD9FAA 2023-08-02 [SC] [expires: 2026-08-01]418D41921938A753CAAE57985114AD037FAD9FAAuid [ultimate] Your Organization <you@yourorg.com>sub cv25519/07EB38A7 2023-08-02 [E] [expires: 2026-08-01] -
Export the key in ASCII-armored format. In the above example, the short key ID is
7FAD9FAA.Terminal window $ gpg --export-secret-keys --armor 7FAD9FAA-----BEGIN PGP PRIVATE KEY BLOCK-----lIYEZMpnEhYJKwYBBAHaRw8BAQdA1FQMKz+wwliKNdLehegZP0QiaKrZJqADNyVnVCUzIrD+BwMCwZrqVbVPfSr8NwxEh3M6kWtMGmnLMOk/NWVe7dtCxDxo37l/NcxjMm9EZiH6WXwoXXq20nOW354oNOVz/UPvDU+oaRDDUM9SYs392i69WLQjWW91ciBPcmdhbml6YXRpb24gPHlvdUB5b3Vyb3JnLmNvbT6ImQQTFgoAQRYhBEGNQZIZOKdTyq5XmFEUrQN/rZ+qBQJkymcSAhsDBQkFo5qABQsJCAcCAiICBhUKCQgLAgQWAgMBAh4HAheAAAoJEFEUrQN/rZ+qgtsBAMCBuTqYEJljxStRO7SsMLWOc47CIIXD0YidCbySBX0ZAP9DXuuGVYbHFONvHxNKszu2hY9A1BbRuNjeGeWuVOw9ApyLBGTKZxISCisGAQQBl1UBBQEBB0AFxkZ+ZdEN7Epwri/w5ETAf+MOqdwAP2sS6TccSjEiXQMBCAf+BwMCtKG1TBUSC/z8tn761I5j+ifVIuMqdQPYIhZtjvIyC+NyrBi0j1ZtUG4ADAeDKNyM63uyb7omOH8+Lu0J71SGhVnZWszUOf3rrT/TA5MktYh+BBgWCgAmFiEEQY1Bkhk4p1PKrleYURStA3+tn6oFAmTKZxICGwwFCQWjmoAACgkQURStA3+tn6qaXAD/W2ucVURngmCUiUtdjQAZz36yQYPQmBhcdabZMyXKHz0A/itwYkuRbD2mp4p/xJk/QLXs/2/xBA6s0ROVVspy6MEA=p/g/-----END PGP PRIVATE KEY BLOCK----- -
Publish your PGP public key.
Terminal window $ gpg --keyserver keyserver.ubuntu.com --send-keys 7FAD9FAAIf you get the following error:
gpg: sending key XXXXXX to hkp://keyserver.ubuntu.comgpg: keyserver send failed: No route to hostthen your computer might be trying to use IPv6 and failing. Run the following to get keyserver.ubuntu.com’s IPv4 addresses:
Terminal window $ host keyserver.ubuntu.comkeyserver.ubuntu.com has address XXX.XXX.XXX.XXkeyserver.ubuntu.com has address XXX.XXX.XXX.XXkeyserver.ubuntu.com has IPv6 address XXXX:XX:XXXX:XXXX::XXXkeyserver.ubuntu.com has IPv6 address XXXX:XX:XXXX:XXXX::XXXThen rerun the
gpgcommand with one of the IPv4 addresses:Terminal window $ gpg --keyserver XXX.XXX.XXX.XX --send-keys 7FAD9FAA
Add secrets to your production repo
- In the production repo, navigate to Secrets and variables > Actions > New repository secret.
The URL should look like
https://github.com/<org>/<repo>/settings/secrets/actions/new. - Add the following secrets:
-
GPG_SIGNING_PASSWORD: the passphrase you entered when creating the keypair. -
GPG_SIGNING_KEY: your PGP private key. It should be the entire output ofgpg --export-secret-keys --armor <keyid>. -
SONATYPE_USERNAME: username for your Sonatype account. -
SONATYPE_PASSWORD: password for your Sonatype account (OSSRH) or your Sonatype user token (Central Portal).