LLM API fallback: how to keep your AI product running when a provider rate-limits or goes down
An LLM API fallback strategy is retries, a cooldown, and a second model or provider behind the first. How each layer works, what it costs in latency and quality, and what to decide before launch.
Your AI feature works in the demo, then a provider returns a burst of 429s
during your busiest hour and users see a spinner that never resolves. An
LLM API fallback strategy is what turns that into a slower answer
instead of a failed one. It is also one of the cheapest reliability
decisions to make early and one of the most annoying to retrofit.
This post covers the layers, in the order you should build them, and the
trade-offs each one introduces. It is about the domain, not any particular
deployment: the sources are public docs and vendor write-ups, linked inline.
Several of those vendors sell gateways, so read their framing accordingly.
What actually fails when you call an LLM API?
Three things, and they need different responses:
Rate limits (HTTP 429). Providers cap requests and tokens per minute
(and often per day). Maxim's guide to 429s
lists four dimensions: RPM, TPM, RPD and TPD. Bursty traffic hits these
first.
Server-side errors (500s, 503). The provider is overloaded or
degraded. These are often brief but can last long enough that retrying
against the same endpoint is wasted effort.
Slow responses. Not an error code at all. Portkey
notes a chatbot answer taking 6–8 seconds already feels broken, which is
why timeouts belong in the design and not only status codes.
Layer 1: retries with backoff and jitter
Start here, because it costs nothing and fixes the common transient case.
Wait longer after each failure, add randomness so a fleet of clients does
not retry in lockstep, and read the Retry-After header when it is present.
Maxim's sample code uses a cap of 5 retries, a 1-second base delay and up to
50% jitter; treat those as a starting point, not a standard.
Cap retries. A failed request still counts against your per-minute
allowance, so unlimited retrying can keep you rate-limited longer.
Layer 2: a cooldown, so you stop hitting a failing endpoint
If a deployment has failed several times in a row, stop sending it traffic
for a short while. LiteLLM's router docs
expose this as allowed_fails (default 3) and cooldown_time (default 5
seconds), and note that rate-limit errors back off exponentially while
generic errors retry immediately. Defaults change between versions, so check
the current docs rather than copying numbers from a blog post, including
this one.
Without a cooldown, every request pays the full timeout against a dead
endpoint before it reaches the fallback.
Layer 3: the fallback chain itself
Once retries are exhausted, move to the next entry. There are four common
shapes, summarised from Portkey's overview:
Strategy
How it works
Cost
Main risk
Sequential failover
Try primary, then backup on 429/5xx/timeout
None extra
Adds latency on the failing path
Status-code rules
Different errors route differently (429 to another key, 5xx to another provider)
None extra
Rules need maintaining
Latency-threshold hedging
If no answer within a set time, send to a second provider and take the first reply
Duplicate requests billed
Higher spend, more load
Proactive split
Spread traffic across providers or tiers all the time
Depends on mix
More surfaces to test
For most products, sequential failover with status-code rules is enough.
Hedging is worth it only where latency matters more than the extra tokens.
Is it safe to fall back to a different model?
This is the part vendors gloss over. A fallback that returns a worse or
differently formatted answer can be a bigger problem than an error, because
nothing flags it. Before a model goes into the chain:
Check structured output, tool-call formats and context-window size.
LiteLLM's enable_pre_call_checks exists because a fallback with a
smaller context window will reject a long request outright.
Decide what the user sees. Sometimes a visible "using backup model"
state, or a degraded-but-honest answer, is better than a silent swap.
Check data terms. A second provider is a second data processor, which
matters for the compliance questions covered in the
DPDP Act post.
What should you build yourself versus buy?
Situation
Reasonable choice
One model, one provider, early product
Retry wrapper plus one backup model in your own code
Several models or teams, shared limits
An open-source router or gateway such as LiteLLM
Need audit logs, budgets and per-customer routing
A managed gateway, evaluated on price and lock-in
The same logic as build vs buy for AI features
applies: buy the plumbing once it is costing you engineering time, not
before. And note that routing between cheap and premium models for cost is a
related but separate decision, covered in
how to reduce LLM API costs.
What to do next
Before launch, answer five questions in writing:
Which errors trigger a retry, and how many attempts?
When does a failing endpoint go into cooldown, and for how long?
What is the fallback chain, and has each entry passed your evaluation set?
What is the user-facing timeout, and what do they see when it fires?
Who is alerted when the fallback is carrying more than a small share of
traffic?
If you are building an AI product and want this designed in rather than
patched on after the first incident, that is the kind of work our
AI SaaS service covers.
Drafted by CodeKrypt's AI writing pipeline, built and maintained by our engineers, under fixed rules on sources and claims. How we write
Frequently asked questions
What is an LLM API fallback?
It is a rule that sends a failed model request somewhere else instead of showing the user an error. Usually that means retrying with backoff first, then moving to a second deployment, model or provider after a rate limit (429), a server error (500/503) or a timeout.
Should I retry or fall back when I get a 429?
Retry first, but respect the Retry-After header when the provider sends one and cap the number of attempts, because failed requests still count against your per-minute limit. If the limit is sustained rather than a burst, fall back to another key, model or provider.
Do I need an LLM gateway to do this?
No. A retry wrapper and a two-entry fallback list is a few dozen lines of your own code. A gateway such as LiteLLM or Portkey earns its place once you have several models, several teams, or need shared cooldown state and cost tracking.
Is falling back to a different model safe?
Only if you have tested it. A different model can follow your prompt differently, format structured output differently, or handle your tool definitions differently. Run your evaluation set against every model in the chain before it goes in production.
Enterprise buyers ask to use their own LLM provider account or encryption keys. What BYOK means in an AI SaaS product, how to store customer keys, and what it does to cost, support and quality.
An AI feature SLO needs more than uptime. Which indicators to measure, which to put in a contract, and how to keep a provider outage or a quality drift from becoming your SLA breach.
Voice AI agent latency is not just model speed. How turn detection, endpointing and barge-in handling decide whether callers feel heard, and how to measure each stage.