Building a fallback path for provider incidents, step by step

Every hosted model has bad days. A long-running job dies halfway because of elevated error rates, a coding session stalls with repeated API errors, and the status page either says nothing yet or will not load at all. For a hobby project that is an annoyance; for anything with users it is lost trust.
This guide is for developers who call Claude, or any hosted model, from their own code and want the product to degrade gracefully instead of breaking. You will set up error classification, retries with backoff, a circuit breaker and a secondary backend for features that can tolerate a smaller model. The examples use Python and the OpenAI SDK format, with this site's free endpoint as the illustrative fallback.
Frequently asked questions
What counts as an outage from the client's point of view?
Anything that stops a request from succeeding in reasonable time: server errors, overloaded responses, timeouts and connection failures. Rate-limit responses are different, because they reflect your own traffic rather than the provider's health.
How does a retry differ from a failover?
A retry sends the same request to the same backend again after a pause, which fixes brief hiccups. A failover sends it to a different backend, which helps when the primary is down for minutes or hours.
Which errors should never be retried?
Requests rejected for being malformed, too large or unauthorised will fail again in exactly the same way. Fix the request instead. Retrying them only wastes quota and delays the error message.
Is a smaller fallback model good enough?
For some features, yes: summaries, classification, drafting short messages, simple extraction. For complex code changes or long-document analysis, a smaller model may produce noticeably worse results, and it is often better to queue those tasks until the primary returns.
What is a circuit breaker?
A small piece of logic that stops sending requests to a backend after several consecutive failures, waits for a cool-down, and then tries again with a single test request. It prevents a flood of doomed calls during an incident.
Does the free endpoint here have an SLA?
No. It has no SLA, no accounts and no support contract, and it returns 503 when busy. It is suitable as a best-effort fallback for non-critical features, not as a guaranteed backup for production-critical paths.
Which is better for resilience: a second commercial provider or a free endpoint?
A second commercial provider with its own key and published terms gives stronger guarantees. A free endpoint costs nothing and is useful for development, demos and low-stakes features. Many teams use both for different tiers.
Should users be told when a fallback model answered?
Being transparent is usually wise, especially when quality differs. A small note such as a reduced-quality mode indicator sets expectations and avoids confusing bug reports.
Step by step
- Classify every error — Write one function that sorts failures into transient, rate-limited and client errors, and react differently to each.
- Add backoff with jitter — Retry transient errors a few times with exponentially growing, randomised waits, and honour Retry-After on 429.
- Configure a second backend — Describe primary and fallback by base URL, key and model in configuration, and let the client walk the list.
- Add a circuit breaker — Skip a backend after repeated failures, test it again after a cool-down, and alert when the state changes.
- Mark features by tolerance — Decide for each model call whether it may degrade, should queue, or should fail visibly.
- Rehearse the failover — Force the fallback in tests regularly so you find formatting and prompt problems before a real incident.
Why outages hurt more than they should
A common frustration among paying users is not that incidents happen, but that their own tools are built as if they never will. A long agent run with no checkpoints loses an hour of work when a single call fails. A web app that calls one model synchronously shows users a spinner forever. Neither problem is caused by the provider; both are design choices on the client side.
Hosted model providers, Anthropic included, publish incident information on their official status pages, and posts mirroring those updates show elevated errors on specific models from time to time. Treat that as a given, the same way you treat network failures, and design around it.
Status pages lag
Incident pages are updated by people, which takes minutes. Your client will usually see errors before any official notice appears, so it must decide on its own.
Partial incidents are common
Often only one model or one region is affected. A fallback to a different model tier from the same provider can be enough, if your code supports it.
Classify errors before reacting
The first building block is a function that sorts every failure into one of a few buckets. The right reaction depends entirely on the bucket, and mixing them up is the source of most bad retry logic.
Transient server problems
Server errors, overloaded responses and 503s usually clear quickly. Retry with backoff, then fail over if they persist.
Rate limiting
A 429 means you are sending too much. Honour the Retry-After header and slow down; failing over to burn another quota is rarely the right fix. The details are in our article on rate limits for agents.
Client mistakes
Bad parameters, oversized context and authentication failures need a code or configuration fix. Log them loudly and do not retry.

