Cross-Platform
Kotlin Multiplatform
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.
Ktor Client
val client = HttpClient(CIO) {
defaultRequest {
url("https://api.meetgateway.com/v1/proxy/YOUR_ENDPOINT/")
header("Authorization", "Bearer YOUR_GATEWAY_API_KEY")
}
}
Flutter
dio
HTTP Client
If you're using the popular dio
package for HTTP requests in Flutter, you can easily integrate Gateway by modifying your base URL and adding an authentication interceptor.
final dio = Dio()
..options.baseUrl = 'https://api.meetgateway.com/v1/proxy/YOUR_ENDPOINT/'
..interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) {
options.headers['Authorization'] = 'Bearer YOUR_GATEWAY_API_KEY';
return handler.next(options);
},
),
);
http
Package
If you're using the standard http
package, you can create a custom client that adds the Gateway API key to all requests:
class GatewayClient extends http.BaseClient {
final String apiKey;
final http.Client _inner;
GatewayClient(this.apiKey, this._inner);
@override
Future<http.StreamedResponse> send(http.BaseRequest request) {
request.headers['Authorization'] = 'Bearer $apiKey';
return _inner.send(request);
}
}
// Usage
final client = GatewayClient(
'YOUR_GATEWAY_API_KEY',
http.Client(),
);
// Make requests
final response = await client.get(
Uri.parse('https://api.meetgateway.com/v1/proxy/YOUR_ENDPOINT/your-endpoint'),
);
tip
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