Android
You have two options for integrating Gateway into your Android application:
Option 1: Gateway SDK (Recommended)
The Gateway SDK provides native Android support with built-in security features like device attestation, API key protection, and certificate pinning.
Setup
- Add the Gateway SDK dependency to your
build.gradle
:
dependencies {
implementation("io.github.brahyam:gateway-client:0.3.0")
}
- 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
)
}
}
- Create a service instance using your Gateway credentials e.g. OpenAI:
import io.github.brahyam.gateway.client.Gateway
// Gateway-Protected Service (Recommended)
val openAIService = Gateway.createOpenAIService(
partialKey = "your-partial-key", // Get this from the Gateway dashboard
serviceURL = "your-service-url" // Get this from the Gateway dashboard
)
// Or Direct Service (for testing only - exposes API keys)
val directOpenAIService = Gateway.createDirectOpenAIService(
apiKey = "your-openai-api-key"
)
- Make API requests:
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)
Supported AI Providers
The Gateway SDK supports multiple AI service providers:
- OpenAI
- Google Gemini
- Groq
- Mistral AI
- Together AI
- Anthropic Claude
- AI/ML API
- Custom (any compatible OpenAI-style API)
Option 2: Use Your Existing SDK
When using your existing SDK instead of the Gateway SDK, device attestation will not be available. This means you'll lose the security benefits of verifying that requests come from genuine, untampered devices. For maximum security, we recommend using the Gateway SDK (Option 1).
You can use Gateway to route your API calls without changing your current SDK.
OpenAI API client for Kotlin
com.aallam.openai:openai-client
Follow the official documentation to install the library.
Then, when initializing the client, pass in your Gateway API key and endpoint instead of defaults:
val openAi = OpenAI(
token = "YOUR_GATEWAY_API_KEY",
host = OpenAIHost("https://api.meetgateway.com/v1/proxy/YOUR_ENDPOINT/v1")
)
Remember to suffix your endpoint with /v1
to match the OpenAI API version as the library does not include it when using an alternative host.
Plain HTTP Clients
If you're using plain HTTP clients like Ktor, OkHttp, or Retrofit, you can easily integrate Gateway by modifying your base URL and adding an authentication interceptor.
OkHttp Example
val client = OkHttpClient.Builder()
.addInterceptor { chain ->
val original = chain.request()
val request = original.newBuilder()
.header("Authorization", "Bearer YOUR_GATEWAY_API_KEY")
.build()
chain.proceed(request)
}
.build()
// Use the client with your API calls
val retrofit = Retrofit.Builder()
.baseUrl("https://api.meetgateway.com/v1/proxy/YOUR_ENDPOINT/")
.client(client)
.build()
Ktor Example
val client = HttpClient(CIO) {
defaultRequest {
url("https://api.meetgateway.com/v1/proxy/YOUR_ENDPOINT/")
header("Authorization", "Bearer YOUR_GATEWAY_API_KEY")
}
}
Make sure to:
- Replace
YOUR_GATEWAY_API_KEY
with your actual Gateway API key - Replace
YOUR_ENDPOINT
with your target API endpoint - Add any necessary path segments after the base URL in your API calls