Skip to content

Protocol translation

Last updated: 2026-11-27T10:53:03-03:00 (UTC-3)

Clients speak four API dialects: OpenAI Chat Completions, OpenAI Responses, Anthropic Messages and Google Gemini GenerateContent. Providers speak six: those four plus Cohere v2 and AWS Bedrock Converse. The gateway lets any of the four client routes reach any of the six providers, so a Messages client (Claude Code, the Anthropic SDKs) can use a GPT, Gemini or Bedrock model, and a Responses client can use Claude, without changing the client.

Every translation goes through one canonical format: the Chat Completions request, response and stream the chat route already speaks, with the gateway’s extensions for reasoning text (reasoning_content), cached prompt tokens and reasoning tokens.

  • Each client route has a decoder (its request to the canonical format) and an encoder (the canonical answer, stream and errors back to its own shape).
  • Each provider has one encoder (canonical to its API and back), the same one the chat route uses.

Four decoders and six encoders instead of 24 hand-written pairs. A translated request runs the whole chat pipeline: guardrails, budgets and TPM, semantic cache, admission, circuit breaker, fallback, usage and live evaluation.

Client route Native target Reaches through translation
POST /v1/chat/completions openai openai with api: responses (or auto, per request), anthropic, gemini, cohere, bedrock (and sagemaker, oci)
POST /v1/responses openai openai with api: chat_completions, anthropic, gemini, cohere, bedrock
POST /v1/messages anthropic openai (either API), gemini, cohere, bedrock
POST /v1beta/models/{alias}:generateContent, :streamGenerateContent?alt=sse gemini openai (either API), anthropic, cohere, bedrock

Declare the route’s capability on an alias whose target is another provider. The declaration is the opt-in: there is no extra flag beyond the route’s own (anthropic_messages, openai_responses, gemini_generate_content).

features: {anthropic_messages: true, openai_responses: true, gemini_generate_content: true}
models:
# Claude Code against a GPT model.
- id: coder
capabilities: [messages]
targets: [{provider: openai, model: gpt-5}]
# A Responses client against Claude.
- id: assistant
capabilities: [responses]
targets: [{provider: anthropic, model: claude-sonnet-4-5}]
# A Gemini SDK against a model on Bedrock.
- id: travel
capabilities: [generate_content]
targets: [{provider: bedrock, model: amazon.nova-lite-v1:0}]
  • An alias whose targets all speak the route’s dialect natively keeps the native passthrough, byte for byte.
  • If any target is not native, every target of that alias goes through the canonical format, so a fallback never switches dialect in the middle of a request.
  • anthropic, gemini, cohere and bedrock aliases keep one capability per alias. SageMaker and OCI stay chat only.

OpenAI targets: Chat Completions or Responses

Section titled “OpenAI targets: Chat Completions or Responses”

An openai target speaks one of two OpenAI APIs, chosen with api:

models:
# A chat client against a model that only exists on the Responses API.
- id: deep
capabilities: [chat]
targets: [{provider: openai, model: o3-pro, api: responses}]
# A Responses client against a server that only has /chat/completions.
- id: local-agent
capabilities: [responses]
targets: [{provider: vllm, model: qwen3, api: chat_completions}]

The default is responses on a responses alias and chat_completions everywhere else. On the Responses API the gateway sends store: false unless the chat client asked to store, because a chat client does not expect the provider to keep the conversation.

Current OpenAI reasoning models accept some requests only on the Responses API, while most clients and most requests are fine on Chat Completions. With api: chat_completions those requests fail with the provider’s 400; with api: responses every request pays the translation and its refusals (stop, n, logprobs, …). api: auto sends each request to the API it needs:

models:
- id: reasoning
capabilities: [chat, messages]
targets: [{provider: openai, model: gpt-6-luna, api: auto}]

The decision is made for each attempt, on the body that attempt would send: the client’s request after the target’s request parameter policy. The first matching row wins.

# The attempt’s body API wire_api_reason
1 reasoning_effort is an object ({effort, summary}), set by the target’s request_defaults or request_overrides Responses reasoning_effort_object
2 reasoning_effort: max Responses reasoning_effort_max
3 A function tool, and reasoning_effort other than none Responses tools_with_reasoning_effort
4 Rows 1–3 match, but the Responses translation would refuse a field (n, stop, logprobs, seed, a non-function tool, …), unsupported_parameters: drop would remove one, or a message, content part, tool call, tool or response_format has a non-empty member the translation does not map (a message name or refusal text, annotations, a part’s cache_control, …); empty members (null, [], "", {}) and a tool call’s stream index are ignored Chat Completions responses_translation_refused
5 Anything else, including a client’s own reasoning_effort object, tools without reasoning_effort, and reasoning_effort: none Chat Completions chat_completions_sufficient

