name: model-router
description: >
Dynamically route Claude API calls between expensive and cheap models based on task complexity.
Use this skill whenever the user wants to optimize API costs, reduce latency, build a smart
model-switching system, or automatically select between Claude Haiku and Claude Sonnet/Opus
based on what the task actually needs. Trigger this skill for any mention of model routing,
cost optimization, tiered model usage, dynamic model selection, or smart API dispatching —
even if the user just says "I want to save on API costs" or "route tasks to the right model."
Model Router Skill
What This Skill Does
This skill teaches Claude to build a two-stage routing system that:
- Uses a cheap classifier (Haiku) to assess task complexity
- Routes to the appropriate model based on that assessment
The result: maximum quality where it matters, minimum cost everywhere else.
Model Tier Map
| Tier |
Model |
Use When |
| Fast |
claude-haiku-4-5-20251001 |
Simple Q&A, formatting, translation, summarization |
| Smart |
claude-sonnet-4-6 |
Reasoning, code, analysis, multi-step tasks |
| Power |
claude-opus-4-6 |
Architecture decisions, deep synthesis, highest stakes |
Core Routing Logic
Stage 1 — Classify (always use Haiku, it's cheap)
Send the user's prompt to Haiku with this system prompt:
You are a task complexity classifier. Analyze the user's prompt and return ONLY valid JSON.
No preamble, no markdown fences.
Return this structure:
{
"complexity": "simple" | "medium" | "complex",
"reasoning": "one sentence explanation",
"estimated_tokens": <number>
}
Classification rules:
- simple: factual Q&A, yes/no, formatting, translation, basic summarization, single-step tasks
- medium: code generation, multi-step reasoning, content creation, structured analysis
- complex: architecture decisions, deep research synthesis, cross-domain reasoning, debugging complex systems
Stage 2 — Route
simple → claude-haiku-4-5-20251001
medium → claude-sonnet-4-6
complex → claude-opus-4-6
Implementation Pattern (JavaScript / React)
async function routeAndRun(userPrompt) {
// Stage 1: Classify
const classifyRes = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: "claude-haiku-4-5-20251001",
max_tokens: 200,
system: CLASSIFIER_SYSTEM_PROMPT,
messages: [{ role: "user", content: userPrompt }]
})
});
const classifyData = await classifyRes.json();
const { complexity, reasoning } = JSON.parse(classifyData.content[0].text);
// Stage 2: Route
const modelMap = {
simple: "claude-haiku-4-5-20251001",
medium: "claude-sonnet-4-6",
complex: "claude-opus-4-6"
};
const selectedModel = modelMap[complexity];
// Stage 3: Execute
const response = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: selectedModel,
max_tokens: 1000,
messages: [{ role: "user", content: userPrompt }]
})
});
const data = await response.json();
return {
answer: data.content[0].text,
model: selectedModel,
complexity,
reasoning
};
}
Cost Insight
The classifier call costs ~$0.0002 per call (Haiku, ~200 tokens).
If 70% of your traffic is simple tasks routed to Haiku instead of Sonnet,
you reduce costs by ~85% on those calls — with classifier overhead under 1%.
Key Design Decisions
- Always classify with Haiku — never use Sonnet/Opus just to decide which model to use
- Keep classifier prompt tight — the output must be parseable JSON, no fluff
- Add a fallback — if JSON parsing fails, default to
medium (Sonnet)
- Log routing decisions — track which tasks land where; use this to tune thresholds over time
- Never route user-facing trust-critical tasks to Haiku — legal, medical, financial decisions should default to medium/complex
Edge Cases to Handle
| Scenario |
Recommended Handling |
| Classifier returns invalid JSON |
Default to medium, log the failure |
| API error on selected model |
Retry once, then fall back to Sonnet |
| Very long prompts (>4k tokens) |
Override to medium or complex regardless |
| User override requested |
Honor it — expose a forceModel param |
Testing This Skill
Run these prompts and verify correct routing:
Should → Haiku (simple)
- "What is the capital of France?"
- "Translate 'good morning' to Spanish"
- "Format this list alphabetically: banana, apple, cherry"
Should → Sonnet (medium)
- "Write a Python script to parse a CSV and compute weekly averages"
- "Explain the tradeoffs between REST and GraphQL APIs"
- "Draft a 3-paragraph product update for our stakeholders"
Should → Opus (complex)
- "Design a multi-tenant SaaS architecture for a fintech platform handling PII"
- "Synthesize these 5 research papers and identify contradictions"
- "Debug why our distributed system has intermittent data inconsistency under load"
1---2name: model-router3description: Dynamically route Claude API calls between expensive and cheap models based on task complexity. Use this skill whenever the user wants to optimize API costs, re4---5---6name: model-router7description: >8 Dynamically route Claude API calls between expensive and cheap models based on task complexity.9 Use this skill whenever the user wants to optimize API costs, reduce latency, build a smart10 model-switching system, or automatically select between Claude Haiku and Claude Sonnet/Opus11 based on what the task actually needs. Trigger this skill for any mention of model routing,12 cost optimization, tiered model usage, dynamic model selection, or smart API dispatching —13 even if the user just says "I want to save on API costs" or "route tasks to the right model."14---1516# Model Router Skill1718## What This Skill Does1920This skill teaches Claude to build a **two-stage routing system** that:211. Uses a cheap classifier (Haiku) to assess task complexity222. Routes to the appropriate model based on that assessment2324The result: maximum quality where it matters, minimum cost everywhere else.2526---2728## Model Tier Map2930| Tier | Model | Use When |31|------------|------------------------------|-------------------------------------------------------|32| **Fast** | `claude-haiku-4-5-20251001` | Simple Q&A, formatting, translation, summarization |33| **Smart** | `claude-sonnet-4-6` | Reasoning, code, analysis, multi-step tasks |34| **Power** | `claude-opus-4-6` | Architecture decisions, deep synthesis, highest stakes|3536---3738## Core Routing Logic3940### Stage 1 — Classify (always use Haiku, it's cheap)4142Send the user's prompt to Haiku with this system prompt:4344```45You are a task complexity classifier. Analyze the user's prompt and return ONLY valid JSON.46No preamble, no markdown fences.4748Return this structure:49{50 "complexity": "simple" | "medium" | "complex",51 "reasoning": "one sentence explanation",52 "estimated_tokens": <number>53}5455Classification rules:56- simple: factual Q&A, yes/no, formatting, translation, basic summarization, single-step tasks57- medium: code generation, multi-step reasoning, content creation, structured analysis58- complex: architecture decisions, deep research synthesis, cross-domain reasoning, debugging complex systems59```6061### Stage 2 — Route6263```64simple → claude-haiku-4-5-2025100165medium → claude-sonnet-4-666complex → claude-opus-4-667```6869---7071## Implementation Pattern (JavaScript / React)7273```javascript74async function routeAndRun(userPrompt) {75 // Stage 1: Classify76 const classifyRes = await fetch("https://api.anthropic.com/v1/messages", {77 method: "POST",78 headers: { "Content-Type": "application/json" },79 body: JSON.stringify({80 model: "claude-haiku-4-5-20251001",81 max_tokens: 200,82 system: CLASSIFIER_SYSTEM_PROMPT,83 messages: [{ role: "user", content: userPrompt }]84 })85 });86 const classifyData = await classifyRes.json();87 const { complexity, reasoning } = JSON.parse(classifyData.content[0].text);8889 // Stage 2: Route90 const modelMap = {91 simple: "claude-haiku-4-5-20251001",92 medium: "claude-sonnet-4-6",93 complex: "claude-opus-4-6"94 };95 const selectedModel = modelMap[complexity];9697 // Stage 3: Execute98 const response = await fetch("https://api.anthropic.com/v1/messages", {99 method: "POST",100 headers: { "Content-Type": "application/json" },101 body: JSON.stringify({102 model: selectedModel,103 max_tokens: 1000,104 messages: [{ role: "user", content: userPrompt }]105 })106 });107 const data = await response.json();108109 return {110 answer: data.content[0].text,111 model: selectedModel,112 complexity,113 reasoning114 };115}116```117118---119120## Cost Insight121122The classifier call costs ~$0.0002 per call (Haiku, ~200 tokens).123If 70% of your traffic is simple tasks routed to Haiku instead of Sonnet,124you reduce costs by ~85% on those calls — with classifier overhead under 1%.125126---127128## Key Design Decisions129130- **Always classify with Haiku** — never use Sonnet/Opus just to decide which model to use131- **Keep classifier prompt tight** — the output must be parseable JSON, no fluff132- **Add a fallback** — if JSON parsing fails, default to `medium` (Sonnet)133- **Log routing decisions** — track which tasks land where; use this to tune thresholds over time134- **Never route user-facing trust-critical tasks to Haiku** — legal, medical, financial decisions should default to medium/complex135136---137138## Edge Cases to Handle139140| Scenario | Recommended Handling |141|---------------------------------|-----------------------------------------------|142| Classifier returns invalid JSON | Default to `medium`, log the failure |143| API error on selected model | Retry once, then fall back to Sonnet |144| Very long prompts (>4k tokens) | Override to `medium` or `complex` regardless |145| User override requested | Honor it — expose a `forceModel` param |146147---148149## Testing This Skill150151Run these prompts and verify correct routing:152153**Should → Haiku (simple)**154- "What is the capital of France?"155- "Translate 'good morning' to Spanish"156- "Format this list alphabetically: banana, apple, cherry"157158**Should → Sonnet (medium)**159- "Write a Python script to parse a CSV and compute weekly averages"160- "Explain the tradeoffs between REST and GraphQL APIs"161- "Draft a 3-paragraph product update for our stakeholders"162163**Should → Opus (complex)**164- "Design a multi-tenant SaaS architecture for a fintech platform handling PII"165- "Synthesize these 5 research papers and identify contradictions"166- "Debug why our distributed system has intermittent data inconsistency under load"