explaingit

androidpoet/openai-kmp

11KotlinAudience · developerComplexity · 3/5ActiveLicenseSetup · moderate

TLDR

Kotlin Multiplatform SDK for the OpenAI APIs. Builds on Ktor, ships as fourteen small modules per endpoint family, and targets Android, JVM, iOS, macOS, Linux, Windows, and WasmJs.

Mindmap

mindmap
  root((openai-kmp))
    Inputs
      OpenAI API key
      Chat or embedding requests
      Audio and image files
    Outputs
      Typed result objects
      Streamed WebSocket events
      Embeddings and images
    Use Cases
      Add OpenAI to a KMP app
      Share code between Android and iOS
      Pick only the needed endpoint modules
      Build a desktop or Wasm client
    Tech Stack
      Kotlin
      Ktor
      Gradle
      Maven Central

Things people build with this

USE CASE 1

Call OpenAI chat completions from shared Kotlin code in an Android plus iOS app

USE CASE 2

Add embeddings and vector store APIs only, keeping the binary small

USE CASE 3

Use the realtime WebSocket module from a desktop Kotlin client

USE CASE 4

Run image and audio endpoints from a Wasm or Linux x64 target

Tech stack

KotlinKtorGradleMaven

Getting it running

Difficulty · moderate Time to first run · 1h+

Needs a Kotlin Multiplatform Gradle project plus an OpenAI API key, and you must add a separate module per endpoint family.

MIT license, use freely in commercial and personal projects with attribution.

In plain English

openai-kmp is a Kotlin Multiplatform SDK for the OpenAI APIs. The point of being multiplatform is that the same Kotlin code can be compiled for many targets: Android, JVM, iOS in several CPU variants, macOS, tvOS, watchOS, Linux x64, Windows mingw x64, and WasmJs. The transport layer is built on Ktor, and the SDK is published to Maven Central. Instead of one giant artifact, the project is split into about fourteen small modules. openai-core holds shared error and list contracts, and openai-client provides the HTTP transport, configuration, and JSON or multipart plumbing. On top of that sit one module per OpenAI endpoint family: chat completions, responses, embeddings, files, batches, models, moderations, images, audio, realtime over WebSocket, fine-tuning, vector stores, and multipart upload sessions. You pick only the modules your app needs, which keeps binaries small. The Gradle version catalog snippet in the README pins everything to a single openai-kmp version reference so all modules move together. In your commonMain source set you depend on openai-client plus whichever endpoint modules you want. A client is built with OpenAI.create, passing an api key from an environment variable plus optional settings like logging, a timeout in milliseconds, and OpenAI organization and project IDs. From the client you call accessor methods such as client.chat(), client.responses(), client.embeddings(), client.images(), client.audio(), client.fineTuning(), client.vectorStores(), and client.uploads(), each of which exposes typed request methods like createTyped or generateTyped. Results are returned as an outcome object rather than being thrown. You call onSuccess and onFailure on it, where the failure side gives you a status code and message. The project is MIT licensed.

Copy-paste prompts

Prompt 1
Add openai-kmp to a Kotlin Multiplatform project using the Gradle version catalog, including only openai-client and chat modules
Prompt 2
Create an OpenAI client with OpenAI.create that reads the key from OPENAI_API_KEY and sets a 30 second timeout
Prompt 3
Call client.chat() with a typed request from commonMain and handle the result with onSuccess and onFailure
Prompt 4
Build a SwiftUI screen that calls into a shared Kotlin function using openai-kmp embeddings
Prompt 5
Wire client.audio() to transcribe a local wav file from a JVM target with openai-kmp
Open on GitHub → Explain another repo

Generated 2026-05-22 · Model: sonnet-4-6 · Verify against the repo before relying on details.