https://github.com/vyfor/groq-kt
📦 Kotlin Multiplatform library for the Groq API
https://github.com/vyfor/groq-kt
android groq groq-api groq-integration javascript js jvm kmp kotlin kotlin-native multiplatform native sdk sdk-kotlin
Last synced: 6 months ago
JSON representation
📦 Kotlin Multiplatform library for the Groq API
- Host: GitHub
- URL: https://github.com/vyfor/groq-kt
- Owner: vyfor
- License: mit
- Created: 2024-11-06T05:05:57.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-01-27T21:46:03.000Z (8 months ago)
- Last Synced: 2025-04-10T21:12:32.493Z (6 months ago)
- Topics: android, groq, groq-api, groq-integration, javascript, js, jvm, kmp, kotlin, kotlin-native, multiplatform, native, sdk, sdk-kotlin
- Language: Kotlin
- Homepage: https://central.sonatype.com/artifact/io.github.vyfor/groq-kt
- Size: 141 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# 📚 Groq Kotlin Library

**An idiomatic [Kotlin Multiplatform](https://kotlinlang.org/docs/multiplatform.html) library for the [Groq](https://groq.com/) API.**
## 💎 Features
- 🚀 Built with [Ktor](https://ktor.io/) for seamless networking
- 🎨 Complete and documented API for chat completions, audio transcription, and translation, including tool support and function calling
- ⚡ Real-time streaming responses via Kotlin Flows
- 🧩 Rich, idiomatic DSL for clean and expressive syntax
- 🔒 Ensures required validations are met before request submission
- 🔧 Allows specifying default values for API requests in client configuration
- ⏳ Automatically handles rate limiting and retries on failed requests
- 📱 Supports multiple platforms:
- Android
- iOS
- JavaScript
- JVM
- Linux
- macOS
- Windows
- WebAssembly
- tvOS, watchOS## 🔌 Requirements
- Java 8 or higher (only for use within the JVM environment)## ⚙️ Installation
Add these dependencies to your project:
```kotlin
dependencies {
implementation("io.github.vyfor:groq-kt:0.1.0")
/* required */
implementation("io.ktor:ktor-client-$engine:$version")
}
```For the list of supported engines, see [Ktor Client Engines](https://ktor.io/docs/client-engines.html#platforms).
## 🧩 Usage
### Initialization
```kotlin
/* It is recommended to use an environment variable for the API key */
val apiKey = System.getenv("GROQ_API_KEY") // JVM
val apiKey = process.env.GROQ_API_KEY // JS
val apiKey = getenv("GROQ_API_KEY")!!.toKString() // Nativeval client = GroqClient(apiKey)
```### Specifying default values
You can configure default values for requests. These values will be automatically applied to every request made with a DSL function.
```kotlin
val client = GroqClient(apiKey) {
defaults {
chatCompletion {
model = GroqModel.LLAMA_3_8B_8192
}
audioTranscription {
format = AudioResponseFormat.VERBOSE_JSON
}
}
}
```### Chat completion
```kotlin
val response = client.chat {
model = GroqModel.LLAMA_3_8B_8192messages {
system("You are a helpful assistant.")
text("What is the capital of Germany?")
}
}
```### Streaming
```kotlin
val response = client.chatStreaming {
model = GroqModel.LLAMA_3_2_90B_VISION_PREVIEWmessages {
user(
"Describe what you see in the image.",
"https://example.com/image.png"
)
}
}.data.collect { chunk ->
println(chunk)
}
```### Audio transcription
```kotlin
val response = client.transcribe {
model = GroqModel.DISTIL_WHISPER_LARGE_V3_ENfile("path/to/audio.mp3")
/* or */
url = "https://example.com/audio.mp3"
}
```### Audio translation
> [!NOTE]
> Does not seem to be supported by the API yet.
```kotlin
val response = client.translate {
model = GroqModel.DISTIL_WHISPER_LARGE_V3_ENfile("path/to/audio.mp3")
/* or */
url = "https://example.com/audio.mp3"
}
```## ⚖️ License
`groq-kt` is licensed under the [MIT License](./LICENSE).The project is not affiliated with [Groq](https://groq.com/) in any way.
## 📚 Documentation
The REST API documentation can be found on [console.groq.com](https://console.groq.com/docs).
## 🌱 Contributing
This project is in beta and hasn't undergone excessive testing. Contributions of any kind are welcome, just make sure you read the [Contribution Guidelines](./.github/CONTRIBUTING.md) first. You can also contact me directly on Discord (**[vyfor](https://discord.com/users/446729269872427018)**) if you have any questions.