Android and Kotlin Multiplatform (KMP) client for accessing different AI providers (OpenAI, Claude...) directly or with API key protection through Gateway's servers
- Enhanced Gemini Support: Advanced image generation and editing capabilities
- Nano Banana Integration: Support for
gemini-2.5-flash-image-previewmodel - Multimodal Chat: Process and generate both text and images in conversations
- Image Attachment: Attach images to chat messages for context-aware responses
The Gateway client supports the following AI service providers (see
Gateway.kt):
- OpenAI
- Google Gemini
- Groq
- Mistral AI
- Together AI
- Anthropic Claude
- AI/ML API
- Custom (any compatible OpenAI-style API)
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:
- Device attestation: Ensures the request is coming from a genuine device.
- API key protection: Hides your real API keys.
- Rate limiting: Controls the number of requests based on IP/User.
- Certificate pinning: Ensures secure communication with Gateway servers.
- Monitoring: Tracks usage and performance.
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:
- Star: Give it a star at the top right. It means a lot!
- Contribute: Found an issue or have a feature idea? Submit a PR.
- Feedback: Have suggestions? Open an issue or start a discussion.
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.