Blog
What “OpenAI-compatible” actually means
An OpenAI-compatible API accepts the same request and response shapes as OpenAI's endpoints, so an existing OpenAI SDK works after changing base_url — but the promise covers the wire format, not identical behaviour in every corner.
What the promise covers
| Area | Typically compatible |
|---|---|
| Chat | POST /v1/chat/completions with messages, model, temperature, max_tokens |
| Streaming | stream: true over SSE, ending with data: [DONE] |
| Tool calling | tools / tool_choice, tool_calls in the response |
| Usage | usage.prompt_tokens, completion_tokens, total_tokens |
| Auth | Authorization: Bearer <key> |
What still differs, and always will
- Model ids. Each provider names its own; a gateway exposes its own id space.
- Error bodies. Status codes are standard, the JSON inside is not — write for the code, not the message.
- Rate limits. Per key, per account, per concurrency. Nobody promises OpenAI's numbers.
- Token counts. Different tokenizers produce different counts for the same text, so the same prompt can bill differently.
- Feature drift. Parameters added last week by one vendor may not exist elsewhere.
A migration checklist that catches the real problems
- Set
base_urland keep the SDK. - Replace model ids with ids from
GET /v1/models. - Check error handling: does it branch on status code or on message text?
- Re-measure token counts on your own prompts — cost estimates based on the other tokenizer will be off.
- Replay a day of traffic and diff the answers before switching the default.
from openai import OpenAI
client = OpenAI(
api_key="sk-...",
base_url="https://todapi.work/v1", # the only line that changes
)
Why compatibility matters commercially
It collapses an integration project into a configuration change. That is the whole reason gateways converge on this format: a developer can test a cheaper model on real traffic without rewriting the client, and can move back if quality drops.
FAQ
Is an OpenAI-compatible API the same as OpenAI?
No. It implements the same wire format; the operator, models and prices are different.
Will tool calling work identically?
The shape does. Model behaviour under tool calling varies, so test with your own schemas.
Do responses include the same fields?
The core fields are the same. Extra vendor fields may be absent; do not depend on them.