Lightweight ChatGPT Kotlin SDK with spring-boot-starter

ChatGPT Kotlin SDK

This SDK provides a Kotlin API for the OpenAI Chat API powered by GPT. With this SDK, you can easily integrate OpenAI chat capabilities into your Kotlin applications.


  • JDK 11 or later
  • API key from OpenAI


The SDK can be installed using Gradle or Maven.


Add the following to your build.gradle file:

dependencies {
    implementation 'com.github.yahorbarkouski:chatgpt-kotlin:1.0.0'


Add the following to your pom.xml file:



The SDK provides a ChatGptClient class that can be used to interact with the OpenAI chat API. Here is an example of how to use the SDK:

import com.github.yahorbarkouski.chatgpt.ChatGptClient
import com.github.yahorbarkouski.chatgpt.ChatModel
import com.github.yahorbarkouski.chatgpt.ChatMessage

fun main() {
    val apiKey = "your-api-key-here"
    val client = ChatGptClient(apiKey)

    val messages = listOf(
        ChatMessage("user", "Hello!"),
        ChatMessage("system", "Hi, how can I help you today?")

    val response = client.complete(messages, ChatModel.GPT_3_5_TURBO)

    if (response.isSuccessful) {
        val result = response.body()!!.choices.first().text
        println("Response: $result")
    } else {
        println("Error: ${response.message()}")


Contributions to this project are welcome. If you find a bug or want to add a feature, please open an issue or submit a pull request.


This project is licensed under the MIT License.


View Github

Leave a Reply

Your email address will not be published. Required fields are marked *