In this categoryTroubleshooting · 27
- How to Fix an OpenAI 401 'Invalid API Key' ErrorStart
- How to Fix OpenAI 429 Rate Limit Errors With Backoff
- How to Fix Anthropic Claude API 401 Authentication Errors
- How to Fix Google Gemini 'API Key Not Valid' Errors
- How to Fix an API Key That Loads as Undefined
- How to Handle Anthropic 529 'Overloaded' Errors
- How to Fix Rate Limit Errors from an AI API
- How to Fix CORS Errors When Calling an AI API From the Browser
- How to Fix 'Model Not Found' and Deprecated Model Errors
- How to Rotate a Leaked API Key Without Downtime
- How to Fix SSL Certificate Errors When Calling AI APIs
- How to count tokens before sending a prompt to Claude
- How to Fix 'Context Length Exceeded' Token Limit Errors
- How to fix a context length exceeded error in the Claude API
- How to fix a Claude response that gets cut off mid-sentence
- How to reduce Claude hallucinations by grounding answers in your documents
- How to keep a long Claude conversation under the context limit
- How to stop Claude from calling tools when it should not
- How to handle a Claude Fable 5 refusal with a fallback model
- How to choose the right Claude model for cost and quality
- How to cut Claude API costs with prompt caching
- How to halve Claude costs for bulk jobs with the Batch API
- How to cap spend on a Claude agent with a task budget
- How to Debug an MCP Server That Will Not Connect
- How to Ask an Agent to Explain a Bug Before Fixing It
- How to Roll Back a Bad Deploy Quickly
- How to Fix Cursor Not Indexing Your Codebase
How to handle a Claude Fable 5 refusal with a fallback model
Detect the refusal stop reason and opt into a server-side fallback so a declined request is re-served by another model.
Claude Fable 5 runs safety classifiers that can decline a request. A decline comes back as a successful HTTP 200 with stop_reason set to refusal, not as an exception. If your code reads response.content directly, it will break on these. Worse, false positives can hit benign adjacent work. This guide shows how to detect the refusal and opt into a fallback model so the request is rescued automatically.
- The Anthropic SDK with access to claude-fable-5
- An organization with 30-day data retention (Fable 5 is not available under zero retention)
- A fallback model in mind, typically claude-opus-4-8
Step 1: Check stop_reason before reading content
Always branch on stop_reason first. A pre-output refusal has an empty content array and is not billed. A mid-stream refusal bills the partial output, which you should discard. Reading content[0] without this guard throws on refused requests.
resp = client.messages.create(
model="claude-fable-5",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
if resp.stop_reason == "refusal":
print("declined:", resp.stop_details.category if resp.stop_details else None)
else:
print(resp.content[0].text)Step 2: Opt into a server-side fallback
Fallbacks are opt-in. On the beta endpoint, pass the server-side-fallback beta header and a fallbacks list. On a policy decline the API runs the next model on the same request and returns its answer, with credit-style repricing applied automatically. Ship this by default in new Fable 5 code.
resp = client.beta.messages.create(
model="claude-fable-5",
max_tokens=1024,
betas=["server-side-fallback-2026-06-01"],
fallbacks=[{"model": "claude-opus-4-8"}],
messages=[{"role": "user", "content": prompt}],
)
for block in resp.content:
if block.type == "fallback":
print(f"{block.from_.model} declined; {block.to.model} continued")Step 3: Confirm which model served the answer
A fallback block in content marks each switch point. The reliable served-by signal is a fallback_message entry in usage.iterations, which also covers sticky follow-up turns that carry no block. Pair it with stop_reason, since the fallback model can itself refuse.
fallback_ran = any(
entry.type == "fallback_message"
for entry in (resp.usage.iterations or [])
)
if fallback_ran and resp.stop_reason != "refusal":
print("served by", resp.model)Result: a benign security-tooling prompt that Fable 5 declined with a cyber category now returns a real answer. The fallbacks list re-served it on Opus 4.8 inside the same call, the fallback_message entry confirmed Opus produced the response, and the declined Fable attempt cost nothing.
Watch related tutorials
1:42:18
28:14
41:09
9:47
8:23
52:31New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.