Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

LLM Cost Engineering

Free · sign in to start and track progress

1 · Spending less on the same work

  • 1Token economics of an agent fleet
  • 2Prompt caching as system design
  • 3Trimming and compacting context
  • 4Batch, flex and fast tiers

2 · Changing the model, and governing the spend

  • 5Cost-quality curves, routing and cascades

    Exercise answers

    • Answer: Measure a cost-quality curve and test a cascade
    • Answer: Does a learned router beat self-confidence?
  • 6Distilling into small models
  • 7Self-hosting break-even
  • 8Attribution, budgets and alerts
CapstoneCost-engineer an agent pipelineReference implementation

Module 2 · Changing the model, and governing the spend · Lesson 5

Cost-quality curves, routing and cascades

Measuring the cost-quality frontier with evals, then deciding whether static routing, a learned router or a cheap-first cascade moves you along it, with the arithmetic that shows when a cascade beats the strong model and when its verifier caps it.

80 min 1 video 3 exercises 6-question quiz Answers
Setup for the exercises:Install Claude CodePython with uv

By the end of this lesson you can

  • Build a cost-quality curve from an eval across models and effort levels, and identify its Pareto frontier
  • Derive the cost and accuracy of a two-model cascade from the cheap model's error rate and the verifier's recall and false-alarm rate
  • Explain how FrugalGPT, RouteLLM, Hybrid LLM and AutoMix route or cascade, and what their reported savings depend on
  • Size an eval large enough to tell two configurations apart, and account for cache and latency effects of routing

On this page

  • Intuition: triage at the front desk
  • Step one: measure the curve
  • How big must the eval be?
  • Three ways to use two models
  • The mechanism: cascade arithmetic
  • Worked example
  • Same model, two passes
  • Hidden costs of routing
  • Misconceptions and limits
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01Intuition: triage at the front desk
  2. 02Step one: measure the curve
  3. 03Three ways to use two models
  4. 04The mechanism: cascade arithmetic
  5. 05Hidden costs of routing
  6. 06Misconceptions and limits
  7. 07Connections
  8. 08Summary

Sources & further reading

  • FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving PerformancePaper · Chen, Zaharia, Zou · 2023The LLM cascade (query cheap models first, score the answer, stop when it is good enough), with up to 98% cost reduction at GPT-4-level accuracy on its benchmarks. Read section 3 on the cascade and its learned scorer.
  • RouteLLM: Learning to Route LLMs with Preference DataPaper · Ong, Almahairi, Wu, Chiang, Wu et al. · 2024Routers trained on human preference data choose between a strong and a weak model before calling either, cutting cost by over 2× in some settings without lowering quality, and transferring to new model pairs.
  • Hybrid LLM: Cost-Efficient and Quality-Aware Query RoutingPaper · Ding, Mallick, Wang, Sim, Mukherjee et al. · Microsoft Research · 2024ICLR 2024. A difficulty-predicting router with a tunable quality threshold; up to 40% fewer large-model calls with no drop in quality.
  • AutoMix: Automatically Mixing Language ModelsPaper · Aggarwal, Madaan et al. · 2023NeurIPS 2024. A cascade whose escalation signal is the small model's few-shot self-verification, with a POMDP router to handle noisy verification; over 50% cost reduction at comparable performance.
  • Predictable performance is suboptimal, and what it means for model routingPaper · Zhang, Hardt · 2026Shows that learned performance predictors only beat a model's own self-confidence when the model is suboptimal on the task, and that the advantage shrinks after fine-tuning. A useful corrective before building an elaborate router.
  • Dynamic Model Routing and Cascading for Efficient LLM Inference: A SurveyPaper · Moslem, Kelleher · 2026The current survey of routing paradigms (difficulty, preference, clustering, uncertainty, reinforcement learning, cascades) with a framework for when decisions are made, on what information, and how.
  • Optimizing for cost and intelligence (Claude docs)Docs · AnthropicEffort sweeps, re-running failures at a higher effort, and the rule that a multi-model configuration must beat the single model's whole score-versus-spend curve.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 8 more sections
  • 3 hands-on exercises
  • A 6-question quiz
  • Progress, quiz scores and bookmarks