A 200 from the backup model is not a recovery
Adding a second provider is not a fallback plan. Which errors should move a request, which backup to choose, how to cap its cost and how to see which model answered.
On 11 December 2024 the OpenAI API, ChatGPT and Sora went down for hours after a new telemetry service overwhelmed the company's Kubernetes control planes, as OpenAI's own incident report explains. A product with a backup model would have switched to it, and a switch like that can return HTTP 200 and still be wrong for the app. Elroy Fernandes opens a piece in Startup Fortune on 23 November with this outage and argues that the fallback rule must be set before the outage, with numbers in it. This post follows that argument and adds what a gateway can take off your plate. This post is for developers and small teams whose agents and scripts depend on more than one model: how to decide what counts as an outage, what the backup should be, and how to find out afterwards which model actually answered. Prism is a self-hosted AI gateway that makes those switches and reports every one of them.
A green dashboard and a broken parser
The common setup is a second API key and a retry. The primary provider starts erroring, the code retries against the backup, a 200 comes back, and the monitoring goes green. Nobody checks what the 200 contains.
The problems are in that content. Providers do not agree on request or response shapes. Anthropic's Messages API requires max_tokens on every request and takes the system prompt as a top-level field; OpenAI's chat format expects it as a message in the list. OpenAI returns tool-call arguments as a JSON string; Anthropic returns them as an object inside a tool_use block. A gateway can translate those shapes. What no gateway can translate is behaviour: whether the second model picks the right tool, whether it wraps its JSON in a code fence and opens with a sentence of commentary, whether it answers in two sentences or two paragraphs, or whether it declines a request that the first model accepted.
Some differences show up only on real traffic. Tokenizers differ, so a prompt that fits on one model can overflow another's context window. A model that writes twice as much doubles your output tokens and breaks any interface that assumed short answers.
So the backup is not a spare key. It is a piece of your product, and switching to it deserves the same care as a release.
Not every error is an outage
The first decision is which failures should move a request elsewhere. These are reasonable defaults to tune against your own traffic:
- Fail over on time. A connection error, a first token that takes too long, or a total request timeout. A model that answers after 40 seconds is down as far as a user in a chat is concerned.
- Fail over on server-side failure. Any 5xx. Anthropic's
529 overloaded_errorreports provider capacity rather than anything wrong with the request; treat it like a rate limit, as Prism does. - Treat rate limits as a signal about one model on one account. A 429 means that model is limited on that account. With another account or provider available, moving is usually better than making the user wait.
- Do not fail over on request errors. A malformed body or an invalid schema will be rejected by the second model for the same reason. Sending it there hides the bug and doubles the bill.
There is one useful exception to the last rule, and it depends on who chose the model. When you name the model, a 400 is usually about your request. When the gateway chose the model and adapted the body for it, a 400 can be a fact about that model: it does not take a parameter the gateway sent. In that case, the next candidate receives a differently shaped body and may succeed. If every candidate rejects the request, you should get the 400 status back, with every attempt listed.
One failure class never appears in status codes at all. If a growing share of responses stop passing your schema validation, the model is degraded for your purposes, even while the provider's status page stays green.
The first rung: the same model somewhere else
The easiest backup to trust is the model you already run, sold through another host. Claude models are also available on AWS Bedrock and Google Vertex AI; OpenAI models on Azure. Prompts, tool formats and behaviour carry over almost unchanged, so there is little to re-test. It will not help if the model itself has a bad day, so treat it as the first step, with a different model as the second.
For a conversation in progress, this is a choice you can make once, in advance, instead of per incident. In Prism the setting If the model does not answer mid-conversation has two values:
- Next model in order (the default): the conversation continues on the next model by price and quality tier.
- Same model at another provider: Prism first tries the conversation's model at its other providers and only then moves to another model.
A mid-conversation switch has a cost that is easy to forget: providers cache a conversation on their own side, so any switch to another provider or model loses that cache and the next request pays full price for the context again. A same-model backup still loses the cache; it just keeps the behaviour.
Two more rules belong in the same decision. A request that names a provider, such as provider::model, stays on that provider and switches only between its accounts, unless you explicitly allow cross-provider failover for the deployment or for that request. And a request marked private never falls back to a cloud provider: if no local model can serve it, it fails, which is the result you want from a privacy setting.
What Prism does when a model stops answering
| What happens upstream | What Prism does | Reason it reports |
|---|---|---|
| Connection error or timeout | Moves to the next eligible model, provider or account | timeout, transport |
| 5xx from the provider | Moves to the next eligible route | unavailable |
| Rate limit (429 or 529) | Moves; after 3 within a minute, excludes that model for a cooldown that starts at 30 seconds and doubles up to 10 minutes by default | rate_limit |
| Billing refusal or exhausted quota | Moves to another account or provider; the unfunded account gets at most one probe per window, 15 minutes at first and doubling up to 2 hours while it stays unfunded | billing |
| Model retired (404 or 410) | Moves to the next eligible route; for a pinned model, other providers serving it | gone |
| Your pinned model rejects the request (400) | Stops and returns the error; an unsupported parameter or capability is first tried at another provider of that model | bad_request |
| Request body too large (413) | Stops and returns the error | payload_too_large |
| Private request, no local model available | Refuses with 503 and does not go to the cloud | privacy_route_unavailable |
The last column matters as much as the second. The number of attempts, the providers tried and the reason for each are returned in the response headers (X-Prism-Attempts, X-Prism-Attempt-Providers, X-Prism-Attempt-Reasons) and shown in the console, and X-Prism-Provider and X-Prism-Model name the route that actually served the answer. When nobody can serve the request, the error body lists every attempt with its provider, model, status, reason and latency. Prism does not substitute a provider silently, so a switch can be found in the headers or the console.
The cooldown, the probe and the bill
Deciding request by request is expensive: every request during an outage pays the failed attempt first. The alternative is to remember the failure. In Prism, after repeated 429s inside a minute, the affected model is excluded from routing for a cooldown and then let back in when the cooldown expires. A provider that refused for billing reasons is excluded while it is unfunded, and Prism admits at most one probe for it per window; one successful probe clears the state immediately. The probe is the part people forget. Without it you stay on your more expensive backup long after the primary has recovered.
Costs need a rule written before the incident, because traffic tends to spike during one: clients retry and users refresh, now on a model that is often pricier. Put the ceiling on the backup itself. In Prism, [[budget.account_limits]] caps one provider account per hour, day, week or month, and a spent account takes no traffic until its window resets. Set the cap for the account you expect to carry fallback traffic as a multiple of what it normally spends in that window, and an outage has a maximum price. For a model budget, [budget] model_fallback chooses how a spent model is replaced; the default is the nearest cheaper model that supports at least the same tools, image input and JSON output, so a budget switch cannot silently drop a capability your request needs.
Then make the switch visible. Prism shows each routing role as normal, on a backup target or dead, with the target serving it, since when and why, and notifies the owner when a role has run on a backup for more than three hours.
Rehearse it while nothing is broken
A backup that has never served your real prompts is an assumption. The rehearsal does not need a special tool. In a test setup, disconnect the primary provider for an hour, send the requests your product really sends, and then read the request log: which model answered, how many outputs failed to parse, how long the answers were and what the hour cost. Fix the prompt for the backup if it needs one, and repeat until the backup's outputs parse and its answer length and cost are acceptable. Repeat the drill when you change a prompt or a provider ships a new version.
Where Prism fits
Your agents and applications call one Prism API, and on each request Prism chooses the model, provider and account from your policy and live signals: capability, health, remaining funds and cost. For failover that means:
- You decide what the backup is. The same model at another provider, or the next model in order. See how a request is routed.
- It switches on real outages, not on your bugs. Timeouts, server errors, rate limits and exhausted quota move a request; a request the pinned model rejects comes back to you with the reason.
- It remembers and recovers. A failing model is excluded for a cooldown, an unfunded provider is probed at most once per window, and both return by themselves without a restart.
- It never switches silently. The attempts and their reasons are in the response headers and in the console.
- It knows what a model can do. Where nobody has stated whether a model takes tools, images or JSON output, Prism checks it with a few small requests in the background and routes accordingly.
- Private stays private. Requests marked private are served only by your local models, or refused.
- Fallback spend has a ceiling. Account and model budgets apply during an outage exactly as on a normal day.
Two limits. Prism cannot make a second model behave like the first: that is the rehearsal's job, and for some requests the right answer is a separate prompt per model. And Prism is not yet publicly available. If you run agents on several providers and want failover you can see and explain, request access to Prism Free, which costs nothing for up to 3 people. The comparison pages show how Prism differs from other gateways, and the FAQ answers the rest.
Questions and answers
What errors should trigger a fallback to another model?
Connection errors, timeouts, 5xx responses, Anthropic's 529 overloaded error, rate limits and exhausted quota. A malformed request should not: the body is broken or uses an unsupported schema, and the second model will reject it for the same reason.
Should you fail over on a 400 error?
Not when you named the model: the rejection is about your request. When the gateway chose the model and adapted the body for it, the 400 can mean that model does not support a parameter, so trying the next candidate is reasonable. If every candidate rejects the request, the error should reach you with every attempt listed. In Prism, a pinned model that rejects the request usually ends it with the reason bad_request; a rejection of one parameter or of a missing capability is first tried at another provider of the same model.
Is it better to fail over to the same model on another provider or to a different model?
The same model on another provider keeps behaviour, so it needs little re-testing, but it does not help if the model itself is degraded. In Prism the setting "If the model does not answer mid-conversation" offers both: next model in order (the default) or the same model at another provider first. Any switch to another provider or model loses the conversation cache.
How do you find out which model answered a request?
Prism names the provider and model that served each response in the X-Prism-Provider and X-Prism-Model headers, gives the number of attempts in X-Prism-Attempts, and lists the providers tried and their results in X-Prism-Attempt-Providers and X-Prism-Attempt-Reasons. The same information appears in the console under Usage history, Request details.
How do you stop a fallback from running up the bill?
Cap the account that carries fallback traffic. In Prism, [[budget.account_limits]] limits one provider account per hour, day, week or month, and a spent account receives no traffic until its window resets.
What happens to a private request when local models are unavailable?
It is refused. A request marked private is never sent to a cloud provider, so when no local model can serve it Prism answers with 503 privacy_route_unavailable.