Stop paying Sonnet prices for Haiku work — route by task complexity, not model preference
Our coding agent was burning through Claude API credits like crazy. $200+ bills for what should have been $30 worth of work. The culprit? It was using Claude 3.5 Sonnet for everything — including tasks that Haiku could handle for 1/20th the cost.
Most people think model routing is about intelligence levels. Wrong. It's about matching cognitive load to task complexity.
Here's the routing logic that cut our costs 73%:
def route_model(task_type, context_size, requires_reasoning):
# File operations, simple edits, documentation
if task_type in ['read', 'edit', 'format'] and context_size < 2000:
return 'claude-3-haiku'
# Complex debugging, architecture decisions
if requires_reasoning or 'debug' in task_type:
return 'claude-3-5-sonnet'
# Everything else - the sweet spot
return 'claude-3-5-haiku'The magic isn't in the routing logic — it's in teaching your agent to self-assess before choosing a model.
We added a preprocessing step that analyzes the task:
- Simple file operations: Reading configs, updating documentation, formatting code → Haiku ($0.25/1M tokens)
- Standard development: Writing functions, fixing bugs, implementing features → Haiku 3.5 ($1/1M tokens)
- Complex reasoning: Architecture decisions, debugging race conditions, performance optimization → Sonnet ($3/1M tokens)
The key insight: 80% of coding tasks don't need the most expensive model. Your agent just defaults to it because that's what you configured.
Most agents use Sonnet for everything because it "just works." But paying $3/1M tokens to read a config file is like hiring a senior architect to change a lightbulb.
Here's what surprised us: Haiku 3.5 handles 90% of our coding tasks perfectly. The only time we need Sonnet is for genuine complexity — debugging distributed systems, optimizing algorithms, or making architectural decisions.
Our routing saved us $140 last month alone. On a $200 bill, that's real money.
The pattern works because most coding is routine. Your agent spends more time reading existing code, making small edits, and running tests than it does solving novel problems. Route accordingly.
Want to implement this? Start with a simple rule: if the task involves more than 3 files or requires understanding system interactions, use Sonnet. Everything else gets Haiku 3.5.
Your agent will be just as effective and your bill will shrink by 60-80%. The only thing you'll lose is the anxiety of checking your API usage dashboard.