One last thing before we move on. pass this to mark the lesson done, or skip and keep moving. hop to the next when you're ready.
Final drill. The pattern Perplexity and Cursor built into their products from day one: routing logic that picks the cheapest model that meets a quality floor under a monthly budget cap.
Build pick_model(constraint) that takes a constraint dict:
max_cost_per_month: float — the budget cap in dollars per user per monthquality_floor: str — one of"haiku","sonnet","opus"(the model must be at LEAST this good)
And returns one of: "haiku", "sonnet", "opus", or "none"
if no model meets both the floor AND the budget.
Quality ranking (low to high): haiku < sonnet < opus. A
quality_floor of "sonnet" means sonnet or opus qualifies; haiku
does not. Among models that meet the floor, pick the cheapest one
that stays under budget.
Use this fixed usage profile (don't change it):
- 20 messages/day
- 500 avg input tokens, 200 avg output tokens
- 30 days/month
- prices: haiku $1/$5, sonnet $2/$10, opus $5/$25 per 1M tokens
Five constraints run for you. Expected output:
tight budget, haiku floor: haiku
mid budget, sonnet floor: sonnet
big budget, opus floor: opus
tight budget, sonnet floor: none
big budget, haiku floor: haiku