
AI client enables interaction with OpenAI's API, supporting features like chat, images, and embeddings. Offers multiplatform capabilities, utilizing coroutines, and provides extensive guides and setup instructions.
Android and Kotlin Multiplatform (KMP) client for accessing different AI providers (OpenAI, Claude...) directly or with API key protection through Gateway's servers
gemini-2.5-flash-image-preview modelThe Gateway client supports the following AI service providers (see
Gateway.kt):
For KMP projects, add to your commonMain dependencies in your shared module's
build.gradle.kts:
commonMain.dependencies {
implementation("io.github.brahyam:gateway-client:0.4.0")
}For Android-only projects, add to your build.gradle:
dependencies {
implementation("io.github.brahyam:gateway-client:0.4.0")
}For KMP, configure Gateway in your shared code (e.g., RootComponent, MainViewModel, or app
startup):
import io.github.brahyam.gateway.client.Gateway
class RootComponent {
init {
// Replace with your actual Google Cloud Project Number
Gateway.configure(
googleCloudProjectNumber = YOUR_GCP_PROJECT_NUMBER
)
}
}For Android, configure Gateway in your Application class:
import android.app.Application
import io.github.brahyam.gateway.client.Gateway
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Gateway.configure(
googleCloudProjectNumber = YOUR_GCP_PROJECT_NUMBER
)
}
}You can either call AI Services directly (not recommended for production as it exposes your API keys), or use the Gateway-protected service which offers:
Direct (Unprotected!!) OpenAI Service
val openAIService = Gateway.createDirectOpenAIService(
apiKey = "your-openai-api-key"
)Gateway-Protected OpenAI Service
val openAIService = Gateway.createOpenAIService(
partialKey = "your-partial-key", // Get this from the Gateway dashboard
serviceURL = "your-service-url" // Get this from the Gateway dashboard
)val response = openAIService.chatCompletion(
request = ChatCompletionRequest(
model = ModelId("gpt-4o-mini"),
messages = listOf(ChatMessage(role = Role.User, content = "Hello, how are you?"))
)
)
println(response.choices[0].message.content)// Initialize Gemini service with Gateway protection
val geminiService = Gateway.createGeminiService(
serviceURL = "your-service-url",
partialKey = "your-partial-key",
logging = LoggingConfig(LogLevel.All)
)
// Generate images with text prompts and optional input images
val geminiImageGeneration = createGeminiImageGenerationWithImages(
text = "Create a beautiful sunset landscape",
model = "gemini-2.5-flash-image-preview", // Nano banana model
images = existingImages, // Optional: for image editing
responseModalities = listOf("TEXT", "IMAGE")
)
val imageResponse = geminiService.generateImages(geminiImageGeneration)
val generatedImage = imageResponse.getFirstImage()?.dataFor a complete working example, check out the sample/android and sample/kmp folders. The KMP sample demonstrates the new image generation features!
Get started and understand more about how to use OpenAI API client for Kotlin with these guides:
Appreciate the project? Here's how you can help:
Gateway AI Client is an open-sourced software licensed under the MIT license. This is an unofficial library, it is not affiliated with nor endorsed by Open AI. Contributions are welcome.
This project starts as a fork of OpenAI Kotlin Client and the great work of all its contributors. Thank you.
Android and Kotlin Multiplatform (KMP) client for accessing different AI providers (OpenAI, Claude...) directly or with API key protection through Gateway's servers
gemini-2.5-flash-image-preview modelThe Gateway client supports the following AI service providers (see
Gateway.kt):
For KMP projects, add to your commonMain dependencies in your shared module's
build.gradle.kts:
commonMain.dependencies {
implementation("io.github.brahyam:gateway-client:0.4.0")
}For Android-only projects, add to your build.gradle:
dependencies {
implementation("io.github.brahyam:gateway-client:0.4.0")
}For KMP, configure Gateway in your shared code (e.g., RootComponent, MainViewModel, or app
startup):
import io.github.brahyam.gateway.client.Gateway
class RootComponent {
init {
// Replace with your actual Google Cloud Project Number
Gateway.configure(
googleCloudProjectNumber = YOUR_GCP_PROJECT_NUMBER
)
}
}For Android, configure Gateway in your Application class:
import android.app.Application
import io.github.brahyam.gateway.client.Gateway
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Gateway.configure(
googleCloudProjectNumber = YOUR_GCP_PROJECT_NUMBER
)
}
}You can either call AI Services directly (not recommended for production as it exposes your API keys), or use the Gateway-protected service which offers:
Direct (Unprotected!!) OpenAI Service
val openAIService = Gateway.createDirectOpenAIService(
apiKey = "your-openai-api-key"
)Gateway-Protected OpenAI Service
val openAIService = Gateway.createOpenAIService(
partialKey = "your-partial-key", // Get this from the Gateway dashboard
serviceURL = "your-service-url" // Get this from the Gateway dashboard
)val response = openAIService.chatCompletion(
request = ChatCompletionRequest(
model = ModelId("gpt-4o-mini"),
messages = listOf(ChatMessage(role = Role.User, content = "Hello, how are you?"))
)
)
println(response.choices[0].message.content)// Initialize Gemini service with Gateway protection
val geminiService = Gateway.createGeminiService(
serviceURL = "your-service-url",
partialKey = "your-partial-key",
logging = LoggingConfig(LogLevel.All)
)
// Generate images with text prompts and optional input images
val geminiImageGeneration = createGeminiImageGenerationWithImages(
text = "Create a beautiful sunset landscape",
model = "gemini-2.5-flash-image-preview", // Nano banana model
images = existingImages, // Optional: for image editing
responseModalities = listOf("TEXT", "IMAGE")
)
val imageResponse = geminiService.generateImages(geminiImageGeneration)
val generatedImage = imageResponse.getFirstImage()?.dataFor a complete working example, check out the sample/android and sample/kmp folders. The KMP sample demonstrates the new image generation features!
Get started and understand more about how to use OpenAI API client for Kotlin with these guides:
Appreciate the project? Here's how you can help:
Gateway AI Client is an open-sourced software licensed under the MIT license. This is an unofficial library, it is not affiliated with nor endorsed by Open AI. Contributions are welcome.
This project starts as a fork of OpenAI Kotlin Client and the great work of all its contributors. Thank you.