Skip to content
All patterns
Cost

Model routing

One frontier model for everything versus routing by difficulty

Savings depend on your traffic mix, so measure routing accuracy and quality per model.

Problem

Using a frontier model for every query is expensive and slow. Most queries are simple and a small model is sufficient.

Pattern

Classify query complexity and route to the cheapest model that can handle it, with fallback to stronger models on low confidence.

Implementation
router.py
# Model names change often; check your provider's model list (as of 28 October 2026). Replace <...-model> with a model id from that list.
SMALL, LARGE = "<small-model>", "<large-model>"

def route_model(query: str, history: list) -> str:
    # Rule-based fast path
    if len(history) == 0 and len(query) < 80:
        # Simple first turn — try small model
        return SMALL

    # Keyword signals for complexity
    complex_signals = ["analyse", "compare", "design", "architect", "debug"]
    if any(sig in query.lower() for sig in complex_signals):
        return LARGE

    # Default to the small model
    return SMALL

def call_with_routing(query, history):
    model = route_model(query, history)
    try:
        return call_llm(query, model=model), model
    except LowConfidenceError:
        # Escalate to the large model
        return call_llm(query, model=LARGE), LARGE
Trade-offs
  • Large cost reduction on mixed traffic (60-80% is a commonly quoted rule of thumb; it depends on your traffic mix and prices)
  • Classification errors route to wrong model
  • Behavioural inconsistency across models
  • Requires per-model evals
Production checklist
  • Monitor routing accuracy
  • Per-model cost and quality dashboards
  • Fallback on low confidence
  • A/B test routing rules
  • Pin model versions