LLM failover across providers: three ways to set it up

Put LLM failover in your code, in a proxy you run, or in a hosted gateway. Working patterns for each, what fails over and what cannot, and how to test it.

Checked 2026-11-21

·All posts·Models

There are three places to put LLM failover: in your code (catch a 5xx or 429 and retry another provider), in a proxy you run (LiteLLM's fallback lists), or in a hosted gateway. On UplinkSwitch, a model with several routes fails over automatically on a 5xx or 429 at the same price, and a models list of up to 5 fallback ids at https://api.uplinkswitch.com/v1 covers a whole model going down.

Route failover and model fallback are different things

  • Route failover: the same model, served by another host. The answer is the same model, and here the price doesn't change.
  • Model fallback: a different model when the first can't answer at all, for example claude-sonnet-5-5 failing over to gpt-6.1-sol. The answer and the price change, so choose fallbacks you'd accept.

1. In your own code

python
import time, openai
client = openai.OpenAI(base_url="https://api.uplinkswitch.com/v1", api_key="sk-uplink-live-…")
def ask(messages, models=("claude-sonnet-5-5", "gpt-6.1-sol", "gemini-4-argon")):
    for m in models:
        for attempt in range(2):
            try:
                return client.chat.completions.create(model=m, messages=messages)
            except openai.RateLimitError as e:
                time.sleep(float(e.response.headers.get("retry-after", 2)))
            except openai.APIStatusError as e:
                if e.status_code < 500: raise   # 4xx other than 429: fix the request, don't retry
                break
    raise RuntimeError("all models failed")

This works with any provider and costs nothing extra, but every service you run has to carry it.

2. In a proxy you host

LiteLLM takes a fallback list per model in its config, and Portkey has configurable fallbacks across your keys. You get one place to change the policy, at the price of running the proxy.

3. In the gateway

On UplinkSwitch, route failover is automatic and model fallback is one field:

json
{"model": "claude-sonnet-5-5",
 "models": ["gpt-6.1-sol", "gemini-4-argon"],
 "messages": [{"role": "user", "content": "…"}]}

A fallback id gets its turn only after all routes of the previous model have failed without returning any output. Whichever model answers bills at its own catalog price, and the ones that failed cost nothing.

What can't fail over

  • A stream already under way. Failover happens before the first byte; once tokens are streaming, a mid-stream break is an error you handle.
  • Models with a single route. Gemini models have one route here, so only a fallback model protects them.
  • Bad requests. A 400 or 401 is your request's problem; retrying elsewhere doesn't help.

Test it before you need it

Every day at 06:30 UTC one real request runs on each format's backup route, and the status page shows the result. The public feed is GET https://api.uplinkswitch.com/v1/status, and the console counts your own failed-over requests over 30 days.

Questions and answers

Not for route failover: the model bills at its catalog price whichever route answers. A model fallback bills at the fallback model's price, and only when it answers.

Yes, until the first byte. After that, a broken stream is returned to you as an error.

The x-uplink-model header names the model that answered, and so does the model field of the request record at GET /v1/requests/{id}, using the x-uplink-request-id every response carries.
Join on Telegram
Help