Skip to content

Response headers for clients

Last updated: 2026-11-22T06:50:00-03:00 (UTC-3)

Every inference answer carries X-Request-Id, traceparent and X-Gateway-Provider, and a provider’s Retry-After on 429 and 503. An application that paces itself, or reports what a call cost, can also receive the provider’s rate-limit budget, the target that answered, the number of provider sends and the cost. Each of these is opt-in under server.response_headers, because each tells the client something about the operator rather than about its own request.

server:
response_headers:
provider_rate_limits: true # relay the provider's x-ratelimit-* budget
attempts: true # X-Gateway-Attempts
served_target: true # X-Gateway-Served-Model
cost: true # X-Gateway-Cost-USD, when known
stream_cost: true # also gateway_cost_usd in a stream's final usage event
Parameter Default What the client receives Why it is off by default
server.response_headers.provider_rate_limits false The provider’s x-ratelimit-limit-requests, x-ratelimit-limit-tokens, x-ratelimit-remaining-requests, x-ratelimit-remaining-tokens, x-ratelimit-reset-requests and x-ratelimit-reset-tokens, as the provider sent them on the answer being relayed They describe the operator’s provider account, which every key and team on that connection shares: one tenant would see the others’ consumption
server.response_headers.attempts false X-Gateway-Attempts: how many provider sends the answer took, retries and fallbacks included It reveals retries and fallbacks
server.response_headers.served_target false X-Gateway-Served-Model: the model of the alias target that answered, such as gpt-4o-mini It reveals how an alias is routed
server.response_headers.cost false X-Gateway-Cost-USD: the valued cost of the request in USD, such as 0.000017 It reveals the operator’s prices
server.response_headers.stream_cost false The same cost as gateway_cost_usd on a stream’s final usage event (in-band cost); requires cost Same as cost

The block is read at startup; restart each replica to change it. Settings & sources → Infrastructure → Inference HTTP lists the parts that are on (infrastructure.inference_http.response_headers). It applies to the inference API (/v1/* and the native Gemini /v1beta/*), never to the console or the admin API.

What each header contains, and when it is absent

Section titled “What each header contains, and when it is absent”

Provider rate limits. Only the six names above are relayed; other provider headers (organization, project, processing time and so on) never are. A value is relayed only when the provider sent it once and it looks like a budget (a number, a duration such as 6m0s, or a timestamp). They come from the provider response the gateway relays, so after a fallback they describe the target that answered. Providers that use other names, such as Anthropic’s anthropic-ratelimit-*, are not relayed.

Attempts. The number of provider sends for this request, counted as in the request events; after a semantic fallback it adds the refused first send to the fallback’s own. It is absent when no provider was called (a cache hit, or a refusal before dispatch).

Served model. The model of the target that answered, from the alias configuration. It is sent only when it is a plain model name: a path or an ARN (for example a Bedrock inference profile, which contains the AWS account number) is not sent. The header never carries a provider credential or internal identifier.

Cost. The same exact decimal the request log and request events value, without trailing zeros. It needs usage_valuation and a price for the model that answered, and for streams the stream_usage flag, which meters them. It is never estimated: when the cost is unknown (no price, no reported usage, an error answer, several provider sends, an indeterminate durable outcome) the header is absent, never 0.

A buffered answer that the gateway holds until the request is recorded (with budgets, TPM or usage analytics on) gets the cost as an ordinary header. A stream, or an answer already on its way, is sent before its cost is known, so the cost follows it as an HTTP trailer: the response announces Trailer: X-Gateway-Cost-USD and the value arrives after the body, or not at all when unknown.

HTTP/1.1 200 OK
Content-Type: text/event-stream
X-Gateway-Attempts: 1
X-Gateway-Served-Model: gpt-4o-mini
X-Ratelimit-Remaining-Requests: 9999
Trailer: X-Gateway-Cost-USD
data: ...
X-Gateway-Cost-USD: 0.0000027

Trailers arrive after the body; many HTTP clients do not expose them (Go’s net/http does, in Response.Trailer once the body is read; a browser’s fetch does not), and some proxies drop them. Turn on the in-band cost, or read it from the request events or usage analytics instead.

server.response_headers.stream_cost: true (default false; requires cost: true) also writes the cost on the stream itself, for clients that cannot read trailers, such as a browser’s fetch. The stream’s final usage event gains one top-level member, a decimal string:

data: {"id":"chatcmpl-1","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":9,"completion_tokens":4,"total_tokens":13},"gateway_cost_usd":"0.000017"}
data: [DONE]
API Final usage event
Chat Completions The last chunk that carries usage: the usage-only chunk (the client asks for it with stream_options.include_usage: true), or the finishing chunk of a provider that puts usage there
Responses response.completed or response.incomplete
Messages The message_delta that carries usage
  • The value is the trailer’s, from the same valuation, and the unknown rule is the same: when the cost is not known the member is absent, never 0. The trailer is still sent.
  • Responses that may carry it say so with X-Gateway-Stream-Cost: gateway_cost_usd (also exposed to browsers under CORS), sent when stream_cost is on and stream_usage meters streams. A gateway_cost_usd the upstream itself put on the final usage event is removed, so a client that sees the header can trust the member; without the header, ignore any member of that name.
  • The member is written only once the provider’s end has been seen: the provider closed the stream, or it sent its terminal event and the stream then stopped. To do that, the gateway holds the final usage event and the closing events after it (the [DONE] line; ping and message_stop) until then, within 512 KiB. Any other event after it shows it was not the final one: what was held goes at once, unchanged. Past the bound, or when the stream is cut, the held events are released unchanged and without the member. Nothing else in the stream changes, and the framing (line endings, event names) is kept.
  • If the request is cancelled (the client leaves, a stream deadline, a gateway stop) after the provider’s last event but before it closed the stream, the held events cannot be written any more: the request event records the stream as cut by the client instead of delivered.
  • A usage event whose JSON spans several data: lines is relayed unchanged. Gemini generateContent streams are not covered.

Settings & sources → Infrastructure → Inference HTTP and GET /api/v1/admin/config (infrastructure.inference_http.response_headers) show which parts are on.

Nothing changes until a part is turned on. Before rolling back to an older binary, remove server.response_headers (and stream_cost before rolling back below T164.011), because its strict YAML refuses it.

m7gtw[email protected]