Model routing & cascades

In one sentence

Send each request to the cheapest model that can handle it, by rules, a learned classifier or a cascade that escalates on a failed check, and fall back to another provider on outages.

Analogy: Hospital triage: a nurse handles most visits, sends the hard cases straight to a specialist, and if the nurse's quick check doesn't add up, the patient goes up a level.

Rules or a classifier route up front; the cascade escalates only when a check on the small model's output fails.

How it works

  • It pays because traffic is mixed and price gaps are large: a small model can be ~20× cheaper.
  • Start with rules (task type, input length, tenant tier): free, transparent, the right first step.
  • A learned router predicts whether the cheap model is good enough; RouteLLM reported over 2× cost reduction at similar quality.
  • A cascade costs small + P(escalate) × large; escalated requests pay twice and wait longer.
  • Measure quality per route: a router that sends hard cases to the small model loses users.

Check yourself

Answer to mark it learned; your answers aren't scored.

Your cascade accepts the small model's answer when the model reports confidence >= 0.8. Escalation is only 5% and costs fell sharply, but the golden-set score dropped 8 points. Best fix?

Go deeper

Full explanation

Model routing picks a model per request instead of one model for everything. It pays because traffic is mixed and price gaps are large: within one family the small model can be ~20× cheaper.

Three mechanisms, often combined:

  • Rules: route by task type, input length, tenant tier or feature. Free and transparent; the right first step.
  • Learned router: a small classifier predicts whether the cheap model will be good enough. RouteLLM (LMSYS, 2024) trains one on human preference data and reported over 2× cost reduction at similar quality on benchmarks such as MT Bench. A small LLM doing Pattern: routing, or embedding similarity to labeled examples, are cheaper variants.
  • Cascade: try the small model first; accept if a check passes (schema validation, tests, a verifier), otherwise escalate. Expected cost = small + P(escalate) × large, and escalated requests pay twice and wait longer.

Fallbacks are routing for reliability: on 429s, 5xx or timeouts, retry the same model on another provider or region, then a different model, through an LLM gateway.

The non-negotiable part: measure quality per route. Log the route on every request, evaluate each slice against your golden set and watch the escalation rate. A router that quietly sends hard cases to the small model saves money by losing users.

Code Rule + cascade router with a verifiable check
pythonRule + cascade router with a verifiable check
from typing import Literal
from openai import OpenAI
from pydantic import BaseModel

client = OpenAI()
SMALL = "gpt-4.1-nano"  # any cheap model
LARGE = "gpt-4.1"       # any strong model

class Draft(BaseModel):
    category: Literal["billing", "bug", "how_to", "account", "other"]
    reply: str
    policy_id: str | None  # the policy the reply relies on, if any

def ask(model: str, ticket: str) -> Draft:
    r = client.responses.parse(model=model, instructions="Triage and draft a reply.",
                               input=ticket, text_format=Draft)
    return r.output_parsed

def passes_check(d: Draft) -> bool:
    # Verifiable checks beat the model's self-reported confidence (poorly calibrated)
    return d.category != "other" and (d.policy_id is None or kb_has(d.policy_id))

def route(ticket: str, tier: str) -> tuple[Draft, str]:
    if tier == "enterprise" or len(ticket) > 6_000:  # rule: skip the cascade
        return ask(LARGE, ticket), "rule:large"
    try:
        d = ask(SMALL, ticket)
        if passes_check(d):
            return d, "small"
    except Exception:  # invalid output or provider error: escalate, don't fail
        pass
    return ask(LARGE, ticket), "escalated"  # log the route; eval each slice
Real example

A support app sends 1M tickets/month to a frontier model. Error analysis shows ~70% are password resets, order status and FAQ-style questions. They add a cascade: a model ~20× cheaper drafts the reply, a deterministic check (valid category, cited policy exists) gates it, and failures escalate. Escalation runs at 25%, so expected cost ≈ 0.05 + 0.25 × 1 = 0.30 of the all-frontier bill, a ~70% cut. Overall resolution rate holds on the golden set, but one slice, refunds in Spanish, drops 6 points, so a rule now sends refunds straight to the large model.

Trade-offs +3 · −3

+ You gain

  • Large savings on mixed traffic: easy requests stop paying frontier prices.
  • Lower latency for the easy majority, since small models answer faster.
  • The same gateway layer gives provider fallbacks and model A/B tests.

− You pay

  • Another component to evaluate: a bad router hides quality loss inside averages.
  • Cascades pay twice and add latency on every escalation.
  • Routers drift: new models, prices and traffic move the right thresholds.

Use it when

Mixed traffic with a clear easy majority, a large price gap between candidate models, and an eval set that can measure quality per route.

Avoid it when

Low volume, uniformly hard tasks, or no way to measure quality per slice: one good model plus caching is simpler and safer.

Numbers to know 4
  • RouteLLM (LMSYS, 2024): over 2× cost reduction at similar quality; ~85% cheaper than GPT-4-only on MT Bench at 95% of its quality.
  • FrugalGPT (2023): cascades matched GPT-4 quality at up to 98% lower cost on its benchmarks.
  • Cascade cost = small + P(escalate) × large: a 20× cheaper model with 25% escalation costs ~30% of all-large.
  • Price gap to exploit: GPT-4.1 $2 vs GPT-4.1-nano $0.10 per 1M input tokens (20×, 2025 list).
Common pitfalls 4
  • Trusting the model's self-reported confidence: it is poorly calibrated. Use verifiable checks or a trained router.
  • Judging the router on average quality only: check each route and slice (language, tier, intent).
  • Falling back to a model your prompts were never tested on: a fallback is a deployment, eval it.
  • A routing LLM call that costs nearly as much as the answer it is trying to save.
Interview questions 2

Answer out loud first, then reveal.

Router or cascade: how do you choose?Show answer

A router decides before generating, so it never pays twice, but it needs to predict difficulty from the input alone; that works when difficulty shows in task type, length or tenant. A cascade decides after seeing the small model's output, so it can use a real check (valid schema, tests passing, a cited source that exists), but escalations pay for both calls and add latency. I start with rules, add a cascade wherever I have a cheap verifiable check, and train a router only once I have enough labeled traffic to evaluate it.

How do you make sure routing doesn't quietly degrade quality?Show answer

I log the route and model on every request and evaluate each route as its own slice against the golden set, not just the blended average, because a small average drop can hide a large drop in one segment. Online, I track escalation rate, user feedback and task success per route, and keep a small random sample going to the large model as a control. Any change to thresholds or models goes through the same offline eval and a staged rollout.