Skip to content

OpenAI Adapter

Connect to OpenAI's API or any OpenAI-compatible endpoint: including Azure OpenAI, OpenRouter, and self-hosted models with an OpenAI-compatible interface.

Never ship API keys in your mobile app
API keys bundled in a mobile app binary can be extracted by anyone who downloads the app. Use the Webhook adapter for production: it proxies all LLM calls through your backend server.

Configuration

Ts
1const llmConfig: LocalLLMConfig = {
2  provider: "openai",
3  baseUrl: "https://api.openai.com",
4  model: "gpt-4o-mini",   // or "gpt-4o", "gpt-4-turbo", "gpt-3.5-turbo"
5  apiKey: "sk-...",        // required
6  temperature: 0.7,        // optional
7  maxTokens: 1024,         // optional
8  timeoutMs: 30_000,       // optional, default 60s
9};

Recommended models

ModelSpeedJSON qualityBest for
gpt-4o-miniFast★★★★★Best value: recommended default
gpt-4oMedium★★★★★Most capable, highest cost
gpt-4-turboMedium★★★★★Large context window (128k tokens)
gpt-3.5-turboVery fast★★★★☆Budget option for simple flows

Compatible endpoints

Ts
1{
2  provider: "openai",
3  baseUrl: "https://YOUR-RESOURCE.openai.azure.com/openai/deployments/gpt-4o",
4  model: "gpt-4o",
5  apiKey: "your-azure-api-key",
6}
Ts
1{
2  provider: "openai",
3  baseUrl: "https://openrouter.ai/api",
4  model: "anthropic/claude-3-haiku",
5  apiKey: "your-openrouter-key",
6}
Ts
1{
2  provider: "openai",
3  baseUrl: "http://your-server:8000/v1",
4  model: "meta-llama/Llama-3-8B-Instruct",
5  apiKey: "not-needed",  // or your token
6}

How it works

The adapter calls POST /v1/chat/completions with response_format: { type: "json_object" } for reliable structured output.

Request body
1{
2  "model": "gpt-4o-mini",
3  "messages": [...],
4  "response_format": { "type": "json_object" },
5  "temperature": 0.7,
6  "max_tokens": 1024
7}