What OpenAI-Compatible Actually Means in Production
Compatibility is more than matching one request body. Learn which authentication, streaming, error, model, and retry behaviors must stay stable during a provider migration.
An OpenAI-compatible endpoint can make a provider change look like a base URL edit, but production compatibility is a behavioral contract rather than a logo on an API reference. The request schema matters, and so do streaming events, error shapes, model discovery, tool calls, and the point at which a retry stops being safe.
The five layers of compatibility
- Transport: The endpoint paths, HTTP methods, content types, and authentication headers match the client.
- Request schema: Messages, tools, response formats, token limits, and optional fields preserve their meaning.
- Response schema: Choices, usage, finish reasons, tool calls, and errors remain readable by the existing SDK.
- Streaming: Event framing, chunk order, termination, and disconnect behavior match what the application expects.
- Operations: Retries, request IDs, rate limits, model discovery, and observability remain predictable.
note: Transport is the foundation
If the endpoint path or auth header shape changes, every SDK integration breaks. Getting transport right is a prerequisite, but it is not sufficient for behavioral compatibility.
Why a successful hello-world request is not enough
A basic non-streaming chat completion exercises the narrowest part of the contract. Real applications often depend on structured output, multimodal input, tool calls, cached prompts, usage accounting, or provider-specific limits.
Compatibility gaps usually appear under load or at the edges: a missing finish reason, a tool-call delta emitted in a different order, a zero value silently removed, or an upstream error returned as an HTML proxy response.
warning: The happy path is a trap
A single successful request proves nothing about your ability to migrate. Test error paths, edge cases, and streaming behavior before cutting over production traffic.
The compatibility checklist
- Happy paths. Test non-streaming and streaming requests for every endpoint used in production.
- Feature paths. Exercise tools, JSON or structured output, images, audio, files, and reasoning controls where applicable.
- Failure paths. Verify 400, 401, 403, 429, 5xx, timeout, and disconnect behavior.
- Accounting paths. Compare token usage, finish reasons, request IDs, and billed totals with expected behavior.
Use model discovery instead of assumptions
A compatible API does not imply that every credential can access every model. Availability may depend on account group, key restrictions, current marketplace supply, or provider health.
Call the models endpoint during integration and treat its exact IDs as the source of truth for the current key. This is especially important in a marketplace context where models may appear or disappear based on available seller offers.
const client = new OpenAI({
apiKey: process.env.MODEL_GATEWAY_API_KEY,
baseURL: "https://cisoma.com/v1",
});
const models = await client.models.list();
const available = new Set(models.data.map((model) => model.id));The streaming edge cases no one tests until too late
Streaming is where most compatibility gaps reveal themselves. Providers differ in how they flush partial tool-call deltas, whether they send a final usage block, and how they signal termination. A missing or reordered chunk can silently break a parser that expects a specific event sequence.
caution: Never assume chunk ordering
Tool-call deltas from different providers may arrive in different orders. Parse each delta independently rather than concatenating raw chunks.
The request-to-response lifecycle
This diagram shows every hop a request takes through the gateway, from the moment the SDK sends it until the final usage record is settled in your account.
start(Client SDK)
auth:Validate API key
route:Check model availability
route:Select eligible provider
relay:Forward to upstream
stream:Stream response back
meter:Count tokens used
settle:Settle buyer charge
settle:Credit seller earnings
end(SDK receives final chunk)
start -> auth
auth -> route
route -> relay
relay -> stream
stream -> meter
meter -> settle
settle -> endKeep provider-native escape hatches explicit
Compatibility should not force every provider into the smallest shared feature set. Native Anthropic or Gemini routes can remain useful when an application needs a provider-specific capability.
The important boundary is intentionality: shared workflows use the compatible contract, while native features use a clearly separate route and test suite.
tip: Document your escape route
If you maintain a native provider integration for advanced features, label it clearly. Teams should know when they are opting out of the portable contract.
The production definition
An API is compatible when an existing application can change its endpoint without losing the behavior it relies on. That definition is narrower than identical and stronger than accepting the same JSON.
Treat compatibility as a tested contract and provider migration becomes an operational change instead of a product rewrite.