---
title: "Unified AI API: how OpenAI-compatible translation works and breaks"
type: "deep dive"
url: "https://aifordevs.org/articles/unified-ai-api"
markdown: "https://aifordevs.org/articles/unified-ai-api.md"
publisher: "AI for Devs"
license: "https://aifordevs.org/reuse"
attribution: "Credit AI for Devs and link to https://aifordevs.org/articles/unified-ai-api"
description: "A unified AI API puts every LLM provider behind one OpenAI-format endpoint. See how requests and streams are translated, what gets dropped, and how to migrate."
author: "AI for Devs"
published: "2026-11-24"
level: "Intermediate"
topics: ["apis", "models"]
---

# Unified AI API: how OpenAI-compatible translation works and breaks

A unified AI API puts every LLM provider behind one OpenAI-format endpoint. See how requests and streams are translated, what gets dropped, and how to migrate.

> **TL;DR**
>
> - A unified AI API accepts one request format, usually OpenAI Chat Completions, picks a provider from the model name, and translates each request and response to and from that provider's native schema.
> - Most fields are renamed or moved, not lost: an OpenAI system message becomes Anthropic's top-level `system` field and Gemini's `systemInstruction`. Some are dropped silently, including `strict` on tool schemas and `seed` for Anthropic.
> - Streaming is the hardest translation. Anthropic numbers a tool call by content block, so a tool call after text arrives as block 1 and must leave as OpenAI tool call index 0.
> - Bifrost, an open-source AI gateway, routes by provider prefix such as `anthropic/claude-sonnet-5-5`, keeps native Anthropic, GenAI, and Bedrock routes, and offers passthrough endpoints that skip translation for provider-only APIs.
> - Adopt one by changing the base URL, diffing responses against direct calls, and testing tools and streaming per provider before you turn on fallbacks.

A unified AI API is one endpoint, in one request format, that reaches models from many LLM providers. Most copy the OpenAI Chat Completions format, so code written for the OpenAI SDK can call Anthropic, Gemini, Bedrock, or a local model by changing a base URL and a model string. Behind the endpoint, a translation layer rewrites every request into the provider's native shape and every reply back. This article walks through that translation field by field, shows where it loses data, and uses [Bifrost](https://www.getmaxim.ai), an [open-source AI gateway](https://github.com/maximhq/bifrost), as the worked example of adopting one without rewriting an app.

