AI Wisdom

Fallback Chain

Route LLM requests through a prioritised list of models/providers, falling back to alternatives on rate limits, errors, or latency SLO violations.

In this article

Problem: LLM providers experience outages, rate limits, and high latency. Depending on a single provider creates single points of failure in production.

Solution: Define a prioritised provider chain and automatically route to the next provider on failure.

Implementation:

  1. Define chain: Primary (GPT-4o via Azure OpenAI) โ†’ Fallback 1 (GPT-4o via OpenAI direct) โ†’ Fallback 2 (Claude 3.5 via Anthropic)
  2. Trigger conditions: HTTP 429 (rate limited), HTTP 5xx (provider error), timeout > SLO (e.g., 30s)
  3. Circuit state: Track failure rate per provider; skip degraded providers proactively (circuit breaker)
  4. Prompt adaptation: If switching model families (OpenAI โ†’ Claude), apply per-model prompt templates

LiteLLM pattern:

from litellm import completion
response = completion(
  model="gpt-4o",
  fallbacks=["claude-3-5-sonnet-20241022", "gemini/gemini-1.5-pro"],
  messages=[{"role": "user", "content": prompt}]
)

Trade-Offs:

  • โœ” Pro: High availability โ€” provider outages become seamless
  • โœ” Pro: Cost optimisation โ€” route to cheaper models during low-priority periods
  • โœ– Con: Different model families produce inconsistent outputs โ€” test each fallback path
  • โœ– Con: Cost unpredictability if fallbacks are more expensive

When To Use: Any production system with SLA requirements and more than 1000 RPD. When to avoid: Internal tools where brief downtime is acceptable.

Related Articles

the ai gateway pattern

Discussion

Sign in to share your feedback and join the discussion.