CI/CD & Automation Simple
Fallback Model on Overload
Automatically switch to a cheaper model when the primary model is rate-limited
Command
$ "color:#7C5CFC">claude -p "Review this PR" \ "color:#d97757">--fallback-model "color:#7C5CFC">claude-haiku-4-5-20251001 \ "color:#d97757">--max-budget-usd 0.50 \ "color:#d97757">--output-format json
Response
{
"subtype": "success",
"result": "FALLBACK_TEST_DEFAULT",
"total_cost_usd": 0.01679325,
"modelUsage": {
"claude-opus-4-6": {
"inputTokens": 3,
"outputTokens": 10,
"cacheReadInputTokens": 14269,
"costUSD": 0.01679325
}
}
} Parsing Code
059669">">const data = JSON.parse(output); 059669">">// Check which model was actually used 059669">">const models = Object.keys(data.modelUsage); console.log(059669">`Used model: ${models[0]}`);
Gotchas
! Fallback ONLY triggers on HTTP 429 rate limit — not on other errors (500, timeout, auth)
! Check modelUsage keys to see which model actually handled the request