For choosing the gateway itself, see the ranked [best LLM gateways](https://aifordevs.org/articles/best-llm-gateways). For hosted model marketplaces, see [OpenRouter alternatives](https://aifordevs.org/articles/openrouter-alternatives). This piece is about the translation layer that both kinds share.

## What a unified AI API does

A unified AI API does three jobs on every request. It translates the request into the provider's schema, normalizes the response back into the common schema, and maps provider errors onto status codes your client already handles. Your code sees one request shape and one response shape, whichever model answered.

The model string carries the routing decision. The common convention is a provider prefix: `openai/gpt-5.4-mini` goes to OpenAI and `anthropic/claude-sonnet-5-5` goes to Anthropic. The [AI gateway](https://aifordevs.org/glossary#ai-gateway) strips the prefix, picks a stored key for that provider, and sends the native call.

There are two ways to get the interface:

| Approach | Where translation runs | Keys live in | Good fit |
| --- | --- | --- | --- |
| Provider compatibility endpoint | The provider's servers | Each app | Trying one provider's models with OpenAI SDK code |
| Client library | Inside each app process | Each app | One service, one language, few providers |
| Gateway | A shared server | The gateway | Many services, fallbacks, shared budgets and logs |

Provider compatibility endpoints are the narrowest option. Anthropic's [OpenAI SDK compatibility page](https://platform.claude.com/docs/en/api/openai-sdk) says its layer is "primarily intended to test and compare model capabilities" and lists more than a dozen request fields it ignores. A gateway or library does the same mapping for every provider at once, and when a migration fails, the cause is almost always in one of the three jobs above.

## How request translation works

Request translation is field-by-field rewriting from the OpenAI format into each provider's native format. Plain chat is easy. The differences show up in where each provider expects a field to live, which fields it requires, and which it has no slot for.

**Figure 1.** Most of an OpenAI-format request survives translation by being renamed or moved into another structure. The hatched cells are fields with no target, which a translator drops without an error.

Take a request with a system prompt, one user message, a token limit, and one tool, sent to Anthropic. The [Bifrost Anthropic conversion guide](https://docs.getbifrost.ai/providers/supported-providers/anthropic) lists what changes, and Anthropic's own compatibility layer does nearly the same:

- **The system prompt moves.** OpenAI treats it as a message with `role: "system"`. Anthropic wants a top-level `system` field, so the translator pulls every system message out of the array.
- **The token limit is renamed.** `max_completion_tokens` becomes `max_tokens`, which Anthropic requires on every request.
- **Tool schemas change keys.** OpenAI nests the JSON Schema under `function.parameters`. Anthropic puts it under `input_schema`.
- **Tool results change form.** OpenAI sends each result as a message with `role: "tool"` and a `tool_call_id`. Anthropic expects `tool_result` blocks inside a user message, so consecutive tool messages merge into one, and the message count changes.
- **`tool_choice: "required"` becomes `any`.** A named tool becomes `{"type": "tool", "name": ...}`.

Gemini needs a different set of moves: the assistant role is called `model`, the system prompt goes in `systemInstruction`, and tools become `functionDeclarations`, per the [Gemini conversion guide](https://docs.getbifrost.ai/providers/supported-providers/gemini). Each provider adds its own list, so a translator keeps one mapper per provider. The [LLM-Rosetta paper](https://arxiv.org/abs/2604.09360) argues for a shared intermediate format for exactly this reason: with a hub in the middle, each provider needs one adapter instead of one per pair.

Order matters as well as names. Anthropic's layer concatenates every system and developer message into one `system` string, wherever they appeared in the conversation. An agent that inserts a system message mid-conversation sends a different prompt to Claude than to an OpenAI model, with no error from either.

## How response normalization works

Response normalization rewrites the provider's reply into an OpenAI-shaped `choices` array, with a finish reason and a usage block your code reads the same way every time. Two fields need the most care: why the model stopped, and how many [tokens](https://aifordevs.org/glossary#token) it used.

Finish reasons are the first thing to check, because agent loops branch on them:

| Meaning | OpenAI `finish_reason` | Anthropic `stop_reason` | Gemini `finishReason` |
| --- | --- | --- | --- |
| Normal end | `stop` | `end_turn`, `stop_sequence` | `STOP` |
| Hit the token limit | `length` | `max_tokens` | `MAX_TOKENS` |
| Wants a tool | `tool_calls` | `tool_use` | `STOP` with a `functionCall` part |
| Blocked | `content_filter` | `refusal` | `SAFETY`, `RECITATION`, others |

A good mapper turns `max_tokens` into `length` and `tool_use` into `tool_calls`, so a loop that checks `finish_reason == "tool_calls"` keeps working on every provider. Bifrost maps Gemini's `MALFORMED_FUNCTION_CALL` to `tool_calls` as well, which means a loop on Gemini can see `tool_calls` with a call that failed to parse. Handle an empty or invalid tool call even when the finish reason says one exists.

Token usage needs the same care. Anthropic reports cache reads and cache writes apart from `input_tokens`. Bifrost adds all three into `prompt_tokens` and puts the cache counts in `prompt_tokens_details`, so a cost dashboard that reads `prompt_tokens` sees the full input. A translator that forgets the cache fields undercounts input on every request that hits a [prompt cache](https://aifordevs.org/glossary#prompt-caching), and the [Claude API pricing guide](https://aifordevs.org/articles/claude-api-pricing) shows how large a share of the bill those cached tokens can be.

## What breaks in a unified AI API

The parts that break are the ones where providers structure data differently. Renaming a field is a one-line mapping. Reshaping a stream of events, a content block, or a JSON Schema is where translation layers lose data, and they usually lose it without an error.

### Tool calls

[Tool calling](https://aifordevs.org/glossary#tool-calling) breaks most often, because the formats differ in three places. OpenAI returns `function.arguments` as a JSON-encoded string, per its [function calling guide](https://developers.openai.com/api/docs/guides/function-calling), while Anthropic returns a `tool_use` block whose `input` is already an object. Call IDs must survive the round trip, since the next request sends results keyed by them. And schema enforcement differs: `strict: true` is dropped on the way to both Anthropic and Gemini, so arguments are no longer guaranteed to match the schema.

Some failures are not translation bugs at all. Anthropic's compatibility table lists several current models, including Claude Sonnet 5.5 and Claude Opus 5.5, that return a 400 error for forced tool use. The mapping from `required` to `any` is correct, and the model still refuses it. The [tool calling guide](https://aifordevs.org/articles/tool-calling) covers loop design. For a unified API, test `tool_choice`, parallel calls, and schema features such as `anyOf` against each model in your fallback chain.

### Streaming

Streaming breaks because providers send different event sequences. OpenAI streams chunks that each carry a `delta`. Anthropic streams typed server-sent events, `message_start`, `content_block_start`, `content_block_delta`, `content_block_stop`, `message_delta`, and `message_stop`, documented in its [streaming guide](https://platform.claude.com/docs/en/build-with-claude/streaming). The translator buffers those and re-emits them as OpenAI chunks in order.

**Figure 2.** Anthropic numbers content blocks, so a tool call that follows text is block 1. OpenAI clients expect it as tool call index 0, and the translator has to renumber every fragment on the way out.

Tool calls in a stream are the hardest case. Anthropic sends argument text as `input_json_delta` events carrying `partial_json`, indexed by content block. OpenAI clients accumulate `delta.tool_calls` fragments by tool-call index. If the translator passes the block index through, the client looks for a tool call at index 1 that never started. If two parallel calls share an index, their fragments concatenate into one invalid JSON string, and the parser fails only on streamed requests.

Usage is the other trap. Anthropic's `message_delta` usage counts are cumulative, and OpenAI clients expect one usage block at the end, sent only when the request sets `stream_options: {"include_usage": true}`. Bifrost's Gemini translation sets the finish reason and usage on the final chunk only. If billing code reads usage from streams, test it per provider.

### Multimodal input

Multimodal requests break on how the media is delivered. OpenAI's `image_url` part takes a public URL or a base64 data URL. Bifrost converts it to an Anthropic `image` block with a `url` or `base64` source and a `media_type`. Other inputs fail outright: Anthropic's compatibility layer returns a 400 for `input_audio` and `file` parts.

Support also varies by model within one provider, so a request with an image can be valid on the primary model and invalid on the next one in a fallback list. An explicit error is the safer behavior. For multimodal embeddings, the supported providers page says a part the model cannot handle returns a 400 naming the modality, and that "Bifrost never drops a part silently."

### Provider-specific parameters

Provider-specific parameters break because the common format has no slot for them. For Anthropic, Bifrost silently drops `frequency_penalty`, `presence_penalty`, `logit_bias`, `logprobs`, `top_logprobs`, `seed`, and `service_tier`. For Gemini it drops `logit_bias`, `logprobs`, `top_logprobs`, `parallel_tool_calls`, and `service_tier`. A unified API can do one of three things with a field it cannot map:

1. **Drop it.** The request succeeds and behaves differently. A `seed` meant to make tests repeatable stops doing anything.
2. **Reject it.** You find out at once, but a fallback to that provider fails.
3. **Pass it through.** The field reaches the provider unchanged, and that call now depends on one provider again.

Reasoning settings show why the choice matters. Bifrost maps OpenAI-style `reasoning.max_tokens` to Anthropic's `thinking.budget_tokens`, and a budget below 1,024 fails with an error instead of being clamped. For anything your output depends on, such as [structured outputs](https://aifordevs.org/glossary#structured-outputs) or a [reasoning model's](https://aifordevs.org/glossary#reasoning-model) budget, prefer rejection or passthrough over a silent drop.

## How Bifrost implements a unified AI API

[Bifrost](https://www.getmaxim.ai/llm-gateway) exposes an OpenAI-compatible API in front of 25+ providers and 10,000+ models, and its docs publish a conversion guide for each provider, which is the detail a migration needs. Three features map to the failure points above: provider-prefixed models, native SDK routes, and passthrough endpoints.

The switch is a base URL change. The [OpenAI SDK integration](https://docs.getbifrost.ai/integrations/openai-sdk/overview) points the client at `/openai` and replaces the provider key with a Bifrost [virtual key](https://docs.getbifrost.ai/features/governance/virtual-keys). Unprefixed models go to OpenAI, and a prefix routes anywhere else.

```python title="unified_client.py (not run)"
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8080/openai",
    api_key="YOUR_BIFROST_VIRTUAL_KEY",
)

# Same client, same response shape, two providers.
client.chat.completions.create(
    model="gpt-5.4-mini",
    messages=[{"role": "user", "content": "Summarize this ticket."}],
)
client.chat.completions.create(
    model="anthropic/claude-sonnet-5-5",
    messages=[{"role": "user", "content": "Summarize this ticket."}],
    extra_body={
        "top_k": 40,  # Anthropic-only, forwarded in the body
        "fallbacks": ["openai/gpt-5.4-mini"],
    },
)
```

The details that matter for the failure modes:

- **Native SDK routes.** The [drop-in replacement](https://docs.getbifrost.ai/features/drop-in-replacement) also covers the Anthropic SDK at `/anthropic`, plus GenAI, Bedrock, and Cohere routes. The [Anthropic SDK integration](https://docs.getbifrost.ai/integrations/anthropic-sdk/overview) accepts prefixes too, so an Anthropic-format service can call `openai/gpt-5.4-mini` without moving to the OpenAI format.
- **Provider fields in the body.** Anthropic's `top_k` goes directly in the request body on the gateway, per the conversion guide, so it reaches Anthropic instead of being dropped.
- **Passthrough for provider-only APIs.** [Passthrough endpoints](https://docs.getbifrost.ai/integrations/passthrough) such as `/anthropic_passthrough` and `/genai_passthrough` forward the native path and body without conversion, in both directions, while logging, virtual-key model restrictions, and budgets still apply. Bifrost injects its own provider key, and Bedrock passthrough is limited to three operations.
- **Fallbacks run per attempt.** A `fallbacks` list in the body runs after the primary's retries are exhausted, per the [fallbacks docs](https://docs.getbifrost.ai/features/fallbacks). Routing does not re-run, but governance, caching, and logging apply to each attempt, and raw passthrough is turned off when the fallback provider cannot take the caller's native body.
- **Headers say who answered.** Each response carries [routing headers](https://docs.getbifrost.ai/providers/response-headers) such as `x-bifrost-routing-info-provider`, `x-bifrost-routing-info-is-fallback`, and `x-bifrost-routing-info-requested-model`, so a wrong-looking reply can be traced to the model that produced it.
- **Emulation is opt-in.** Text completions on a chat-only provider such as Groq are emulated through chat only when `compat.convert_text_to_chat` is `true`.

Bifrost also publishes a [end-to-end test coverage matrix](https://docs.getbifrost.ai/providers/test-harness-coverage) per provider, with gaps marked, such as `seed` and JSON-object response format on Azure OpenAI. Read it next to your feature inventory before you route production traffic.

The same gateway that translates requests is also where policy sits. Bifrost applies governance and security controls, including virtual keys, budgets, guardrails, and audit logs, to every translated call, and [Bifrost Edge](https://www.getmaxim.ai/edge) extends that governance to AI apps and coding agents on employee machines, with [guardrails applied to Edge traffic](https://docs.getbifrost.ai/edge/security) on each device.

## How to adopt a unified AI API without rewriting your app

Adopt a unified AI API by changing the client's base URL and key, keeping the model the same, and comparing responses before you change anything else. Each step below is reversible, and each one isolates one source of difference.

1. **Inventory what you call.** List endpoints (chat, Responses, embeddings) and whether you use tools, streaming, images, structured output, `seed`, or provider-only fields.
2. **Point one service at the gateway, same model.** Change `base_url` and the key only. The [LLM gateway tutorial](https://aifordevs.org/articles/llm-gateway-tutorial) walks through standing one up.
3. **Diff responses against direct calls.** Run the same requests both ways and compare finish reasons, usage, tool call payloads, and streamed output field by field.
4. **Add a second provider behind a prefix.** Send a small share of traffic to `anthropic/...` or another provider, and rerun the inventory against it, streaming and parallel tool calls included.
5. **Decide each mismatch.** For every dropped or provider-only field, choose to accept the drop, send it in the body, or move that call to a native or passthrough route.
6. **Turn on fallbacks last.** A fallback to a provider you never tested with tools or streaming turns an outage into a malformed response. Inject faults on purpose, as the [failover testing guide](https://aifordevs.org/articles/failover-testing) describes, and check the routing headers on each served reply.

Keep one rule through all six steps: a field the common format drops is a behavior change, not a compatibility success. Log the provider, the requested model, and the served model for every request, and the rare translation bug becomes a query instead of a guess.

## Questions

### What is a unified AI API?

A unified AI API is one endpoint and one request format that reaches models from many providers. Most copy the OpenAI Chat Completions format. A translation layer behind the endpoint picks the provider from the model name, rewrites the request into that provider's native schema, and rewrites the reply back, so application code sees one request shape and one response shape for every model.

### What is the difference between a unified AI API and an AI gateway?

A unified AI API is the interface: one schema for many providers. An AI gateway is the server that usually provides it, and adds routing, fallbacks, keys, budgets, caching, and logs on top. A client library can also offer a unified API inside one process with no gateway, but then every service carries its own translation code and its own provider keys.

### Can I use the OpenAI SDK with Claude or Gemini?

Yes, two ways. Anthropic and Google each run an OpenAI-compatible endpoint, though Anthropic says its layer is meant for testing and ignores fields such as seed and strict. A gateway also accepts OpenAI SDK calls and translates them to each provider's native API. In both cases you change the base URL, the API key, and the model name, then test the features you use.

### What breaks when switching LLM providers through a unified API?

The parts where providers structure data differently. Tool calls change format and IDs, streamed events must be renumbered and reassembled, images may need re-encoding, and provider-only parameters have no slot in the common schema. Unmapped fields are often dropped without an error, so a request succeeds and behaves differently. Test tools, streaming, and structured output on each provider before routing to it.

### Does a unified AI API add latency?

It adds the translation work plus, with a gateway, one network hop. The translation itself is small: the Bifrost team reports about 11 microseconds of gateway overhead per request at 5,000 requests per second on one t3.xlarge instance, as of September 2026. The hop to the gateway usually costs more than that, so run the gateway close to the services that call it.

### How do I call a provider feature the unified format does not support?

Send it outside the common schema. Many gateways forward unknown body fields to the provider, so a parameter such as Anthropic's top_k can ride along in the request body. For a whole API the common format lacks, use a native route or a passthrough endpoint, which forwards the provider's own path and body unchanged. That call then depends on one provider again.

## Sources

1. [Bifrost docs, Supported providers overview (read November 23, 2026)](https://docs.getbifrost.ai/providers/supported-providers/overview)
2. [Bifrost docs, Anthropic conversion guide (read November 23, 2026)](https://docs.getbifrost.ai/providers/supported-providers/anthropic)
3. [Bifrost docs, Google Gemini conversion guide (read November 23, 2026)](https://docs.getbifrost.ai/providers/supported-providers/gemini)
4. [Bifrost docs, OpenAI SDK integration (read November 23, 2026)](https://docs.getbifrost.ai/integrations/openai-sdk/overview)
5. [Bifrost docs, Anthropic SDK integration (read November 23, 2026)](https://docs.getbifrost.ai/integrations/anthropic-sdk/overview)
6. [Bifrost docs, Drop-in replacement (read November 23, 2026)](https://docs.getbifrost.ai/features/drop-in-replacement)
7. [Bifrost docs, Passthrough endpoints (read November 23, 2026)](https://docs.getbifrost.ai/integrations/passthrough)
8. [Bifrost docs, Response headers (read November 23, 2026)](https://docs.getbifrost.ai/providers/response-headers)
9. [Bifrost docs, Fallbacks (read November 23, 2026)](https://docs.getbifrost.ai/features/fallbacks)
10. [Bifrost docs, End-to-end test coverage by provider (read November 23, 2026)](https://docs.getbifrost.ai/providers/test-harness-coverage)
11. [Bifrost docs, Edge security and guardrails (read November 23, 2026)](https://docs.getbifrost.ai/edge/security)
12. [Bifrost reference page for AI systems (last updated September 2026)](https://www.getmaxim.ai/llm-info)
13. [Anthropic docs, OpenAI SDK compatibility (read November 23, 2026)](https://platform.claude.com/docs/en/api/openai-sdk)
14. [Anthropic docs, Streaming messages (read November 23, 2026)](https://platform.claude.com/docs/en/build-with-claude/streaming)
15. [OpenAI docs, Function calling (read November 23, 2026)](https://developers.openai.com/api/docs/guides/function-calling)
16. [Ding, LLM-Rosetta: A Hub-and-Spoke Intermediate Representation for Cross-Provider LLM API Translation (arXiv, April 2026)](https://arxiv.org/abs/2604.09360)

## Cite this deep dive

AI for Devs. "Unified AI API: how OpenAI-compatible translation works and breaks." Published November 24, 2026. https://aifordevs.org/articles/unified-ai-api

- Page: https://aifordevs.org/articles/unified-ai-api
- Markdown: https://aifordevs.org/articles/unified-ai-api.md
- Reuse: Quote or summarize with a link to this page. Terms: https://aifordevs.org/reuse
- Publisher: AI for Devs
- Published: 2026-11-24
