Kotlin Multiplatform port of Vercel AI SDK v6 patterns and public feature areas.
This is a green-room Kotlin rewrite of the architectural contracts, not a TypeScript source translation and not an official Vercel package.
- Common Kotlin API for shared agent code.
- Android library publication.
- iOS static framework publication for
iosX64,iosArm64, andiosSimulatorArm64. - JVM artifact for backend and desktop services.
Until the first release is published, use a source dependency or publishToMavenLocal:
./gradlew publishToMavenLocaldependencies {
implementation("ai.torad:aisdk-kotlin:0.1.0-SNAPSHOT")
}import ai.torad.aisdk.ToolLoopAgent
import ai.torad.aisdk.stepCountIs
import ai.torad.aisdk.tool
import ai.torad.aisdk.toolSetOf
import ai.torad.aisdk.providers.MockLanguageModel
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
@Serializable
data class EmptyInput(val unused: String = "")
val helloTool = tool<EmptyInput, String, Unit>(
name = "hello",
description = "Return a greeting.",
inputSerializer = serializer(),
outputSerializer = serializer(),
) { "Hello from a tool." }
val agent = ToolLoopAgent<Unit, String>(
model = MockLanguageModel.textOnly("Welcome."),
instructions = "Be brief.",
tools = toolSetOf(helloTool),
stopWhen = stepCountIs(3),
)AgentandToolLoopAgent.- Typed
tool()definitions,dynamicTool(), schemas, andToolSet. generateText,streamText, and coldFlow<StreamEvent>streaming.- Structured output through
Output.obj,Output.array,Output.choice, andOutput.json. - Deprecated v6 compatibility shims:
generateObjectandstreamObject. - Embeddings, reranking, image generation, speech generation, transcription, and video generation model contracts.
- Provider registry and
customProviderrouting. - Gateway facade with
createGateway,gateway, gateway metadata APIs, gateway errors, provider-executed gateway tool descriptors, and a Ktor-backedKtorGatewayTransport. - OpenAI-compatible Ktor provider for chat, completions, embeddings, images, speech, and transcription through
createOpenAICompatible. - Provider-utils parity helpers: schemas, IDs, JSON event stream parsing, headers, base64 byte helpers, media and URL validation utilities.
- Text stream, UI message stream, and chat transport primitives for Kotlin hosts.
- Telemetry helpers, global/local telemetry integrations, and a KMP tracer/span abstraction.
- Compatibility helpers such as
DefaultGeneratedFile,pruneMessages, experimental media aliases, and v6 public error types. - Lifecycle hooks, middleware, stop conditions, call/step preparation, and cancellation.
- UI message aggregation types for Compose, SwiftUI, or server-rendered hosts.
- Mock models for deterministic tests across every model family.
Provider facades for the AI SDK v6 package ecosystem are folded into this root artifact for now. Future aisdk-provider-* artifacts can split publication boundaries without changing the common contracts.
- Docs wiki
- Local LLM context
- Interface contract
- Port notes
- Architecture decisions
- Parity ledgers
- Kotlin SDK engineering standard
Use JDK 21 to build the project. JVM and Android bytecode target JVM 17.
./gradlew jvmTest
./gradlew check publishToMavenLocalAndroid publication requires an Android SDK with compile SDK 36 installed.
Apache-2.0. See LICENSE.