# Model Routing, Gateways and Fallbacks

> Route each request to the right model, survive provider outages with fallbacks, and centralize keys, limits and spend in an AI gateway. Free notes, key...

Canonical: https://www.internhack.in/roadmaps/tracks/ai-engineer/model-routing-fallbacks
Last updated: 2026-11-28

Route each request to the right model, survive provider outages with fallbacks, and centralize keys, limits and spend in an AI gateway.

Advanced · about 4 hours · difficulty 3/5

Learn first: [Rate Limits, Errors and Cost Awareness](https://www.internhack.in/roadmaps/tracks/ai-engineer/rate-limits-and-cost), [Regression Testing and Evals in CI](https://www.internhack.in/roadmaps/tracks/ai-engineer/eval-driven-development)

Depending on one model from one provider is a single point of failure and often a waste of money. Production systems increasingly treat models as interchangeable backends behind a routing layer.

### Routing

- **Static routing by task**: a small model for classification and extraction, a mid-sized model for most chat, a frontier or reasoning model for hard analysis.
- **Dynamic routing**: a cheap classifier estimates difficulty and picks a model per request. Validate with evals that the cheap path does not hurt quality.
- **Cascades**: try a cheap model first and escalate when a check fails or confidence is low.

### Fallbacks and resilience

- Retry transient errors with backoff, then **fail over** to another model or provider.
- Keep prompts portable; test your fallback model on your eval set so a failover does not silently degrade answers.
- Use **circuit breakers** to stop hammering a failing provider.
- Degrade gracefully: a shorter answer, a cached answer or a clear error beats a hanging spinner.

### AI gateways

Gateways such as LiteLLM, Portkey, Cloudflare AI Gateway or cloud platform equivalents sit between your app and providers. They offer a unified API, key management, per-team budgets, rate limiting, logging, caching and fallbacks in one place.

### Cost governance

Track spend per feature, team and customer. Set budgets and alerts, and review your most expensive prompts regularly.

### Good enough to move on

Your app routes at least two task types to different models, fails over to a second provider in a simulated outage, and reports cost per feature.

## Key concepts

- **Task-based model routing**
- **Cascades and escalation**
- **Provider failover**
- **Circuit breakers**
- **LiteLLM / Portkey gateways**
- **Per-feature cost tracking**
- **Graceful degradation**

## Mini project

Put a LiteLLM proxy (or your own router) in front of your app with a cheap and a strong model, route by task type, configure failover to a second provider, and show the cost difference on a day of traffic.

## Check yourself

Your fallback model has never been run against your eval set. What could go wrong during the next provider outage?

## Free resources

- [LiteLLM documentation](https://docs.litellm.ai/) (LiteLLM)
- [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/) (Cloudflare)
- [OpenRouter documentation](https://openrouter.ai/docs) (OpenRouter)

Previous: [Response Caching and Semantic Caching](https://www.internhack.in/roadmaps/tracks/ai-engineer/llm-caching) · Next: [Serving Open-Weight Models at Scale](https://www.internhack.in/roadmaps/tracks/ai-engineer/serving-open-models)

## More in LLMOps and Production Engineering

- [Deploying LLM-Powered Services](https://www.internhack.in/roadmaps/tracks/ai-engineer/deploying-ai-services)
- [Latency Optimization](https://www.internhack.in/roadmaps/tracks/ai-engineer/latency-optimization)
- [Response Caching and Semantic Caching](https://www.internhack.in/roadmaps/tracks/ai-engineer/llm-caching)
- [Model Routing, Gateways and Fallbacks](https://www.internhack.in/roadmaps/tracks/ai-engineer/model-routing-fallbacks)
- [Serving Open-Weight Models at Scale](https://www.internhack.in/roadmaps/tracks/ai-engineer/serving-open-models)
- [GPU and Hardware Basics for AI Engineers](https://www.internhack.in/roadmaps/tracks/ai-engineer/gpu-basics)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [AI Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/ai-engineer)
