> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gloo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Provider Failover

> How Gloo AI keeps serving the model you asked for when the provider behind it fails, when it deliberately does not retry, and what your application should still handle.

Most models in the Gloo AI catalog can be served from more than one provider. When the provider currently serving a model is failing, Gloo sends your request to another provider that serves **the same model**. This is **provider failover**, and it runs on every chat and responses endpoint with no configuration.

> [!TIP]
>
> Getting an app ready for real traffic? [Production-Ready](https://docs.gloo.com/ai-learning-center/gloo-ai-104/production-ready.md) in the AI Learning Center covers retries, failover, routing and model deprecations together.

Failover changes *who* serves your request, never *what* you get: the `model` in the response is the `model` you asked for. (Model deprecation is separate from failover: a deprecated model ID with a `replacement_model` is served by that replacement, and the response's `model` names the replacement. See [Model Lifecycle](https://docs.gloo.com/api-guides/model-lifecycle.md).) It is separate from [auto-routing and `model_family`](https://docs.gloo.com/api-guides/completions-v2), which choose a model for you on the guarded Completions endpoint.

## When a request fails over

Failover handles failures that belong to the provider, not to your request:

* **Provider errors and outages.** A timeout, a lost connection, a provider server error, an empty response, or the provider refusing the request because it is over capacity or rate-limited. Gloo retries the request on another provider serving the same model.
* **A provider that can't take the request.** When a provider can't take a request for reasons on its side, including as a stream opens, Gloo sends the request to another provider that serves the same model. If no provider can take it, you receive a `503` with `retryable: true`: `2002 / PROVIDER_UNAVAILABLE` when the providers are unavailable (retry with backoff), or `3003 / SERVICE_UNAVAILABLE` with a `Retry-After` header when the problem is on Gloo's side (wait, then retry). See [Every provider unavailable](https://docs.gloo.com/api-reference/general/errors.md#every-provider-unavailable).
* **A provider that keeps failing.** Gloo tracks each provider's health per model. When a provider starts failing for a model, new requests for that model go to a healthy provider instead of the failing one, which returns to service automatically once it recovers.
* **A stream that fails before the answer starts.** If a streamed request fails before any text reaches you, Gloo retries it, on another provider when needed, and the answer starts from the beginning. You see the stream start later, not an error.
* **A stream cut off mid-answer.** For models that support it, another provider continues the answer from where the stream stopped, in the same response. For models that do not, the stream ends with an error event instead; see [Handling Streaming Failures](https://docs.gloo.com/best-practices/completions-streaming-failures.md) for how to continue it from your application.

Failover works within a time budget for each request. If no provider answers within it, you receive the error instead of waiting indefinitely.

> [!NOTE]
>
> Not every model has a second provider. For a model served from only one place, failover has nowhere to send the request, and a provider outage returns an error.

A request that uses the `image_generation` tool goes only to a provider that can run the tool. When none can, you get a `503` with `2002 / PROVIDER_UNAVAILABLE` and `retryable: true`, rather than an answer from a provider that cannot draw images. See [Image generation errors](https://docs.gloo.com/api-reference/general/errors.md#image-generation-errors).

## When a request does not fail over

Some failures would fail the same way on every provider, so Gloo returns them straight away instead of repeating the request elsewhere:

| Situation | What you get | What to do |
| :- | :- | :- |
| Invalid request, unsupported model, or input longer than the model's [context window](https://docs.gloo.com/ai-learning-center/gloo-ai-101/prompting-and-generation.md#context-window) | A `400` client error | Fix the request. See [Errors](https://docs.gloo.com/api-reference/general/errors.md). |
| Your [API key](https://docs.gloo.com/studio/manage-api-credentials.md) or organization is not authorized | A `401` or `403` (on the direct endpoints, `authentication_error` or `account_suspended`) | Check your credentials, or [contact support](https://docs.gloo.com/getting-started/support.md#contact-support) for a suspended organization. |
| The provider's content policy blocks the request or the answer | A content-filter error, or `finish_reason: "content_filter"` on a stream | Change the request. Do not retry it unchanged. On the direct endpoints, when a provider's moderation layer (not the model itself) refuses the request outright, before any stream starts, Gloo first tries it once on a different provider; a [guardrail](https://docs.gloo.com/ai-learning-center/gloo-ai-102/guardrails-and-values.md) block or the model's own refusal is final. See [Content Policy Refusals](https://docs.gloo.com/api-reference/general/errors.md#content-policy-refusals-direct-endpoints). |
| Your [organization](https://docs.gloo.com/getting-started/glossary.md#organization) is out of credit or at its [spending limit](https://docs.gloo.com/studio/billing.md#spend-limits) | A `402` or `429` with `fault: "client"` | Resolve the limit. See [Limits](https://docs.gloo.com/api-reference/general/limits.md). |
| A [reasoning model](https://docs.gloo.com/ai-learning-center/gloo-ai-102/models-that-think.md) spent your whole output limit before writing any visible text | A normal response that stopped at the limit (below) | Raise the output limit or lower the reasoning effort. |

### Reasoning models and the output limit

On reasoning models the output limit (`max_tokens` on Chat Completions, `max_output_tokens` on Responses) holds the thinking as well as the answer, so a limit that's too small for the effort can be used up before the model writes any text. See [Set your output limit for reasoning models](https://docs.gloo.com/api-guides/reasoning.md#set-your-output-limit-for-reasoning-models) for how Gloo applies the limit and how to size it.

The provider answered correctly and would answer the same way again, so this is **not** retried or failed over. Gloo returns the provider's answer:

* **Chat Completions**, [streaming](https://docs.gloo.com/ai-learning-center/gloo-ai-104/streaming-responses.md) and non-streaming: the response ends with `finish_reason: "length"` and no text, and `usage` reports the tokens the model used.
* **Responses** (non-streaming, OpenAI reasoning models): HTTP `200` with `status: "incomplete"` and `incomplete_details: {"reason": "max_output_tokens"}`, plus a `suggestion` field that names the tokens used and the limit you sent.

Raise the limit or lower the reasoning effort, leaving generous headroom above the length of the answer you expect; the [sizing table](https://docs.gloo.com/api-guides/reasoning.md#size-the-limit) gives starting points.

## Which endpoints fail over

| Endpoint | Failover |
| :- | :- |
| Guarded [Responses](https://docs.gloo.com/api-guides/responses.md) and [Completions](https://docs.gloo.com/api-guides/completions-v2.md) | Yes |
| [Direct Responses](https://docs.gloo.com/api-guides/direct-responses.md) and [Direct Completions](https://docs.gloo.com/api-guides/direct-completions.md) | Yes |
| [Grounded Responses](https://docs.gloo.com/api-guides/grounded-responses.md) and [Grounded Completions](https://docs.gloo.com/api-guides/grounded-completions.md) | Yes |
| [Anthropic Messages](https://docs.gloo.com/api-guides/anthropic-messages.md) | No. Served directly by Anthropic. Retry a `529` after `retry-after`. |
| [Embeddings](https://docs.gloo.com/api-guides/embeddings.md) | No. A provider failure returns a `503` with `retryable: true`. |

## What you observe

* **The same model.** The response carries the `model` you requested, whichever provider served it. A deprecated model ID that has a replacement is the exception: the response names the replacement that served it.
* **Extra latency.** A request that failed over waited for the failed attempt first.
* **A colder prompt cache.** [Prompt caches](https://docs.gloo.com/ai-learning-center/gloo-ai-104/cost-and-speed.md#prompt-caching) are held by each provider, so a request served by a different provider does not read the cache built on the original one. Expect fewer cached tokens on requests that failed over, and on requests routed around an unhealthy provider, until the cache warms on the new one. See [Prompt Caching](https://docs.gloo.com/api-guides/prompt-caching.md).
* **Stream headers from the first attempt.** A stream's response headers, such as `X-Ignored-Params`, are sent before the first chunk, so they describe the request as it started and aren't updated if it then fails over.
* **No charge for the failed attempt.** An attempt that failed and was replaced by another provider is not billed.
* **An error only when failover could not help.** Errors you receive carry the standard [error object](https://docs.gloo.com/api-reference/general/errors.md#ai-error-object): `fault` says whether the problem was your request, the provider, or Gloo, and `retryable` says whether the same request may succeed if you send it again.

## What your application should do

1. **Rely on failover for provider trouble.** You don't need to switch models or add a second provider yourself to ride out an outage.
2. **Still retry retryable errors.** When an error has `retryable: true`, retry: after the `Retry-After` delay when the response has one, otherwise with exponential backoff. See [Error Handling and Retries](https://docs.gloo.com/best-practices/error-handling-and-retries.md). A later request benefits from Gloo having already routed around the failing provider. Do not retry errors with `retryable: false` unchanged, including `3001 / INTERNAL_ERROR`.
3. **Handle interrupted streams.** On models where Gloo cannot continue a cut-off stream, the stream ends with an error event after partial output (a `response.failed` event on Direct Responses). A provider failure mid-stream arrives as a provider error code (for example `2014 / PROVIDER_STREAM_ERROR`) with `retryable: true`; `3001 / INTERNAL_ERROR` is an error on Gloo's side with `retryable: false`. Follow [Handling Streaming Failures](https://docs.gloo.com/best-practices/completions-streaming-failures.md).
4. **Size output limits for reasoning models.** Treat `finish_reason: "length"` or `status: "incomplete"` with no text as a sign to raise `max_tokens` or `max_output_tokens`, or to lower the reasoning effort, not as an outage.
5. **Log `trace_id`.** Include it, with the `X-Request-Id` response header on the direct endpoints, when you contact support about a failed request.

## Next steps

For what each endpoint family runs around your request, see [Endpoint Types](https://docs.gloo.com/api-guides/endpoint-types.md). For how caching works on each provider, see [Prompt Caching](https://docs.gloo.com/api-guides/prompt-caching.md).

> [card] [Build a resilient client](https://docs.gloo.com/tutorials/resilient-client.md)
>
> Put retries and failover handling into a working client.

> [card] [Error Handling and Retries](https://docs.gloo.com/best-practices/error-handling-and-retries.md)
>
> Which errors to retry, backoff, and retry budgets.

> [card] [Handling Streaming Failures](https://docs.gloo.com/best-practices/completions-streaming-failures.md)
>
> Retry and continuation after a stream fails.

> [card] [Errors](https://docs.gloo.com/api-reference/general/errors.md)
>
> Error codes, `fault`, and `retryable`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.