Guide

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.

  1. 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.
  2. 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
    }
    '
  3. 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
    }
  4. 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.
  5. 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.

FastRouter fallback mechanisms
MechanismWhere it is setFalls back acrossOrder
Fallback model listmodel field and models array on the requestModels, which can be on different providersThe order you list them
Provider orderprovider.order and allow_fallbacks on the requestProviders that serve the same modelThe order of the provider slugs
Virtual model aliasThe dashboard, referenced by alias name in the model parameterThe models and providers mapped to the aliasSet 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.
FAQ

Common questions

FastRouter falls back when the current model is unavailable or returns an error, for example due to rate limits, downtime or moderation. Instead of failing the request, it moves to the next candidate in the list and continues until a model succeeds or every candidate has failed.

Billing is based on the model that actually processes the request. If the primary fails and a fallback answers, you are charged for the fallback that ran, not for the candidates that failed. The response's model field shows which model that was.

Model fallback switches to a different model when the current one fails, using the models array. Provider fallback keeps the same model and switches to another provider that serves it, using the order and allow_fallbacks fields of the provider object. In FastRouter the two are configured separately on a chat completions request.

Yes, if the application calls a virtual model alias. The alias is edited in the FastRouter dashboard, where models and providers can be added, swapped, reordered or reweighted. Deployed applications pick up the new configuration on their next request.

Try it on your own traffic

Point your existing OpenAI-compatible client at FastRouter and send a request. Free to start, no credit card required.