short · 3 min
Provider fallback
Switching to a second model or provider when the first one fails.
updated 29 Sept 2026
Here's a backup plan written as a list:
openai/gpt-6-astrathrough Azure- the same model through OpenAI
anthropic/claude-opus-5through anyone who serves it
If the first fails, try the second. If that fails, the third. The first one that works answers the user. That's provider fallback, and an AI gateway like Vercel's or OpenRouter's will run that list for us.
It's a different thing from a retry. A retry sends the same request to the same place again. A fallback changes where it goes.
Two levels in one list
Notice the list has two kinds of step. Lots of models are served by more than one company, so steps 1 and 2 are the same model through different providers. Step 3 is a different model. Vercel's gateway (as of 2026-09) tries all the providers for one model first, then moves to the next model and does the same.
Steps 1 and 2 change very little. Step 3 changes a lot. Hold on to that.
What sets it off
On OpenRouter, by default, any error from the first model triggers the next one. Downtime and rate limits, sure. Those are why we wanted this. But two more are on the list.
A context-length error: the prompt is too long for the first model, so a model with a bigger window takes it. Probably fine.
A moderation refusal: one provider declines to answer, and the next model gets the same request. That one is a policy decision hiding in a default. A request one provider refused on safety grounds now quietly goes to another. Maybe that's what we want, maybe not, but it's worth choosing on purpose.
What comes along, and what doesn't
Back to step 3. A different model is a different product. It follows our prompt differently, answers differently, and may fail our evals. The gateway docs explain the mechanics well and say nothing about how much quality drops when a fallback kicks in. So every model on the list needs the same testing we'd give a model upgrade. And if the backup is a pricier model, the bill gets a surprise.
The prompt cache doesn't come along either. A cache belongs to one model. When a long, cached request falls back, the new model reads the whole prompt from scratch, at full price and full wait. The Claude Code team found that switching models 100,000 tokens into a conversation cost more than staying on the pricier model. So a fallback during a long agent session is slower and costlier right when things are already going wrong. Sometimes waiting and retrying the primary is cheaper.
Fallbacks also stack with retries. A gateway trying three models, under an SDK that retries, under our own retry loop, can turn one request into dozens of calls during an outage. They belong in the same budget.
And it's silent. The gateway records every attempt in the response metadata, and OpenRouter bills for the model that actually answered and names it in the response. But if we don't log that, a week on the backup looks exactly like a week on the primary, costs and errors included.
So back to the list. Steps 1 and 2 are the cheap insurance: same model, different door. Step 3 is a second product we've signed up to support, and it deserves the eval runs, the logging and the alerts that come with that.
Further reading
- AI Gateway Model Fallbacks, Vercel docs, updated 2026-09-10. How the provider-then-model order works and where the attempt log lives.
- Model Fallbacks, OpenRouter docs. Short. Read it for which errors trigger a fallback by default.
- Lessons from building Claude Code: Prompt caching is everything, Thariq Shihipar (Anthropic), 2026. Why switching models mid-session costs more than it looks.