promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_

The model picker — when Sonnet is wrong and Haiku is right — step 8 of 8

Checkpoint

One last thing before we move on. pass this to mark the lesson done, or skip and keep moving.

Final drill. Synthesize the model picker AND its cost into one function: cost_aware_routing(tasks).

Takes a list of task dicts (same shape as step 7: kind, volume_per_day, latency_ms_max, criticality).

Returns a dict:

  • routes: dict mapping each task's kind to the chosen model ("haiku", "sonnet", or "opus").
  • total_cost: float, total estimated daily cost across all tasks, rounded to 2 decimal places.

Use the same routing rules from step 7:

  1. volume_per_day >= 10000"haiku", unless criticality == "high""sonnet".
  2. volume_per_day < 100 AND criticality == "high""opus".
  3. Default → "sonnet".

Cost math: assume each call averages 1000 tokens. Blended prices per million tokens:

  • haiku: $3.00
  • sonnet: $6.00
  • opus: $15.00

Daily cost for one task = volume_per_day * 1000 * (rate / 1_000_000), which simplifies to volume_per_day * rate / 1000.

Five tasks run. Expected output:

ticket_tagger     -> haiku
support_summary   -> sonnet
contract_review   -> opus
fraud_alert       -> sonnet
architect_review  -> opus
total daily cost: $300.09

full-screen editor opens — close anytime to keep reading.