How do you add fallback across LLM providers?
You add fallback across LLM providers by giving each request an ordered list of candidates instead of a single model and provider, and having a routing layer try the next candidate when one is rate-limited, unavailable or returns an error. You can write that retry logic in application code or use an LLM gateway that applies it per request. With FastRouter, you add a models array of fallback models to a chat completions request, set a provider order for models served by several providers, or call a virtual model alias that has fallback built in.
Last updated
Key facts
- Fallback means trying an ordered list of models or providers until one returns a successful response.
- In FastRouter, the model field sets the primary model and the models array lists fallbacks, tried in order.
- FastRouter falls back when a model is unavailable or returns an error, for example from rate limits, downtime or moderation.
- Billing is based on the model that actually processes the request, and the response's model field reports which one ran.
What is LLM provider fallback?
LLM provider fallback is a reliability pattern in which a request that fails on one model or provider is retried on another. The caller defines the candidates and their order in advance, so a rate limit or an outage at one provider becomes a retry elsewhere instead of an error returned to the user.
There are two levels. Model fallback moves to a different model, which may come from a different provider. Provider fallback keeps the same model and moves to another provider that serves it.
What is the general approach to adding fallback?
Decide which failures should trigger a retry, choose backup candidates that can handle the same request, put them in order of preference and record which candidate answered. The logic can live in your application, where you maintain it for every provider SDK, or in a gateway that all requests pass through.
- Choose backups on different providers, so one provider's incident does not remove every candidate.
- Check that each backup accepts the same request parameters and gives acceptable output for your prompts.
- Log which model and provider served each request, because cost and behavior follow the candidate that ran.
How do you set up fallback with FastRouter?
FastRouter applies fallback per request. You list backup models in a models array, optionally set a provider order for models that several providers serve, and can move the whole list behind a virtual model alias so it is managed in the dashboard.
- Choose a primary model and ordered backups. Pick the model you want to answer by default, then one or more backups in order of preference. Listing candidates across different providers reduces the chance that every candidate fails at once.
- Add a models array to the request. Keep the primary model in the model field and add the backups in a models array on the same chat completions request. FastRouter tries the primary first, then each model in the array in order until one returns a successful response.
curl --location 'https://api.fastrouter.ai/api/v1/chat/completions' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer API-KEY' \ --data '{ "model": "openai/gpt-4o", "models":["openai/o1", "google/gemini-2.5-pro"], "messages": [ { "role": "user", "content": "Why would I need an LLM judge?" } ], "stream": true } ' - Set a provider order for multi-provider models. For a model that more than one provider serves, add a provider object to the request body. The order field lists provider slugs in the sequence to attempt, and allow_fallbacks set to true lets the request use the backup providers when the primary is unavailable.
"provider": { "order": ["openai", "azure"], "allow_fallbacks": true } - Optionally move the list behind a virtual model alias. Create a virtual model alias in the dashboard, select the models and providers it maps to, and choose a strategy. Priority Routing uses a fixed order that you define and falls back to the next model if one fails. Then pass the alias name in the model parameter.
- Check which model answered. Read the model field of the response body. It reports the model that produced the completion, and billing is based on that model.
Which FastRouter fallback mechanism fits which case?
FastRouter has three fallback mechanisms, each set in a different place. A fallback model list switches between models within one request. Provider ordering switches between providers of the same model. A virtual model alias keeps the candidate list in the dashboard, so it can change without touching application code.
| Mechanism | Where it is set | Falls back across | Order |
|---|---|---|---|
| Fallback model list | model field and models array on the request | Models, which can be on different providers | The order you list them |
| Provider order | provider.order and allow_fallbacks on the request | Providers that serve the same model | The order of the provider slugs |
| Virtual model alias | The dashboard, referenced by alias name in the model parameter | The models and providers mapped to the alias | Set by the alias strategy, for example Priority Routing |
What triggers a fallback, and what are you billed for?
FastRouter moves to the next candidate when the current model is unavailable or returns an error, for example because of rate limits, downtime or moderation. You are billed for the model that actually processes the request, and candidates that failed are not charged.
- If the primary and every fallback fail, FastRouter returns the final error.
- Fallbacks, retries and load balancing are included on every plan, including the free Starter plan. The number of virtual model aliases varies by plan, as listed on the pricing page.
- A manual provider.order takes precedence over the sticky routing that FastRouter uses to keep prompt caches warm.
Sources
Where the statements about FastRouter on this page come from.