Retries with backoff and jitter
For transient errors, wait and try again, but not immediately and not forever. Exponential backoff doubles the wait each time; jitter adds a random offset so that many clients recovering at once do not hit the server in lockstep. Three or four attempts are usually enough before moving on.
Timeouts belong in the same logic. A request that has produced nothing after a generous limit should be cancelled and counted as a failure. For streaming responses, measure time to first token separately from total time, because a stalled stream is a failure even if the connection stays open.
- Start with a wait of about one second
- Double the wait after each failure, with random jitter
- Cap the wait at around half a minute
- Stop after three or four attempts
- Always honour Retry-After when the server sends it
A two-backend client in Python
The client below tries the primary backend, retries transient errors, and falls back to a secondary one when the primary keeps failing. Both backends are described by configuration, so the primary could be Claude through an OpenAI-compatible option or any other provider. The fallback here is this site's free endpoint, which needs no key.
The free endpoint is an independent service that is not affiliated with Anthropic, and its model free-ai is not Claude. Use it only for features where a smaller model is acceptable.
Disable SDK auto-retries if you prefer
The OpenAI SDK retries some errors on its own. Pass max_retries=0 to each client if you want this loop to be the only retry logic.
import os, random, time
from openai import OpenAI, APIStatusError, APIConnectionError, APITimeoutError
BACKENDS = [
{'name': 'primary',
'client': OpenAI(base_url=os.environ['PRIMARY_BASE_URL'],
api_key=os.environ['PRIMARY_API_KEY'], timeout=60),
'model': os.environ['PRIMARY_MODEL']},
{'name': 'fallback',
'client': OpenAI(base_url='https://api.anthropicapifreekey.com/v1',
api_key='unused', timeout=60),
'model': 'free-ai'},
]
TRANSIENT = {500, 502, 503, 504, 529}
def ask(messages, attempts=3):
for b in BACKENDS:
delay = 1.0
for _ in range(attempts):
try:
r = b['client'].chat.completions.create(
model=b['model'], messages=messages, max_tokens=1000)
return b['name'], r.choices[0].message.content
except APIStatusError as e:
if e.status_code == 429:
wait = float(e.response.headers.get('retry-after', delay))
elif e.status_code in TRANSIENT:
wait = delay + random.uniform(0, delay)
else:
raise
except (APIConnectionError, APITimeoutError):
wait = delay + random.uniform(0, delay)
time.sleep(min(wait, 30))
delay *= 2
raise RuntimeError('all backends failed')
source, text = ask([{'role': 'user', 'content': 'Summarise: the meeting moved to Friday.'}])
print(source, text)
Add a circuit breaker
Without a breaker, every request during an incident pays the full cost of several failed attempts before falling back. With one, the client remembers that the primary is unhealthy and goes straight to the fallback for a while, testing the primary occasionally with a single request.
A minimal breaker needs only three values per backend: a failure counter, a timestamp of when it opened, and a cool-down period. Open after five consecutive failures, wait sixty seconds, allow one trial request, and close again on success.
Share state across workers
If your app runs several processes, store breaker state in a shared cache so all workers agree on which backend is healthy.
Alert on state changes
Send a notification when a breaker opens. You will know about an incident before your users report it.
Decide which features may degrade
Not every feature should fall back to a smaller model. Go through the product and mark each model call as one of three types: may use the fallback, should queue until the primary returns, or should show an error. The decision depends on how bad a weaker answer is compared with a delayed one.
Draft emails, tags, short summaries and search query rewriting usually degrade well. Legal or medical text, complex code edits and anything where a confident wrong answer is costly should not silently switch to a different model.
- Fallback allowed: summaries, tags, drafts, simple classification
- Queue and retry later: long reports, code refactors, batch jobs
- Fail visibly: tasks where accuracy matters more than speed

Protect long-running jobs
Agent runs and batch jobs suffer most from incidents because one failure can waste everything done so far. Break the work into steps, save progress after each, and make each step idempotent so it can be rerun safely. Then an outage costs you one step instead of the whole run.
For interactive coding sessions, the same idea applies at a human scale. Commit often, keep notes on the plan in a file, and if the tool loses its connection, you can resume in a fresh session with a short summary rather than starting over.
Checkpoint to disk
Write intermediate results and the current step number to a file or database. On restart, read it and continue.
Keep requests small
Shorter requests fail less often and are cheaper to retry. Split huge prompts into stages where you can.
Test the fallback before you need it
A fallback that has never run is a hypothesis. Add a configuration switch that forces the secondary backend, and run your normal test suite against it from time to time. You will find parsing assumptions that only held for the primary model, prompts that a smaller model misunderstands, and timeouts that are too short.
The free endpoint is convenient for this kind of testing because it requires no key and no billing setup. Remember its limits: per IP, 1 request per second with bursts of 3 and 2 in parallel, with a daily allowance that resets at 00:00 UTC. For heavier automated tests, keep them sequential. For broader planning around free versus paid backends, see our cost estimation guide.
Compare outputs, not just status codes
A fallback that returns 200 but produces malformed JSON is still broken for your app. Validate the structure of answers from both backends with the same checks, and log which backend produced each answer so quality problems can be traced back.
Watch the cost side too
If the fallback is a second paid provider, an incident can shift a whole day of traffic onto it. Give it its own spend limit and alerts so a long outage does not become an unpleasant invoice. With a free fallback, the equivalent concern is its per-IP limit, which a busy server reaches quickly.

Send a prototype prompt from the chat box on the home page: no key, no account and no card needed, just the usual per-IP limits.
Read also
- Are Cheap Claude API Resellers and Shared Accounts Safe to Use?
- Why Do Claude Usage Limits Seem to Run Out Faster Lately?
- How Do You Move a Long AI Conversation to Another Model Intact?
- Does Extended Thinking Actually Make Claude's Answers Better?
- How to Estimate and Compare LLM API Costs Before You Commit