The LiteLLM Router: Load Balancing & Fallbacks

9 min read Module 3 of 10 Lesson 9 of 28

What you'll learn

  • Configure multiple deployments under one model_name and observe requests distributed across them
  • Explain the default simple-shuffle routing strategy and when to reach for latency-based or usage-based routing instead
  • Configure a fallback chain so a failed cloud call automatically retries against a self-hosted open-weight model
  • Distinguish load balancing (spreading healthy traffic) from fallback (recovering from failure) as two related but distinct router responsibilities
Building this at your company? For enterprise and company teams taking this to production: book a 30-minute session with our AI engineers for architecture guidance, code review, and a rollout plan for your use case.
Book a Team Session

Lessons 7 and 8 built a model_list with distinct aliases, one deployment each. Real production traffic needs two more things from the routing layer: spreading load across multiple healthy deployments of the same logical model, and automatically recovering when a deployment fails. Both are the job of LiteLLM’s Router, and this lesson configures both, first as a standalone Python object, then as proxy config.

Load Balancing: Multiple Deployments, One Alias

from litellm import Router

model_list = [
    {
        "model_name": "production-chat",           # shared alias: this is the pool
        "litellm_params": {"model": "openai/gpt-4o", "api_key": "sk-openai-..."},
    },
    {
        "model_name": "production-chat",            # second deployment in the same pool
        "litellm_params": {
            "model": "hosted_vllm/meta-llama/Llama-3.1-8B-Instruct",
            "api_base": "http://localhost:8000/v1",
            "api_key": "none",
        },
    },
]

router = Router(model_list=model_list, routing_strategy="simple-shuffle")

response = router.completion(
    model="production-chat",                        # router picks which deployment actually serves this
    messages=[{"role": "user", "content": "Summarize this ticket in one sentence."}],
)

simple-shuffle is the router’s default: it distributes requests across the pool without needing external state. Two other strategies matter for production: latency-based-routing continuously tracks each deployment’s recent response time and biases traffic toward the faster one, useful when self-hosted and cloud deployments have meaningfully different latency profiles; usage-based-routing-v2 tracks per-deployment request/token volume in Redis and balances to stay under each deployment’s configured rate limit, which matters once a deployment’s own rpm/tpm ceiling, not just raw speed, is the binding constraint.

# Prefer the faster deployment when latencies diverge meaningfully
router = Router(model_list=model_list, routing_strategy="latency-based-routing")

# Balance to respect each deployment's own rate limits, needs Redis
router = Router(
    model_list=model_list,
    routing_strategy="usage-based-routing-v2",
    redis_host="localhost", redis_port=6379,
)

Fallbacks: Recovering from Failure

Load balancing assumes every deployment in the pool is healthy. Fallbacks handle the case where one is not. LiteLLM configures this as an explicit mapping from a primary model name to an ordered list of fallback model names:

router = Router(
    model_list=model_list,
    fallbacks=[{"production-chat": ["self-hosted-llama-fallback"]}],
    num_retries=2,
)
# The equivalent proxy config.yaml, extending Lesson 8's model_list
model_list:
  - model_name: production-chat
    litellm_params:
      model: openai/gpt-4o
      api_key: os.environ/OPENAI_API_KEY

  - model_name: self-hosted-llama-fallback
    litellm_params:
      model: hosted_vllm/meta-llama/Llama-3.1-8B-Instruct
      api_base: http://localhost:8000/v1
      api_key: "none"

litellm_settings:
  fallbacks:
    - production-chat: ["self-hosted-llama-fallback"]
  num_retries: 2
sequenceDiagram
    participant Client
    participant Router
    participant GPT4o as gpt-4o (primary)
    participant Llama as self-hosted Llama (fallback)

    Client->>Router: completion(model="production-chat")
    Router->>GPT4o: call
    GPT4o-->>Router: 500 / timeout
    Note over Router: primary failed, walk fallback chain
    Router->>Llama: call
    Llama-->>Router: 200 OK
    Router-->>Client: response (from fallback deployment)

The router only tries self-hosted-llama-fallback after production-chat actually fails, this is deliberately not a load-balancing pool: the fallback is a last resort, not a peer sharing traffic on the happy path. Routing a fallback to a self-hosted deployment specifically, rather than a second cloud provider, buys resilience against a cloud-provider-wide outage, since the self-hosted server’s availability has no dependency on that provider’s infrastructure at all, at the cost of potentially different output quality from the fallback model, a trade-off Lesson 14 covers when it looks at graceful degradation in more depth.

With load balancing and a basic fallback chain running, Module 4 goes deeper on the actual decision logic behind routing, static priority, live latency and cost signals, and classifying a prompt to pick the right model for its task, rather than the single flat pool used here.

Knowledge Check

3 questions to test your understanding

1 Two model_list entries both use model_name: 'production-chat', one pointing at openai/gpt-4o and one at a self-hosted vLLM Llama deployment. With the default routing_strategy, what happens when a client requests model='production-chat'?

2 What is the functional difference between load balancing and a fallback chain, as the router uses the terms?

3 Why would a team configure a fallback from a cloud model to a self-hosted open-weight model, rather than to a second cloud provider?

Go further with expert guidance

Ready to build production AI?
Talk to our R&D team.

These courses give you the foundation. Our embedded AI teams take you from prototype to production in 30–90 days, with your team, your codebase, your goals. Book a free strategy call to see how we can accelerate your AI initiative.

30 minutes · No obligation · Expert AI engineers, not sales reps

AI Architecture Review

Audit your current stack and identify high-impact improvements

Project Review

Get expert feedback on your AI implementation and codebase

Team Mentoring

Upskill your engineers with hands-on AI coaching sessions

AI Strategy

Define your AI roadmap, prioritization, and implementation plan