Why these rows:

  • Rows 2 and 3 are what Chat Completions refuses. Measured on 2026-11-08 against gpt-5.4-nano and gpt-6-luna: Chat Completions answered 400 to reasoning_effort: max (“Supported values are: ‘none’, ‘low’, ‘medium’, ‘high’, and ‘xhigh’”) and to function tools with any effort but none (“use /v1/responses or set reasoning_effort to ‘none’”); the Responses API accepted both. The Chat Completions reference lists max among the values and warns that not every model supports every value; the reasoning guide says Chat Completions does not support function calling with some current models (both read on 2026-11-08).
  • Row 1 is the T101 object form, which only the Responses API carries (reasoning: {effort, summary}).
  • Row 4 keeps auto lossless. A field the Responses translation cannot carry is never dropped or refused because of auto: the request goes to Chat Completions as before and gets the provider’s own answer.
  • Row 5 keeps the established behavior. When the need is not explicit in the body, auto behaves like a target without api. Tools without reasoning_effort stay on Chat Completions even though some models default to a reasoning effort: the gateway does not know a model’s default. To send them to Responses, set the effort on the target (request_defaults: {reasoning_effort: medium}), which row 3 then sees.
  • Paths. On an auto target, paths.chat is the Chat Completions path only; a call on Responses goes to paths.responses when the alias also serves responses and sets it, otherwise to /responses under the connection’s base URL. (api: responses keeps sending its calls to paths.chat, as before.) Both APIs of a target share its circuit breaker, which counts failures per destination: a destination failing on one API is not admitted on the other either. Use auto only with a server that has both APIs: an OpenAI-compatible server without /responses answers 404 to the requests rows 1–3 send there.
  • Native Responses stays native. A /v1/responses request to an alias whose targets all speak Responses natively (api: responses, auto or the default) is passed through as is. On an alias that goes through the canonical format (another target is not native), an auto target decides like any other ingress.

What changes on Responses is what api: responses already does: the request goes with store: false unless the client asked to store, max_completion_tokens becomes max_output_tokens, function tools keep strict: false unless the client set it, and the answer, the stream and errors come back in the Chat Completions shape. The rules apply to every route translated through the canonical format (Chat Completions, Messages, GenerateContent, and Responses on a translated alias), to every attempt of a fallback or retry, and to the quota profile of a single-target alias, which measures the API the attempt uses. A semantic cache entry is the Chat Completions answer either way, so it does not depend on the API.

Each attempt of an auto target logs which API it used and why in upstream_attempt (wire_api, wire_api_reason), the attempt span carries openai.api.type, and the request event has wire_api.

Chat Completions has one field for reasoning, reasoning_effort. Claude has had two request shapes for it, and a model accepts only one of them: the older models take thinking with a token budget, and the models from Opus 4.7 on (Opus 4.7 and later, Sonnet 5 and later, Haiku 5.5, Fable) removed the budget and take adaptive thinking with an effort. A budget sent to one of the newer models is refused with a 400, so a client that sets reasoning_effort fails on them.

Which shape a target takes is declared on the target:

