Inference retries
Last updated: 2026-11-27T01:08:49-03:00 (UTC-3)
A transient 429 or 503 does not have to become an error for the client. For chat, Messages, Responses, embeddings, moderations and rerank, the gateway can repeat the call a few times on the same target, with a growing, randomized wait, respecting the provider’s Retry-After. Flag: inference_retries.
How to enable it
Section titled “How to enable it”features: inference_retries: truemodels: - id: assistant capabilities: [chat, messages, responses] retry: max_attempts: 2 # per target, counting the first send initial_backoff: 100ms max_backoff: 2s targets: - {provider: openai, model: gpt-4.1-mini} - {provider: gemini, model: gemini-2.5-flash}| Field | Values |
|---|---|
max_attempts |
2 or 3 sends per target in total, including the first one. Required |
initial_backoff |
10 ms to 1 s. Required |
max_backoff |
between initial_backoff and 10 s. Required |
The policy applies to aliases with at least one target and one of the capabilities chat, messages, responses, embeddings, moderations or rerank (an alias without capabilities serves chat). In the console: Model catalog → Edit routing → Bounded inference retries, with versioning, audit and revert to YAML. Without retry, nothing changes. The API is PUT /api/v1/admin/models/{id} with the same retry object.
Retry first, then fall back
Section titled “Retry first, then fall back”On an alias with several targets, each target gets its own max_attempts before the alias falls back to the next target, in the alias order. With two targets and max_attempts: 2, a request sends at most four times: two to the first target, two to the second.
Why this order: a 429 or 503 is usually a short, local condition of one destination (a rate window, a busy replica). Retrying it first keeps traffic on the target the operator put first, usually the cheaper or preferred one, and only a target that stays unavailable passes the request on. A failure that retrying cannot fix moves on at once:
- A
500and other 5xx outside the list below are not retried; the alias falls back to the next target, as it does without a policy. - A refused admission (no destination slot) or an open circuit breaker does not wait for another attempt; the alias falls back, or answers 503 on the last target.
- A target that cannot express the request in its protocol is skipped without any send (see fallback across translation refusals).
How it works
Section titled “How it works”- Retries only on: transport failure, 429, 502, 503 and 504. A 500 is not retried.
- Wait: exponential with full jitter. The ceiling doubles on each attempt up to
max_backoff, and the actual wait is a random value between zero and that ceiling. Retry-After: when the provider sends it, it becomes the minimum wait (seconds or an HTTP date). If it is invalid or larger thanmax_backoff, the gateway does not retry that target and moves on as if the attempts were spent: the next target, or the original response,Retry-Afterincluded, on the last one.- Total deadline: the configured operation deadline covers the whole call, including waits and response consumption.
models[].request_timeoutoverridesnetwork.request_timeout; the compiled network default is two minutes. A wait that would end after the deadline is not taken; the gateway keeps the answer it has. Canceling the request interrupts the wait (499). - Attempt timeout: with
attempt_timeoutson, the alias’sattempt_timeoutbounds how long each attempt may wait for the provider to start answering. An attempt it ends is not repeated on the same target: the next target is tried, or the client gets 504. - Capacity and circuit breaker: the target’s slot is released during the wait and requested again on each attempt; the circuit breaker can block an attempt.
- Tracing: each send has its own span and an
upstream_attemptlog, with the same request ID. Under a policy the log record also carriesattempt(1, 2, 3) andmax_attempts.
Before the first byte, never after
Section titled “Before the first byte, never after”A send is repeated only while nothing has reached the client.
- JSON answers. The decision is made on the provider’s status line, before any header or byte is sent to the client.
- Streams. With a policy, the gateway holds a streamed answer until its first byte before it starts the client’s stream, while another send (a retry or a next target) remains. A provider whose stream closes or fails before that first byte is retried like a transport failure. Once the first byte has been relayed the stream belongs to that send: a later break is reported to the client as an interrupted stream and is never repeated. The client’s response headers wait for that first byte; without a policy streams are relayed at once, as before.
- Translated streams. For a target the gateway translates (Anthropic, Gemini, Bedrock, Cohere, OCI, or an OpenAI target with
api: responses, orapi: autowhen it chose Responses), a provider stream that breaks before its first event becomes an in-band error event of the translated stream, which is the first byte: it is relayed and not retried. A failure before the provider’s response headers is still retried. - Stream clocks. A stream timeout that fires (
first_byte,idle,max_duration) is not retried on the same target: the provider accepted the request and was still working on it, so a second send would pay for the same generation twice. It still falls back to the next target, as without a policy. - Answers already served. A body the gateway could not read or translate after the provider answered, and a buffered JSON answer to a stream request (
provider_did_not_stream), are not retried: the provider did the work.
Native Gemini generateContent
Section titled “Native Gemini generateContent”gemini_retries (off by default; requires inference_retries) lets an alias’s retry policy also repeat native Gemini POST /v1beta/models/{model}:generateContent and :streamGenerateContent (T168), with the same attempts, backoff and Retry-After floor: a retryable status (429, 502, 503, 504) or a transport failure is repeated on the same target, before the next target, and only before any byte reaches the client. A request with cachedContent or a provider-hosted tool is sent once per target. The flag also gates the translated generateContent ingress (a generate_content alias served by another provider). The console offers the policy on a generate_content alias only with the flag on.
What is never retried
Section titled “What is never retried”Each case is something a second send could duplicate or break.
| Request | Retried | Why |
|---|---|---|
| Chat Completions, with or without function tools | Yes | The provider keeps no conversation state; the client resends the history and runs its own tools |
Chat with a hosted tool (a tools[].type other than function or custom, or web_search_options) |
No | The tool runs at the provider; its effect or charge could happen twice |
| Messages | Yes | Same as chat |
Messages with container, mcp_servers or a server tool (any tools[].type other than custom) |
No | Code execution, remote MCP calls and server tools act at the provider |
| Responses, stateless | Yes | Same as chat |
Responses with store: true |
Yes | The client only ever receives the ID of the send that succeeded. A failed send may still leave a stored response at the provider (for example after a transport failure), but nothing references it |
Responses with previous_response_id or conversation |
No | The state lives at one provider; the continuation stays pinned there |
Responses with background, a stored prompt, an item_reference input, a reasoning item without encrypted_content, a file_id content part or a hosted tool (code interpreter containers, file or web search, MCP, image generation, computer use) |
No | Each continues or creates provider state, reads a stored object, or acts from the provider |
Embeddings, moderations, rerank with stream, tools, tool_choice, functions, function_call, previous_response_id, conversation or background |
No | Unknown extensions that could select streams, tools or state never inherit permission to replay |
Native Gemini :generateContent and :streamGenerateContent, with gemini_retries |
Yes | Stateless like chat, with or without client function declarations (tools[].functionDeclarations); before the first byte only |
Gemini with cachedContent (or cached_content) or a hosted tool (googleSearch, codeExecution, urlContext, …) |
No | The cached context lives at one provider; hosted tools act from it |
Gemini without gemini_retries, decisions, MCP tools, audio, image, video |
No | Not covered by this policy |
The same rules decide Responses fallback: a request that is not retried is not sent to another target either.
Things to watch for
Section titled “Things to watch for”- Billing. Repeating a POST can lead to a new charge at the provider, for example when a transport failure happened after the provider started the work. Turn it on only where that is acceptable.
- Estimated cost. The reported usage comes from the last response; when there was more than one send, valuation marks the cost as unknown. The receipt represents the client’s request, not each send.
- Budgets and TPM. A quota reservation covers one send to one target. When a budget or TPM policy covers the alias, a request to an alias with a retry policy is refused with 422 before any provider call, as one to an alias with more than one target is.
Limits
Section titled “Limits”- At most
max_attempts × targetssends per request, all inside the request deadline. - The decision is per process; retries are not coordinated across replicas.
- Turning the flag off stops retries on new requests; requests already admitted keep the configuration they were admitted with.
Upgrade notes
Section titled “Upgrade notes”- The single-target rule is gone: a
retrypolicy is valid on an alias with any number of targets, and onchat,messagesandresponsesaliases. Existing embeddings, moderations and rerank policies behave as before on a single target, with two refinements: a transport-failure retry now also needs its wait to fit the deadline, and an answer the gateway received but could not read (an adapter’s normalization error) is no longer sent again. - An alias with chat that already had no
retryis unchanged. Addingretryto a chat alias delays the client’s stream headers until the provider’s first byte.
See also
Section titled “See also”- Routing and resilience, including fallback across translation refusals and Responses fallback.
- Circuit breaker.
- Weights and capacity per target.
- References: Retry-After in RFC 9110.
Shared policy definitions
Section titled “Shared policy definitions”The parameter registry shares the existing retry bounds with Go validation and console controls. All three members are required when a retry policy is configured; omitting the policy adds no retries. The form’s initial values (2 total attempts, 100ms initial backoff and 2s maximum) are creation presets, not backend defaults. Maximum backoff must also be at least the configured initial backoff.