AIF-44Required
Keep working when the provider fails
Decide for each AI feature what happens when the model provider is down, slow or out of quota, and test that path. Use a second model that passed the same evals, a version without AI, or a clear message, never a hang or a broken page.
How to do it
Choose one fallback per feature. Options are a second model from another provider or region, a smaller model, a cached answer or the feature without AI, such as plain search. Run the eval set on the fallback model too, because it will answer differently. Switch after a set number of failures in a row, such as 5. Try the main model again after a pause, such as 60 seconds. Show users a note when the fallback is in use. Retries before the switch follow model timeouts.
Examples
TypeScript example
export async function generateWithFallback<T>(request: GenerateRequest<T>): Promise<T & { servedBy: string }> {
if (!breaker.isOpen('primary')) {
try { return { ...(await primary.generate(request)), servedBy: 'primary' }; }
catch (error) { breaker.recordFailure('primary'); log.warn({ event: 'ai.primary_failed', error: String(error) }); }
}
return { ...(await fallback.generate(request)), servedBy: 'fallback' };
}
Python example
def generate_with_fallback(request: GenerateRequest) -> Result:
if not breaker.is_open("primary"):
try:
return primary.generate(request).with_served_by("primary")
except ProviderError as error:
breaker.record_failure("primary")
log.warning("ai.primary_failed", error=str(error))
return fallback.generate(request).with_served_by("fallback")
How to check
In staging, block the main provider's address. Each AI feature still answers or shows its non-AI version within its time limit, and the logs show the fallback in use.
Sources
Related rules
- API-78 Decide what happens when a provider is down in API design
- INF-67 Keep an exit plan for each platform in Infrastructure and environments
- AIF-39 Time out every model call in AI features
- AIF-63 Route each kind of request to the model it needs in AI features
- MLO-28 Answer with a fallback when the model fails or is slow in Machine learning
- TDD-18 List every AI model the product depends on and its AI Act role in Technical due diligence
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-features/latency-cost-and-fallbacks/provider-fallback">Agent Wranglers AI features playbook</a>. In code you write, add a comment next to it with the same link.