models:
- id: claude
targets:
- provider: anthropic
model: claude-opus-4-8
thinking_mode: adaptive
thinking_mode reasoning_effort becomes Accepted efforts
budget (default) thinking: {type: enabled, budget_tokens: 1024 | 2048 | 4096} low, medium, high
adaptive thinking: {type: adaptive} and output_config: {effort: ...} low, medium, high, xhigh, max
  • It applies to Chat Completions, and to Responses and GenerateContent requests, translated to an anthropic target or to Claude on a bedrock target (there the same fields travel as additional model fields of Converse). Where it would do nothing it is refused when the configuration loads or the model is saved: a target of another protocol, a Bedrock model that is not Claude, a passthrough alias, or an alias with none of the chat, messages, responses and generate_content capabilities. A native /v1/messages request is not changed: the client already wrote thinking in the shape it chose. On a target declared adaptive, a native request that asks for a token budget (thinking: {type: "enabled", ...}) is refused with 422 unsupported_on_provider before the call, naming the field: the model would answer 400 after it, and under a budget a call that went out keeps its reservation. The gateway does not turn the budget into an effort, because no budget maps to one effort; send thinking: {type: "adaptive"} with output_config.effort, or turn thinking off in the client.
  • A request without reasoning_effort does not turn thinking on in either mode.
  • Thinking counts inside the output limit. Under adaptive there is no budget to size it from, so a request without max_tokens gets 8192, and 16384 at xhigh and max; a client’s own limit is sent as it is. Set request_defaults: {max_tokens: N} on the target when answers are cut (finish_reason: length).
  • An effort the mode does not have (minimal, or xhigh under budget) is refused with 422 before the call, naming the field; with another target on the alias, that target is tried.
  • In both modes thinking needs temperature 1 or unset, and top_p is not sent with it. The newer models refuse the sampling parameters altogether: see the sampling drop preset.
  • The newer models return an empty thinking block unless asked for a summary: see reasoning summaries.
  • Why it is declared and not looked up. The gateway does not decide a request’s shape from a model’s name, which changes with every release and alias, nor from the external model catalogue, which is advisory, fetched on demand and absent after a restart. A wrong guess would fail every reasoning request on that target. The model catalogue shows supports_adaptive_thinking for a model, which is where an operator reads the right value.
  • Default. Unset means budget, the behavior before this field existed. Nothing changes on upgrade.
  • Bedrock. The adaptive shape on Converse was not exercised against the real service; it sends the fields Anthropic documents for its own API.

Messages, system prompts, images, tool definitions, tool calls and their results, tool choice, parallel tool calls, temperature, top-p, stop sequences, output limits, structured output, reasoning effort, stop reasons, usage (with cached and reasoning tokens) and errors are mapped in both directions, for JSON and for streams.

Refused before the call (422 unsupported_translation, naming the field), because dropping them would change the answer:

  • Messages: top_k, provider tools (web search, code execution, computer use, text editor, bash), document and search_result blocks, images inside a tool result, container, mcp_servers, context_management, metadata other than user_id.
  • Responses: stored state (store: true, previous_response_id, conversation, background), prompt templates, truncation: auto, max_tool_calls, built-in tools, files and images by file_id, item_reference.
  • GenerateContent: cachedContent, topK, more than one candidate, non-text output, Google tools (search, code execution, URL context), files by URI, non-image inline data, functionCallingConfig VALIDATED.
  • Provider side: each provider encoder still refuses what its API cannot express (for example stop on the Responses API). The refusing target is skipped without a call and the next target is tried; when no target accepts the request, the answer is 422 unsupported_on_provider naming the first and last refusal (fallback across translation refusals). An alias with unsupported_parameters: drop removes such fields instead and names them in X-Gateway-Dropped-Parameters (request parameter policy).

Carried to Claude (T115): prompt cache marks (cache_control on a block, a tool or, in Messages, the whole request) travel in the canonical format as cache_control on a content part, a message or a tool, and reach Anthropic Messages as cache_control and Claude on Bedrock as cachePoint blocks; a target can also place its own points (prompt_cache). Any other target cannot use them: the attempt removes them and cache_control is announced in X-Gateway-Translation-Lossy. A Chat Completions request to an OpenAI Chat Completions target keeps them as sent. See prompt caching.

Left out and announced in the X-Gateway-Translation-Lossy response header, because they steer cost, latency or storage but not the content of the answer: service_tier, metadata, include, prompt_cache_key, stream_options, text.verbosity, safetySettings, labels, and cache_control on a target that is not Claude; and history the canonical format cannot replay: signed thinking blocks, reasoning items, Gemini thought parts and thought signatures. Approximations are listed there too: a thinking budget becomes an effort level (low up to 1,024 tokens, medium up to 2,048 for Messages and 8,192 for Gemini, high above), and a Responses tool without strict is sent without it.

Every translated answer also carries X-Gateway-Translation: <route>>chat.

