theLLMs

Last checked: 2026-05-28

Scope: Global. Provider reliability patterns, API error documentation, and industry incident post-mortems checked on 2026-05-28. Specific error codes and rate-limit tiers vary by provider and plan.

Hero image for Fallback design: what happens when the AI call fails?

Fallback design: what happens when the AI call fails?

TL;DR

Every AI feature will fail. Model APIs return 503s, rate limits hit mid-session, context windows overflow on long inputs. Design every AI feature with four fallback layers, in order:

  1. Degraded mode — return a simpler answer, a cached result, or a safe default
  2. Graceful error — show a clear message explaining what went wrong without blaming the provider
  3. Human escalation — route the request to a person or a manual workflow
  4. Offline state — disable the feature entirely if upstream dependencies are known to be unavailable

Most teams design for the happy path and discover the failure modes in production, under user load, during a demo for the CEO. The right fallback depends on the cost of failure. For a code completion, degraded mode (simpler completion) is fine. For a medical triage tool, only human escalation is acceptable.

What the tutorials skip

Every provider has different failure modes. OpenAI, Anthropic, Google, and open-weight providers all have different error codes, rate limits, availability SLAs, and retry behaviours. A retry strategy that works for one may cause cascading failures for another. Read the provider’s error documentation before writing fallback code.

Rate limits are not just about requests. Provider rate limits cover requests per minute, tokens per minute, tokens per day, and concurrent connections. Hitting any of these can block all users simultaneously. Design for backpressure before the limit is reached, not after.

Context window overflow is not an error. When a user sends a very long input, the model does not return an error — it truncates, loses context, or produces a worse answer. Fallback designs need to detect overflow before calling the API and handle long inputs differently (summarise, chunk, or refuse with explanation).

Degraded mode needs testing. A cached answer from last week may be worse than admitting the feature is temporarily unavailable. Test degraded mode outputs the same way you test happy-path outputs: accuracy, safety, and user experience.

Where teams misuse fallback design

Infinite retries. Retrying the same request against the same provider with the same parameters is not a fallback strategy. After 2–3 retries with exponential backoff, fall back to a different provider, a cached answer, or an error message.

Silent fallback. Switching to a weaker model or a cached answer without telling the user erodes trust. If the feature is running in degraded mode, say so. Users would rather know they are getting a less accurate answer than assume the full system is working.

Falling back to hallucination. Some systems respond to an API error by having the model generate a plausible-sounding answer with no ground truth. This is worse than an error message. A wrong answer confidently delivered is harder to detect than a feature that says “I don’t know right now.”

Practical design patterns

Pattern 1 — Provider cascade

Call primary provider first (e.g., Claude). On timeout or 5xx, fail over to secondary provider (e.g., GPT-4o). On failure, fail over to cached response. On cache miss, show degraded UI. Set request timeouts aggressively (10–15 seconds for LLM calls). Cache successful responses with a TTL appropriate for staleness tolerance.

Pattern 2 — Graceful degradation matrix

Failure typeUser experienceWhat the system does
Model API down”Results may be simpler — our AI is temporarily unavailable”Return cached results or simplified heuristic output
Rate limited”You’ve used your AI requests for now. Try again in a few minutes.”Show limit, offer retry timer
Context overflow”Your input was too long. Try a shorter question or upload a summary.”Refuse with explanation, offer hint
Embedding API down”Search is temporarily limited to keywords.”Fall back to BM25 or traditional search
All upstream down”This feature is temporarily unavailable. Your request has been logged.”Log request, notify operations, show offline banner

Pattern 3 — Human escalation with queues

Route failed requests automatically to a human review queue. The queue should show:

  • The original user request
  • What the AI attempted and why it failed
  • Recommended actions from the fallback logic

Track queue size and resolution time. If the queue backs up, that is a signal the AI feature is too unreliable for its current use case.

Decision framework

QuestionShould you build fallback?
Is the feature user-facing?Yes, always
Is the feature critical to the user’s task?Yes, with human escalation
Is latency sensitive?Yes, with aggressive timeouts and cached fallback
Is the cost of a wrong answer high?Yes, refuse rather than fall back to a weak model
Can you detect failure without the user reporting it?Yes, monitor API errors and degrade proactively

Caveats and scope boundaries

  • This guide covers fallback design for AI features that depend on external model APIs. It does not cover self-hosted model reliability, infrastructure-level failover, or multi-region deployment strategies.
  • Provider API error codes, rate limits, and retry behaviours change. The patterns described here are architecture-level guidance; verify specific error handling against your provider’s current documentation.
  • The degradation matrix is a design template. Adjust thresholds, messaging, and escalation paths based on your product’s risk profile and user expectations.

Methodology

  • Data checked: 2026-05-28
  • Sources consulted: OpenAI error handling documentation, Anthropic API errors and retries, Google AI API rate limits, AWS Well-Architected Framework
  • Assumptions: The reader is designing or operating an AI feature that depends on external model APIs
  • Limitations: This article provides architectural patterns, not provider-specific implementation guides. Provider error codes and rate-limit tiers evolve — verify current documentation
  • Jurisdiction: Global. AWS Well-Architected Framework (US) referenced for fault-tolerance patterns

Source list

Trust Stack

  • Last substantive check: 2026-05-28
  • Corrections policy: Contact via Contact page
  • Affiliation: theLLMs has no vendor affiliation or sponsorship

Change log

  • 2026-07-08: Full editorial rework against 18-gate checklist. Fixed: G3 intro paragraph removed, G4 Editor’s Note format standardized, G6/G18 list formatting corrected, G7 Trust Stack rewritten to required format, section order corrected to blueprint, G9 “Related guides” typo fixed, G2 heading IDs confirmed (Astro auto-generates per G18).
  • 2026-05-28: Full editorial review against 16-gate checklist. Added 3 Editor’s Note asides (converted from blockquote format). Added Methodology, Source list with access dates, Trust Stack, slugified heading IDs (all H2s/H2s), and standalone Caveats section. Fixed frontmatter writtenBy label. Corrected related guide paths to relative format.
  • 2026-05-24: First published version.