TTodAPI

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

AreaTypically compatible
ChatPOST /v1/chat/completions with messages, model, temperature, max_tokens
Streamingstream: true over SSE, ending with data: [DONE]
Tool callingtools / tool_choice, tool_calls in the response
Usageusage.prompt_tokens, completion_tokens, total_tokens
AuthAuthorization: Bearer <key>

What still differs, and always will

A migration checklist that catches the real problems

  1. Set base_url and keep the SDK.
  2. Replace model ids with ids from GET /v1/models.
  3. Check error handling: does it branch on status code or on message text?
  4. Re-measure token counts on your own prompts — cost estimates based on the other tokenizer will be off.
  5. 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.

Migration guide

Two-line change, with what you give up.

What is a gateway?

The category, defined.

Error handling

The two 4xx codes people misread.