Other differences to know:

  • A translated Responses answer is never stored: its ID cannot be retrieved or continued with previous_response_id.
  • A Messages stop_reason of stop_sequence comes back as end_turn (Chat Completions does not say which sequence stopped the answer), and translated thinking blocks carry an empty signature.
  • A Gemini function call without an ID is paired with its response by name, in order; the gateway gives it an ID that is stable within the request.
  • Gemini streams function calls whole, so a translated Gemini stream sends each call when its arguments are complete.
  • Without usage from the provider, a Messages answer reports zeros (the format requires the field); Responses and Gemini omit usage.
  • /v1/messages/count_tokens and /v1/responses/input_tokens still need a native target.
  • The Cohere encoder sends text only: an image to a Cohere target is refused with 422 unsupported_on_provider.
  • An OpenAI refusal (finish_reason: stop with refusal text) and Cohere’s safety stop (ERROR_TOXIC) end as a refusal: stop_reason: refusal for Messages, SAFETY for Gemini, incomplete with content_filter for Responses (Cohere) or a refusal part (OpenAI).

Every route translated through the canonical format carries an image as a Chat Completions image_url part: a Messages image block (base64 or url source), a Responses input_image with image_url, and a GenerateContent inlineData image all become one. What reaches the provider depends on the target:

Image Anthropic Gemini and Vertex Bedrock Converse OpenAI, compatible
data:image/{png,jpeg,gif,webp};base64,... image block, base64 source inlineData image block with bytes sent as is
https://... url source (Anthropic fetches it) with image_input_translation refused, or downloaded with image_url_download refused, or downloaded with image_url_download sent as is (the provider fetches it)
a file part (Chat Completions) or input_file (Responses), with its slice refused Gemini’s own part with gemini_file_inputs (file inputs) refused sent as is; the slice fields follow unsupported_parameters while gemini_file_inputs is on
gs://bucket/path.png refused fileData with image_input_translation, only under image_inputs.reference_prefixes and with an image extension refused sent as is
s3://bucket/path.png refused refused s3Location with image_input_translation, only under image_inputs.reference_prefixes and with an image extension sent as is
https://generativelanguage.googleapis.com/.../files/<id> refused refused (image_reference_not_allowed) refused sent as is

An image is never dropped. Without image_input_translation (operator flag, off by default) only data URLs translate, as before: anything else makes the target refuse the request, and the client gets 422 unsupported_on_provider when no target accepts it. With the flag on, a refused image answers 400 with its own code when every target refused it for its image (another target that takes the image, such as an OpenAI one later in the alias, still answers):

  • image_url_requires_download: the target needs the image’s bytes and the URL is not a reference it fetches; send a data URL, or turn on image_url_download. An http:// URL to Anthropic, or a URL with credentials, is refused the same way.
  • image_format_unsupported: a data URL that is not base64 png, jpeg, gif or webp, or a gs:// or s3:// path without an image extension.
  • image_reference_not_allowed: a gs:// or s3:// reference outside image_inputs.reference_prefixes, or a Gemini Files API URI. Vertex and Bedrock read a storage reference with the gateway’s own credentials, so without an approved prefix a caller could have them read any object those credentials can read, other tenants’ included; the list is empty by default, so every storage reference is refused until the operator approves a bucket or path (gs://bucket/ or s3://bucket/path/, ending in /, up to 64). A Files API URI names a file of the provider project every team shares, which the gateway does not own, so it is refused as on Decisions. The prefixes are gateway-wide, not per team.
  • image_download_refused, image_download_failed: see below.

