Retour au classement

aallam/openai-kotlin

Kotlin

OpenAI API client for Kotlin with multiplatform and coroutines capabilities.

openaikotlinclientmultiplatformcoroutinesapichatgptdall-ellmwhispergpt
Croissance des étoiles
Étoiles
1.8k
Forks
235
Croissance hebdomadaire
Issues
60
5001k1.5k
févr. 2023mars 2024mai 2025juil. 2026
README

OpenAI API client for Kotlin

Maven Central License Documentation

Kotlin client for OpenAI's API with multiplatform and coroutines capabilities.

📦 Setup

  1. Install OpenAI API Kotlin client by adding the following dependency to your build.gradle file:
repositories {
    mavenCentral()
}

dependencies {
    implementation "com.aallam.openai:openai-client:4.1.0"
}
  1. Choose and add to your dependencies one of Ktor's engines.

BOM

Alternatively, you can use openai-client-bom by adding the following dependency to your build.gradle file

dependencies {
    // import Kotlin API client BOM
    implementation platform('com.aallam.openai:openai-client-bom:4.1.0')

    // define dependencies without versions
    implementation 'com.aallam.openai:openai-client'
    runtimeOnly 'io.ktor:ktor-client-okhttp'
}

Multiplatform

In multiplatform projects, add openai client dependency to commonMain, and choose an engine for each target.

Maven

Gradle is required for multiplatform support, but there's nothing stopping you from using the jvm client in a Maven project. You still need to add to your dependencies one of Ktor's engines.

Setup the client with maven
<dependencies>
    <dependency>
        <groupId>com.aallam.openai</groupId>
        <artifactId>openai-client-jvm</artifactId>
        <version>4.1.0</version>
    </dependency>
            
    <dependency>
        <groupId>io.ktor</groupId>
        <artifactId>ktor-client-okhttp-jvm</artifactId>
        <version>3.0.0</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>

The BOM is not supported for Maven projects.

⚡️ Getting Started

[!NOTE] OpenAI encourages using environment variables for the API key. Read more.

Create an instance of OpenAI client:

val openai = OpenAI(
    token = "your-api-key",
    timeout = Timeout(socket = 60.seconds),
    // additional configurations...
)

Or you can create an instance of OpenAI using a pre-configured OpenAIConfig:

val config = OpenAIConfig(
    token = apiKey,
    timeout = Timeout(socket = 60.seconds),
    // additional configurations...
)

val openAI = OpenAI(config)

Use your OpenAI instance to make API requests. Learn more.

Supported features

Beta

Deprecated

Looking for a tokenizer? Try ktoken, a Kotlin library for tokenizing text.

📚 Guides

Get started and understand more about how to use OpenAI API client for Kotlin with these guides:

ℹ️ Sample apps

Sample apps are available under sample, please check the README for running instructions.

🔒 ProGuard / R8

The specific rules are already bundled into the Jar which can be interpreted by R8 automatically.

📸 Snapshots

Snapshot

Learn how to import snapshot version

To import snapshot versions into your project, add the following code snippet to your gradle file:

repositories {
   //...
   maven { url 'https://central.sonatype.com/repository/maven-snapshots/' }
}

🛠️ Troubleshooting

For common issues and their solutions, check the Troubleshooting Guide.

🧪 Testing

openai-client tests are live integration tests and can generate billable API traffic.

  • Default (non-billable): live tests are disabled.
  • Opt-in live tests: set OPENAI_LIVE_TESTS=1 and OPENAI_API_KEY.

Examples:

# Free/offline checks
./gradlew :openai-core:jvmTest :openai-core:jsTest :openai-core:wasmJsTest :openai-core:apiCheck :openai-client:apiCheck

# Live smoke (billable)
OPENAI_LIVE_TESTS=1 OPENAI_API_KEY=... ./gradlew :openai-client:jvmTest --tests "*.TestModels"

⭐️ Support

Appreciate the project? Here's how you can help:

  1. Star: Give it a star at the top right. It means a lot!
  2. Contribute: Found an issue or have a feature idea? Submit a PR.
  3. Feedback: Have suggestions? Open an issue or start a discussion.

📄 License

OpenAI Kotlin API Client is an open-sourced software licensed under the MIT license. This is an unofficial library, it is not affiliated with nor endorsed by OpenAI. Contributions are welcome.

Dépôts similaires
NousResearch/hermes-agent

The agent that grows with you

PythonPyPIMIT Licenseaiai-agent
hermes-agent.nousresearch.com
218.5k41.3k
Significant-Gravitas/AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

PythonPyPIOtheraiopenai
agpt.co
185.6k46.1k
microsoft/markitdown

Python tool for converting files and office documents to Markdown.

PythonPyPIMIT Licenselangchainopenai
168k12.1k
f/prompts.chat

f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.

HTMLOtherchatgptai
prompts.chat
166.2k21.5k
langgenius/dify

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

TypeScriptnpmOtheraigpt
dify.ai
149.7k23.6k
open-webui/open-webui

User-friendly AI Interface (Supports Ollama, OpenAI API, ...)

PythonPyPIOtherollamaollama-webui
openwebui.com
146.3k21.2k
langchain-ai/langchain

The agent engineering platform.

PythonPyPIMIT Licenseaianthropic
docs.langchain.com/langchain/
142.3k23.7k
microsoft/generative-ai-for-beginners

21 Lessons, Get Started Building with Generative AI

Jupyter NotebookMIT Licenseaichatgpt
113.3k60.8k
vllm-project/vllm

A high-throughput and memory-efficient inference and serving engine for LLMs

PythonPyPIApache License 2.0gptllm
vllm.ai
86.8k19.7k
OpenHands/OpenHands

🙌 OpenHands: AI-Driven Development

PythonPyPIOtheragentartificial-intelligence
openhands.dev
81.6k10.4k
lobehub/lobehub

🤯 LobeHub is your Chief Agent Operator, organizing your agents into 7×24 operations by hiring, scheduling, and reporting on your entire AI team.

TypeScriptnpmOtherchatgptopenai
lobehub.com
80.6k15.7k
dair-ai/Prompt-Engineering-Guide

🐙 Guides, papers, lessons, notebooks and resources for prompt engineering, context engineering, RAG, and AI Agents.

MDXMIT Licensedeep-learningprompt-engineering
promptingguide.ai
76.8k8.4k