rosuH / openai-kotlin

OpenAI API client for Kotlin with multiplatform and coroutines capabilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpenAI API client for Kotlin

Maven Central License Kotlin 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 gradle.build file:
repositories {
    mavenCentral()
}

dependencies {
    implementation "com.aallam.openai:openai-client:<version>"
}
  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 gradle.build file

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

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

Multiplaform

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

⚡️ Getting Started

Create an instance of OpenAI client:

val openAI = OpenAI(apiKey)

Note: OpenAI encourages using environment variables for the API key. Read more.

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

Supported features

ℹ️ Sample apps

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

📄 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.

About

OpenAI API client for Kotlin with multiplatform and coroutines capabilities.

License:MIT License


Languages

Language:Kotlin 100.0%