With image_url_download (operator flag, off by default, requires image_input_translation), an https image URL sent to a Gemini, Vertex or Bedrock target is downloaded by the gateway and sent as bytes. A storage reference (gs://, s3://, a Files API URI) is never downloaded: it is passed or refused as above. Each image is downloaded once per request, whatever the number of targets tried. The download is built against server-side request forgery:

  • https on port 443 only, without credentials in the URL; every redirect must stay https on 443, and at most max_redirects are followed.
  • Every address is checked at connection time. The host is resolved, every address it resolves to must be public unicast, and the connection is made to the address that was checked, so a second resolution cannot point it elsewhere (DNS rebinding). Each redirect hop and each new connection is resolved and checked again. Refused: loopback, private (RFC 1918, fc00::/7), link-local (169.254.0.0/16 and fe80::/10, the cloud metadata services 169.254.169.254 and fd00:ec2::254 included), shared address space 100.64.0.0/10, 0.0.0.0/8, multicast, broadcast, benchmark, documentation and reserved ranges, IPv4-mapped addresses of any of these, and the IPv6 forms that embed or route to another address (IPv4-compatible ::/96, IPv4-translated ::ffff:0:0:0/96, NAT64 64:ff9b::/96, 6to4 2002::/16, Teredo 2001::/32). The environment’s HTTP proxy is never used, because it would connect past these checks.
  • Bounded: max_bytes per image (checked against Content-Length and while reading), 32 MiB per request in total, timeout per image including redirects, and max_images downloads per request. A failed download is remembered for the request, so another target does not try it again.
  • An image, checked twice: the answer must be 200 with a Content-Type of image/png, image/jpeg, image/gif or image/webp, and the bytes must sniff as that same type (an HTML page labeled image/png is refused).

A refused download answers 400 image_download_refused (address, scheme, size, type, redirects, too many images) or 400 image_download_failed (timeout, the URL answered another status, the host does not resolve), naming the reason and never the address it resolved to. Nothing reaches the provider.

features:
image_input_translation: true
image_url_download: true
image_inputs:
download:
max_bytes: 5242880 # 1024-20971520, default 5 MiB
timeout: 10s # 1s-60s, default 10s
max_redirects: 3 # 0-5, default 3
max_images: 8 # 1-32, default 8
reference_prefixes: # gs:// and s3:// prefixes callers may name; empty by default (all refused)
- gs://shared-images/

The settings are read on every request. GET /api/v1/admin/image-inputs (providers:read, either flag on) and the Image inputs panel in Providers show the flags, the effective bounds and the reference each provider family fetches. The answer carries the settings as an image_inputs object (download and reference_prefixes), named after the YAML block. Both flags are operator controls, not plan rights.

Verified with real providers (2026-11-17): an 8x8 PNG data URL encoded by the gateway reached Anthropic (claude-haiku-4-5, 20 input and 4 output tokens) and Gemini (gemini-3.5-flash-lite, 1,089 image tokens) as native bytes, and both answered its color. Two calls, under US$0.001 in total. Bedrock (bytes and s3Location) is covered by tests against the documented Converse shape only; it needs an AWS account.

Send the gateway key as Authorization: Bearer <key>. Because the Anthropic and Google SDKs put the key in their own header, the gateway also accepts it in x-api-key on /v1/messages and in x-goog-api-key on the GenerateContent routes, when there is no Authorization header. A key in the URL (?key=) is refused with 400: query strings end up in logs.

anthropic.Anthropic(base_url="https://gateway.example.com", api_key="<gateway key>")
genai.Client(api_key="<gateway key>", http_options={"base_url": "https://gateway.example.com"})

:streamGenerateContent serves the SSE stream (?alt=sse, which the SDKs send); the JSON-array stream without alt=sse is refused with 400.

  • A provider error comes back with its status in the client route’s own error shape: {"type":"error","error":{...}} for Messages, the OpenAI envelope for Responses and Chat Completions, {"error":{"code","message","status"}} for Gemini. The provider’s message is kept. Errors raised by the gateway itself (authentication, limits, refusals) keep the gateway’s shape, as on every route.
  • A stream that fails after the first byte, ends without the provider’s end marker, or loses its connection ends with the route’s own error event (an error chunk for Chat Completions, error for Messages, response.failed for translated Responses and error for native ones, an error object for Gemini). It never ends with message_stop, response.completed, a finish reason or [DONE]. This holds on the native routes too.
  • When the provider sent its own error event, its message and kind go to the client (an overloaded provider stays overloaded_error for Messages, UNAVAILABLE for Gemini); stream_interrupted is only for a stream that broke without one. Either way the request is recorded as failed (error_code: stream_interrupted in the request log and in every error count, a provider error in the metrics, an error span), although its status is the 200 already sent.
  • A provider that answers a stream request with a buffered JSON body gets a 502 provider_did_not_stream before the client’s stream starts.
  • The provider’s Retry-After on 429 and 503 is passed on.
  • A provider redirect is never followed: it answers 502 provider_redirect, without the Location.
  • An AWS authentication error is replaced by a fixed message: on a signature mismatch AWS repeats the signed request, session token included, and that never reaches the client.
  • A refusal from the provider names the field as the client sent it (thinking, reasoning.effort, generationConfig.thinkingConfig).
  • Parallel tool calls stream as separate blocks or items keyed by call, so interleaved argument deltas stay with their call.
  • Every route falls back on transport errors, 429 and 5xx before the first byte, like chat. A translated /v1/responses request is always stateless (its decoder refuses stored state), so it falls back too; a native one falls back only when stateless (Responses fallback).

m7gtwcontact@m7gtw.com