AI-ENGINEERING
    intermediate

    Model Routing & Cost Engineering

    AI Engineer path · lesson 106 of 124
    The idea
    A model router is triage at an ER. Not every visitor needs a surgeon — the intake nurse routes sniffles to the small clinic and heart attacks to the surgeon, and only escalates when the first responder isn't sure.
    How to use
    Press play, switch policies, and watch the cost/quality bars swing. Cascade sometimes wins, sometimes loses — see when.
    Classify request shape/length and route: trivial → small, standard → medium, hard → big.
    —
    avg cost / req
    —
    p50 latency
    —
    avg quality
    —
    escalations / req
    Press Play to stream ~3 requests / second. Try switching policy mid-stream.

    Key insight

    Watch the numbers with a live stream: all-big is a flat quality ceiling at high cost; all-small is cheap but degrades on hard requests; a shape-based heuristic gets 90% of the quality at 20-40% of the cost; a cascade wins when the small model is right most of the time and the escalation signal is well-calibrated.

    Route a request by cost

    Sequence

    Order a cost-aware routing path.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    6. 6Drop a step here
    6 pieces left to place

    Test your knowledge

    20 questions
    Question 1 of 20
    Score: 0

    The main reason "just use a smaller model" is often a worse cost lever than routing:

    The short version

    A model router is triage at an ER. Not every visitor needs a surgeon — the intake nurse routes sniffles to the small clinic and heart attacks to the surgeon, and only escalates when the first responder isn't sure.

    In more depth

    Model routing & cost engineering

    A production LLM system rarely wants one model for every request. Requests differ in complexity, and models differ in cost by 10-50× — routing spreads a diverse workload across a tiered fleet.

    Four common policies

    1.All-big — highest quality, worst cost/latency. Baseline for measuring lift elsewhere.
    2.All-small — cheapest & fastest, degrades on hard requests.
    3.Heuristic router — classify by shape (length, keywords, code presence) and route to the smallest model that will meet quality.
    4.Confidence cascade — try small first; escalate to bigger models when a signal says the small model is uncertain.

    Escalation signals

    Top-token logprob
    Verifier / NLI score against retrieved evidence
    Response length / structural triggers
    Tool-call count / recursion depth

    Why routing beats picking a smaller model outright

    A smaller model saves money globally but drops quality on the hard tail. Routing preserves quality on the tail (small share of requests) while capturing most of the savings on the easy majority.

    Instrument per-route

    Blended quality hides regressions in one bucket. Alert on per-route quality, not the average — and re-tune thresholds when the model versions or traffic mix change.

    Interview Questions

    OpenAI
    Anthropic
    Databricks
    Google
    Meta
    Anthropic
    Amazon
    Google
    Mistral
    NVIDIA
    Databricks
    OpenAI

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required