Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 81/ 160
05. AI System Design

Model Routing

Send easy tasks to cheap models and hard tasks to strong ones automatically.

IntermediateRouter · Cheap→Strong3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

Easy questions go to a cheap, fast AI, and hard ones go to the expensive, smart AI, so you save money without lowering the quality much.

Think of it like…

A hospital triage desk: minor complaints go to a nurse practitioner, complex cases go to a specialist, and a wrong triage is costly in either direction, so the desk is audited against outcomes.

Where you’ve seen it

Illustrative prices: large model $2.50 / $10 per million input / output tokens, small model $0.15 / $0.60. A typical request (3,100 input, 420 output tokens) costs $0.01195 on the large model and $0.000717 on the small one. The team labels traffic: 65% is easy (the small model resolves 94% of these versus 97% on the large model) and 35% is hard (large model 77%). Large-only quality is 0.65 × 0.97 + 0.35 × 0.77 = 90.0%. A trained classifier router (about $0.0002 per request) sends the easy 65% to the small model: blended LLM cost 0.65 × 0.000717 + 0.35 × 0.01195 = $0.00465, plus the router, $0.00485, a 59% saving. Quality becomes 0.65 × 0.94 + 0.35 × 0.77 = 88.1% (down 1.9 points), so cost per resolved request falls from $0.01328 to $0.00551 (−58.5%). The team decides the 1.9-point drop is acceptable for support, but keeps billing-dispute questions on the large model by rule.

Words you’ll hear

Router
A component that picks a model for each request before generation.
Cascade
Try the cheap model first and escalate to a stronger one when a check fails.
Escalation rate
The share of requests that cascade up to the strong model.
Misrouting cost
The quality loss when a hard request is sent to a weak model.

Visual diagram

Loading interactive diagram

Theory & deep dive

Router designs and signals

Rule-based routers use cheap signals: intent from the UI (a button versus a free-text box), input length, presence of code or tables, language, customer tier, and risk category (payments, legal, medical). They're transparent and fast. Classifier routers train a small model (logistic regression on embeddings, or a fine-tuned small transformer) on labelled examples of which model succeeded, predicting difficulty or the probability that the small model is good enough. LLM routers ask a small model to rate difficulty, which is flexible but adds latency and cost. Learned routers (trained on preference or outcome data) can tune the cost-quality trade-off with a single threshold.

A cascade runs the cheap model first and escalates when a check fails: invalid JSON, a refusal or "I don't know", low token log-probabilities, disagreement between two cheap samples, a failed rule, or a verifier model's low score. Expected cost = c_small + p_escalate × c_large (+ verifier cost), and latency is paid twice on escalations. Cascades suit tasks with cheap, reliable verifiers (code that must pass tests, extractions that must match a schema); routers suit tasks where difficulty is predictable from the input.

Cascade cost

Small $0.000717, large $0.01195. If 25% of requests escalate: expected cost = 0.000717 + 0.25 × 0.01195 = $0.00370, plus a verifier at $0.0003 = $0.00400, about 67% cheaper than large-only, while escalated requests take roughly 1.3 to 2 times longer.

Key takeaway: Use rules or classifiers for predictable difficulty and cascades when a cheap verifier can catch failures.

Evaluating and operating a router

Evaluate the whole system, not each model in isolation: replay a labelled golden set (with difficulty and risk tags) through the router and report quality per route and per tag, the escalation or misrouting rate, cost per request and cost per successful request, and latency percentiles. Examine the confusion matrix of the router itself: hard requests sent to the small model (the costly error) versus easy requests sent to the large model (wasted money). Choose the threshold on the cost-quality curve, setting a minimum quality floor per risk tier rather than one global number.

In production, monitor drift (the mix of easy and hard traffic shifts, models change versions), sample a few percent of cheap-route outputs for judge and human review, and keep a manual override and a kill switch that sends everything to the strong model. Keep prompts compatible across models (tool schemas, output formats) or maintain per-model prompt variants and test each. Remember the hidden costs: router latency, maintenance of labels, and engineering complexity; below a modest spend, a single mid-sized model may be simpler and good enough.

Misrouting asymmetry

Router sends 8% of hard requests to the small model, where success drops from 77% to about 50%. On 35% hard traffic, that is 0.35 × 0.08 × 0.27 ≈ 0.8 points of quality lost, a number that appears in the per-bucket report but not in a blended average.

Key takeaway: Judge the router by per-route quality and cost per success, monitor drift and keep an override.

How it works, step by step

Step 1 of 4
Eval team

1. Segment and label traffic

Tag a golden set by difficulty and risk and measure each model's quality per segment.

easy 65% · hard 35%
Key numbers at this step
Large
97% easy · 77% hard

When to use it & trade-offs

What it is

Model routing sends each request to the cheapest model that can handle it well: easy, high-volume requests (classification, extraction, FAQ answers) go to a small, fast, inexpensive model, and hard ones (multi-step reasoning, ambiguous or high-stakes cases) go to a strong model. Two main designs exist: a router that decides before calling any model (rules, a trained classifier or a small LLM), and a cascade that calls the cheap model first and escalates if a verifier, confidence signal or format check says the answer isn't good enough. The goal is to cut cost and latency while keeping quality within a measured tolerance.

Why it matters: Model prices differ by one to two orders of magnitude, and most production traffic is easier than the hardest case. Sending everything to the biggest model overpays for the majority of requests; sending everything to the smallest one fails the hard minority. Routing captures the savings without a blanket quality drop, but only if you measure the quality of each route, because a bad router silently degrades the hard cases.

When to reach for it

  • High-volume mixed-difficulty workloads
  • Cost control without moving everything to a weaker model
  • Risk-tiered handling of sensitive intents

When to avoid or be careful

  • Routing without per-route quality measurement
  • Sending high-stakes topics down the cheap path
  • Building a router for low-volume traffic where the complexity outweighs savings

Routing approaches

Rule-based router
Best for: Clear signals such as intent, tier and risk

Strengths: Transparent, instant, no extra model.

Watch out: Brittle for subtle difficulty differences.

Learned classifier router
Best for: Predicting difficulty from the input at scale

Strengths: Tunable threshold; cheap inference.

Watch out: Needs labelled outcomes and retraining.

Cascade with verifier
Best for: Tasks with cheap, reliable checks

Strengths: Catches failures by construction.

Watch out: Extra latency on escalations and verifier cost.

Interview signals & numbers to know

When this topic comes up

  • “Do we need the biggest model for everything?”
  • “Our LLM bill is dominated by simple requests”
  • Cheap-to-strong cascade
  • Escalation rate
  • Cost per successful request

Benchmarks & rules of thumb

$0.01195 vs $0.000717 -
per-request cost on large vs small model in the example
−59% -
cost saving with a router
1.9 pts -
quality given up for that saving

Common mistakes & follow-ups

Common interview mistakes

  • Reporting only the blended quality and missing a hard-case collapse.
  • Forgetting that a cascade pays latency twice on escalations.
  • Letting prompts diverge so the fallback model behaves differently than tested.

Likely interviewer follow-ups

  • How would you decide which requests go to the cheaper model?
  • What are the trade-offs between a router and a cascade?
  • How would you monitor a router in production?
Interview tip: Give cost per successful request alongside cost per request. It shows you won't accept a saving that destroys the hard cases.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Model Routing with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
User Feedback Loops
Next topic
Model Fallbacks