Skip to main content

Android

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")
)
warning

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")
}
}
tip

Make sure to:

  1. Replace YOUR_GATEWAY_API_KEY with your actual Gateway API key
  2. Replace YOUR_ENDPOINT with your target API endpoint
  3. Add any necessary path segments after the base URL in your API calls