# Routing and resilience

**Last updated:** 2026-11-27T01:08:49-03:00 (UTC-3)

Providers go down, slow down and change their prices. With more than one target per alias, the gateway chooses where to send each request and tries another one when the first fails, without the app noticing.

## What's available

| Feature | What it does | Flag | Learn more |
|---|---|---|---|
| **Fallback** | Transport error, 429 or 5xx before the first byte, or a target that cannot express the request: tries the next target. Stateless Responses included | (always) | [Below](#fallback-across-translation-refusals) and [Routing and admission](/docs/features/routing-and-admission/) |
| **Semantic fallback** | Alternative targets for context overflow or a content policy refusal | `semantic_fallbacks` | [Strategies](/docs/features/routing-strategies/) |
| **Context window check** | Skips a target whose declared `max_input_tokens` the request clearly exceeds, before any provider call, then the next target or the context fallback | `context_window_check` | [Context window check](/docs/features/context-window-check/) |
| **Weight** | Splits traffic between targets by weight | `weighted_routing` | [Routing and admission](/docs/features/routing-and-admission/) |
| **Latency** | Prefers the target that responded fastest, with periodic probing of the others | `latency_routing` | [Latency](/docs/features/latency-routing/) |
| **Cost and load** | Prefers the cheapest or the least busy target | `routing_strategies` | [Strategies](/docs/features/routing-strategies/) |
| **Conditional targets** | Restricts eligible targets by authenticated key/team IDs and admitted tags | `conditional_routing` | [Conditional routing](/docs/features/conditional-routing/) |
| **Tags** | The client asks for a target by tag, such as region or quality | `tag_routing` | [Strategies](/docs/features/routing-strategies/) |
| **Automatic routing** | Chooses the model by the meaning or the difficulty of the question (locally or with a classifier model), on Chat Completions, Messages and Responses, and shows the savings per key | `auto_routing` | [Automatic routing](/docs/features/auto-routing/) |
| **Tool-aware routing** | For coding agents and other tool loops: reads what the tools returned and moves the session to a stronger model after repeated failures and back after the work passes, with holds so the provider's prompt cache is not thrown away on every turn | `tool_aware_routing` | [Automatic routing, trajectory strategy](/docs/features/auto-routing/#trajectory-strategy) |
| **Circuit breaker** | Stops sending traffic to a failing target for a while | `circuit_breaker`, `resilience_management` | [Resilience](/docs/features/resilience/) |
| **Concurrency cap** | A bounded queue and a cap on concurrent requests per target | `destination_limits` | [Routing and admission](/docs/features/routing-and-admission/) |
| **Retries** | Bounded retries on the same target, with jitter, before falling back; chat, Messages, Responses, embeddings, moderations, rerank | `inference_retries` | [Retries](/docs/features/inference-retries/) |
| **Request parameters** | Per-target defaults, overrides, an output-token ceiling and removed parameters (by name or by path), applied to each attempt; asks for a reasoning summary; refuse or drop what a translated target does not support | `request_parameter_policy` | [Request parameter policy](/docs/features/request-parameter-policy/) |
| **Attempt timeout** | Bounds how long each provider attempt may take to start answering, so a hung target hands over to the next one inside the total deadline | `attempt_timeouts` | [Network and timeouts](/docs/operate/network-configuration/#attempt-timeout) |
| **Emergency stop** | Cuts off all inference, on every replica, with one command | (always) | [Incident response](/docs/security/incident-response/) |

## Fallback across translation refusals

An alias can mix protocols: an OpenAI target and a Gemini target, for example. Each target's encoder accepts only what its API can express; Gemini has no `logprobs`, Anthropic has no `seed`. When the target in turn cannot express the request, the gateway **skips it without calling the provider** and tries the next target. Nothing is sent, no slot or circuit-breaker probe is taken, and the skipped target counts as no attempt for valuation.

```yaml
models:
  - id: assistant
    targets:
      - {provider: gemini, model: gemini-2.5-flash}   # refuses logprobs
      - {provider: openai, model: gpt-4.1-mini}       # serves it
```

A chat request with `"logprobs": true` goes to the OpenAI target; the answer carries `X-Gateway-Provider: openai`. The log has one `upstream_attempt_skipped` record for the Gemini target, with `reason: translation_refused` and, when the refusal names a known request member, that name in `field` (never client text), and a `provider.chat.skipped` span; the OpenAI send has its usual `upstream_attempt`.

When **no** target accepts the request, the client gets `422 unsupported_on_provider`. With one target the message is that target's own refusal, as before. With several, it names the first and the last:

```json
{"error": {"code": "unsupported_on_provider",
  "message": "No target of this model accepted the request. First refusal (gemini): logprobs is not supported by the Gemini API; last refusal (anthropic): logprobs is not supported by the Anthropic Messages API"}}
```

- This applies to every route that goes through the canonical chat format: chat, and Messages, Responses and Gemini requests translated for a target of another protocol.
- [`unsupported_parameters: drop`](/docs/features/request-parameter-policy/#unsupported-parameters-refuse-or-drop) still removes such fields instead of skipping the target; the skip happens only when the target would refuse.
- An ingress refusal (`422 unsupported_translation`, such as `previous_response_id` on a translated Responses request) is about the client's dialect, not a target, and is not skipped.
- The native adapters of other operations (embeddings, images, audio) still answer 422 from the target that refuses.

## Responses fallback

`/v1/responses` falls back like chat when the request is **stateless**: transport error, 429 or 5xx before the first byte moves it to the next target, and [weights and strategies](/docs/features/routing-and-admission/#how-weights-work) choose the first target. A request that continues or creates provider state keeps the declared order and a single send, at the provider that holds the state:

- `previous_response_id` or `conversation` (with `responses_lifecycle` or `conversations`, the signed ID names the provider, and the request goes only there);
- `background` mode, a stored `prompt`, an `item_reference` input, a reasoning item without `encrypted_content`, a content part with `file_id`;
- containers and hosted tools (code interpreter, file or web search, MCP, image generation, computer use); only `function` and `custom` tools run at the client.

`store: true` does not pin the request: the client only receives the ID of the send that succeeded, and its signed ID names the provider that served it. A failed send may still leave a stored response at its provider, which nothing references.

Responses translated for a non-OpenAI target were already stateless (their decoder refuses stored state with 422), so they now fall back too. The same rule decides whether a Responses request may be [retried](/docs/features/inference-retries/#what-is-never-retried).

## What doesn't happen

- Once the response has started arriving, there is no retry or fallback: a stream is never repeated.
- Stateful Responses (`previous_response_id`, `conversation`, background, containers, hosted tools) stay on the provider that holds the state.
- A fallback or retry after the provider has received the request can be billed twice; this shows up in usage as attempts.
