OpenAI-Compatible API Quickstart: One Key for Claude, GPT and Gemini
Use one OpenAI-compatible API for Claude, GPT and Gemini: change the base URL in your SDK, read usage on streamed responses, and handle every error code.
On this page
If you call more than one model provider, you already pay a tax for it: a different SDK per vendor, a different auth header, a different error format, and a separate bill at the end of the month. An OpenAI-compatible API removes most of that. You keep the client you already have, point it at one base URL with one key, and choose the model with the model field.
This guide goes from a new account to a working request, then covers what comes up once real traffic starts: streaming with real token counts, the Anthropic-native option for Claude tools, and the error codes worth handling explicitly.
What "OpenAI-compatible" means
An OpenAI-compatible API mirrors the OpenAI wire protocol. On APIKO that means:
| Part | What stays the same as OpenAI |
|---|---|
| Base URL | https://api.apiko.app/v1 instead of https://api.openai.com/v1 |
| Endpoints | POST /v1/chat/completions, GET /v1/models |
| Auth | Authorization: Bearer <key> |
| Request body | model, messages, stream, stream_options, max_tokens, … |
| Response body | choices[0].message, usage.prompt_tokens, usage.completion_tokens |
| Errors | {"error": {"message", "type", "code"}} with standard HTTP status codes |
Because the shape is the same, anything that already speaks OpenAI works without new call logic: the official openai SDKs, LangChain (see the LangChain guide), LlamaIndex, a bare fetch or requests call, and agent tools that ask for a base URL and key. What changes is the set of models behind the endpoint. On APIKO that list includes Claude, GPT, Gemini, DeepSeek, GLM, Grok and Kimi models, all on the same key and the same balance.
One distinction is worth keeping straight. api.apiko.app is the gateway: it serves /v1 and is what your code talks to. apiko.app is the console where you create keys, check usage and top up. The console does not proxy /v1 traffic, so never point an SDK at it.
Step 1: Create an API key
Sign up, open API Keys in the console (/dashboard/apikeys) and create a key. The full sk-… value is shown once, so copy it into an environment variable straight away:
export APIKO_API_KEY="sk-..."
Each key can carry its own spending limit. When a key has spent that amount, its requests fail instead of drawing more from your balance, which makes separate keys for staging, production and individual services a cheap safety net.
If you sign in with Google using a Gmail address, $0.20 is added to your balance automatically, no card needed, once per person. It works with every model, including image and video.
Step 2: Change the base URL in your existing code
The official OpenAI SDKs for Python and Node.js both read two environment variables. If your code creates the client without arguments, this is the whole migration:
export OPENAI_BASE_URL="https://api.apiko.app/v1"
export OPENAI_API_KEY="$APIKO_API_KEY"
If your code passes the values explicitly, change baseURL in JavaScript or base_url in Python. Nothing else in the client changes.
Python:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.apiko.app/v1",
api_key=os.environ["APIKO_API_KEY"],
)
res = client.chat.completions.create(
model="gpt-6.1-sol",
messages=[{"role": "user", "content": "Hello"}],
)
print(res.choices[0].message.content)Node.js:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.apiko.app/v1",
apiKey: process.env.APIKO_API_KEY,
});
const res = await client.chat.completions.create({
model: "gpt-6.1-sol",
messages: [{ role: "user", content: "Hello" }],
});
console.log(res.choices[0].message.content);Building messages, reading choices[0].message.content, your retries and timeouts all stay exactly as they were. That is the point of an OpenAI-compatible API: the integration work you did once covers every model you add later.
Step 3: Call Claude, GPT or Gemini with the same request
Here is the same call over curl:
curl https://api.apiko.app/v1/chat/completions \
-H "Authorization: Bearer $APIKO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": "Hello"}]
}'To switch models, change only the model string: claude-sonnet-5-5 for Claude, gemini-3.8-flash for Gemini, deepseek-v4-pro for DeepSeek. Do not type ids from memory or from another provider's docs. Ask the gateway which ids your key can call:
curl https://api.apiko.app/v1/models \
-H "Authorization: Bearer $APIKO_API_KEY"
You can also browse the model catalog, where each model page shows its supported parameters and current price. Image models such as Nano Banana use /v1/images/generations with the same key; to choose between Google's two tiers, see Nano Banana 2.1 vs Nano Banana Pro.
A note on Gemini: Google runs its own OpenAI-compatible endpoint for Gemini models, so you may have seen "OpenAI-compatible API Gemini" in other guides. Through APIKO you don't need a separate Google key or base URL. Gemini models sit behind the same https://api.apiko.app/v1 as everything else.
Streaming, and how to get real token usage
Set "stream": true and the response arrives as server-sent events: one data: line per chunk, ending with data: [DONE]. That part is standard and rarely causes trouble. The part people miss is usage.
A plain streamed response carries no usage field at all. If your logging, budgeting or per-customer billing depends on token counts, they will simply be missing on the streaming path. Add stream_options to the request:
curl -N https://api.apiko.app/v1/chat/completions \
-H "Authorization: Bearer $APIKO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": "Hello"}],
"stream": true,
"stream_options": {"include_usage": true}
}'With include_usage set, the last chunk carries a usage object with the real prompt and completion token counts for that request. These are the same numbers APIKO bills against, so parse that chunk rather than estimating with a local tokenizer. In Python:
stream = client.chat.completions.create(
model="gpt-6.1-sol",
messages=[{"role": "user", "content": "Hello"}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
if chunk.usage: # usage appears when stream_options.include_usage is enabled
print(chunk.usage)Streaming is also the safer choice for long outputs. A non-streaming request with no response after 100 seconds gets a 524 from the edge proxy, but the request keeps running and is billed. A streamed response starts sending right away and avoids that.
The Anthropic-native option for Claude
If your code or tool already speaks Anthropic's format, you don't have to translate it. The same key works on POST /v1/messages, authenticated with x-api-key plus anthropic-version: 2023-06-01 (or Authorization: Bearer):
curl https://api.apiko.app/v1/messages \
-H "x-api-key: $APIKO_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'Anthropic's SDKs append /v1/messages themselves, so give them https://api.apiko.app as the base URL, not the /v1 URL used for OpenAI clients. Claude-specific fields such as thinking and output_config.effort go in the body as they would with Anthropic; the Claude API reference lists how each one is handled.
Claude Code uses the same endpoint. Set these before starting it:
export ANTHROPIC_BASE_URL="https://api.apiko.app"
export ANTHROPIC_AUTH_TOKEN="$APIKO_API_KEY"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-5-5"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-5-5"
The integration guides cover Claude Code, Cursor, Cline and other tools step by step.
If you stay on the OpenAI-compatible endpoint, you can still call Claude: use the Claude model id and set thinking depth with reasoning_effort. For Claude on Chat Completions the accepted values are none, minimal, low, medium, high, xhigh and max; anything else returns 400.
Error codes worth handling explicitly
Errors use the OpenAI body shape, so existing error handling mostly works. These are the cases to handle on purpose:
| Status | error.code / type | Cause | What to do |
|---|---|---|---|
| 400 | varies | Invalid parameter or value | Fix the request; do not retry |
| 401 | Missing, mistyped or deleted key | Check the Authorization: Bearer header and that the key still exists in API Keys; do not retry | |
| 403 | insufficient_user_quota | Balance is used up | Top up in Billing; do not retry until you have |
| 429 | rate_limit_error | Over 500 requests per minute for the account | Back off with jitter; a 429 is not billed |
| 404 | model_not_found | Model id is wrong or the model was retired | Check the id with GET /v1/models; retrying will not help |
| 503 / 5xx | Upstream failure after the gateway's own retries | Retry with backoff; a failed request is refunded |
A few details from the API reference that save debugging time:
- The rate limit is 500 requests per minute per account, counted across all keys and models. Bursts of up to 500 are accepted, then capacity refills at about 8 requests per second. There is no
Retry-Afterheader, so start backoff at about one second. - On
/v1/messages, the model-not-found case shows aserror.typenot_found_errorinstead of anerror.code. - Most error messages end with a request id. Keep it: Task Logs lists requests by id, and support needs it when you chat with us.
- If you call the API with a bare HTTP library, send a normal
User-Agent. Some library defaults, such as Python's built-inurllib, are rejected at the edge witherror code: 1010before they reach the gateway. The official SDKs set one for you.
How billing works per request
Every call follows the same three steps, streaming or not. A pre-hold is taken from your balance when the request starts, based on an estimate. When the response completes, it settles to the real usage the provider reports. If the call fails, the pre-hold is refunded automatically. Retries across channels happen behind your single call, and only a response that reaches you is billed.
There are no subscriptions or minimums, and one balance covers every model available to your account. The balance never expires. Prices follow upstream costs and change several times a day, so check /pricing for current per-token rates instead of copying numbers into your code. For Claude specifically, Claude API pricing explained walks through thinking tokens and prompt caching.
From first request to production
A few habits keep things predictable once usage grows:
- Log usage from the response. The non-streaming body, or the final chunk with
include_usage, carries the billed token counts. Store them next to your own request ids and the gateway's request id. - Keep the model id in configuration. Since switching models is a one-line change, put it in an environment variable from day one. Trying a newer model or falling back to a cheaper one then needs no deploy.
- Use one key per environment. Give staging and production separate keys with their own spending limits, so a runaway loop in staging cannot drain the production budget.
- Retry only what can succeed. Retry 429 and upstream 5xx with exponential backoff and jitter. Do not retry 400, 401, 403 or
model_not_found. - Test before you trust. Before pointing production at any provider, run the checks in how to test an AI API key: key validity, model list, a paid request, latency and billing.
Try it
The quickest way to see whether an OpenAI-compatible API fits your stack is to run the three steps above: create a key, set the base URL in the client you already use, and make one real call with gpt-6.1-sol. Then swap in a Claude or Gemini id and confirm the rest of your code doesn't notice. Create a key, or check current prices first.
Frequently asked questions
What is an OpenAI-compatible API?
An API that accepts the same requests as the OpenAI API and returns the same response shapes: the same paths (/v1/chat/completions, /v1/models), the same Authorization: Bearer header, the same model / messages / stream fields and the same {"error": {...}} body on failure. Any client written for OpenAI can call it by changing the base URL and the key.
Which SDKs and tools work with an OpenAI-compatible API?
Anything that lets you set a base URL: the official openai SDKs for Python and Node.js, LangChain, LlamaIndex, plain fetch or requests, and agent tools such as OpenClaw, Cline or Cursor. On APIKO the base URL is https://api.apiko.app/v1.
Do I need to change my code?
Usually not. The official OpenAI SDKs read OPENAI_BASE_URL and OPENAI_API_KEY from the environment, so setting those two variables is enough. If your code passes base_url / baseURL explicitly, change that one value and the key. The model string changes to the id you want to call.
How do I get token usage on streaming responses?
Send "stream_options": {"include_usage": true} with "stream": true. The last chunk before data: [DONE] then carries a usage object with the real prompt and completion token counts, the same numbers APIKO bills. Without it, streamed responses have no usage at all.
Can I call Claude with the OpenAI SDK?
Yes. Point the OpenAI SDK at https://api.apiko.app/v1 and use a Claude model id such as claude-sonnet-5-5. Thinking depth is set with reasoning_effort. If you prefer Anthropic's own format, the same key also works on POST /v1/messages with the Anthropic SDK.
Why do I get model_not_found?
APIKO returns HTTP 404 with error.code model_not_found when the model id is wrong or the model was retired. Retrying will not fix it. Call GET /v1/models with the same key and copy the id exactly.
Can I try it for free?
Sign in with Google using a Gmail address and $0.20 is added to your balance automatically, no card needed, once per person. It works with every model, including Claude, Gemini, image and video.