
OpenAI-first client wrapping REST and streaming APIs with typed request/response models, streaming helpers for incremental assembly, and guarded compatibility paths for OpenAI-like providers.
kotlin-web-openai is an OpenAI-first Kotlin Multiplatform client for OpenAI's REST and streaming APIs.
It wraps the current OpenAI platform surface behind typed request and response models built on Ktor and kotlinx.serialization, while keeping provider-specific escape hatches explicit instead of silently weakening the main API.
OpenAI parity is the priority. The library also includes guarded compatibility support for sufficiently OpenAI-like providers such as OpenRouter, Ollama, Azure OpenAI, Groq, xAI, DeepSeek, Anthropic compatibility, and Gemini compatibility, but those paths are best-effort rather than the primary contract.
Current release:
dependencies {
implementation("one.wabbit:kotlin-web-openai:0.0.1")
}The client is Ktor-based and takes an HttpClient, so you supply transport configuration appropriate for your target.
Current project floors and targets:
2.3.10
21 to build the projectminSdk 26
Transport shape:
3.3.x
kotlinx.serialization 1.9.x
HttpClient
API coverage highlights:
The snippet below is mirrored by ReadmeExamplesTest.kt.
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import one.wabbit.web.openai.KtorOpenAIApi
import one.wabbit.web.openai.ModelId
import one.wabbit.web.openai.OpenAIApi
import one.wabbit.web.openai.ResponseCreateRequest
import one.wabbit.web.openai.ResponseInput
suspend fun main() {
val api =
KtorOpenAIApi(
client = HttpClient(CIO),
config =
OpenAIApi.Config(
apiKey = requireNotNull(System.getenv("OPENAI_API_KEY")),
),
)
val response =
api.createResponse(
ResponseCreateRequest(
model = ModelId("gpt-5.4-mini"),
input = ResponseInput.Text("Say hello in one short sentence."),
),
)
println(response.outputText())
}This snippet is also mirrored by ReadmeExamplesTest.kt.
import one.wabbit.web.openai.ModelId
import one.wabbit.web.openai.OpenAIApi
import one.wabbit.web.openai.ResponseCreateRequest
import one.wabbit.web.openai.ResponseInput
import one.wabbit.web.openai.collectResponseStream
suspend fun summarize(api: OpenAIApi, prompt: String): String {
val assembly =
api.streamResponse(
ResponseCreateRequest(
model = ModelId("gpt-5.4-mini"),
input = ResponseInput.Text(prompt),
),
).collectResponseStream()
return assembly.outputText
}If a stream produces more than one assistant output part, use the structured helpers such as assembly.outputTexts instead of the singleton-only outputText shortcut.
Support level:
Public support path:
wabbit@wabbit.oneWhen filing issues, include the provider, model, request shape, and any x-request-id or client request ID available from the failing call.
AGPL-3.0-or-later. See LICENSE.md.
kotlin-web-openai is an OpenAI-first Kotlin Multiplatform client for OpenAI's REST and streaming APIs.
It wraps the current OpenAI platform surface behind typed request and response models built on Ktor and kotlinx.serialization, while keeping provider-specific escape hatches explicit instead of silently weakening the main API.
OpenAI parity is the priority. The library also includes guarded compatibility support for sufficiently OpenAI-like providers such as OpenRouter, Ollama, Azure OpenAI, Groq, xAI, DeepSeek, Anthropic compatibility, and Gemini compatibility, but those paths are best-effort rather than the primary contract.
Current release:
dependencies {
implementation("one.wabbit:kotlin-web-openai:0.0.1")
}The client is Ktor-based and takes an HttpClient, so you supply transport configuration appropriate for your target.
Current project floors and targets:
2.3.10
21 to build the projectminSdk 26
Transport shape:
3.3.x
kotlinx.serialization 1.9.x
HttpClient
API coverage highlights:
The snippet below is mirrored by ReadmeExamplesTest.kt.
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import one.wabbit.web.openai.KtorOpenAIApi
import one.wabbit.web.openai.ModelId
import one.wabbit.web.openai.OpenAIApi
import one.wabbit.web.openai.ResponseCreateRequest
import one.wabbit.web.openai.ResponseInput
suspend fun main() {
val api =
KtorOpenAIApi(
client = HttpClient(CIO),
config =
OpenAIApi.Config(
apiKey = requireNotNull(System.getenv("OPENAI_API_KEY")),
),
)
val response =
api.createResponse(
ResponseCreateRequest(
model = ModelId("gpt-5.4-mini"),
input = ResponseInput.Text("Say hello in one short sentence."),
),
)
println(response.outputText())
}This snippet is also mirrored by ReadmeExamplesTest.kt.
import one.wabbit.web.openai.ModelId
import one.wabbit.web.openai.OpenAIApi
import one.wabbit.web.openai.ResponseCreateRequest
import one.wabbit.web.openai.ResponseInput
import one.wabbit.web.openai.collectResponseStream
suspend fun summarize(api: OpenAIApi, prompt: String): String {
val assembly =
api.streamResponse(
ResponseCreateRequest(
model = ModelId("gpt-5.4-mini"),
input = ResponseInput.Text(prompt),
),
).collectResponseStream()
return assembly.outputText
}If a stream produces more than one assistant output part, use the structured helpers such as assembly.outputTexts instead of the singleton-only outputText shortcut.
Support level:
Public support path:
wabbit@wabbit.oneWhen filing issues, include the provider, model, request shape, and any x-request-id or client request ID available from the failing call.
AGPL-3.0-or-later. See LICENSE.md.