beginner10 min read· Module 2, Lesson 4
🎯Choosing the Right Model
When to use Opus vs Sonnet vs Haiku — cost, speed, and quality trade-offs
Choosing the Right Model
One of the most important decisions when building AI applications is choosing the right model. Each Claude model has different strengths, speeds, and costs.
Available Claude Models
Claude Opus 4 — The Most Powerful
- Best for: Highly complex tasks, deep analysis, advanced coding, research
- Speed: Slowest
- Cost: Highest ($15/$75 per million tokens)
- Context window: 200K tokens
- When to use:
- Analyzing complex, multi-document tasks
- Writing complex architectural code
- Tasks requiring multi-step reasoning
- Academic research and analysis
Claude Sonnet 4 — The Perfect Balance
- Best for: Most everyday tasks, coding, writing, analysis
- Speed: Fast
- Cost: Medium ($3/$15 per million tokens)
- Context window: 200K tokens
- When to use:
- Building chatbots and interactive apps
- Writing and reviewing code
- Summarizing documents
- Most production use cases
Claude Haiku 3.5 — Fastest and Cheapest
- Best for: Simple, fast tasks, high volume
- Speed: Fastest
- Cost: Lowest ($0.80/$4.00 per million tokens)
- Context window: 200K tokens
- When to use:
- Text classification
- Simple Q&A
- Structured data extraction
- High-volume, budget-conscious applications
Comprehensive Comparison Table
| Criteria | Opus 4 | Sonnet 4 | Haiku 3.5 |
|---|---|---|---|
| Quality | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ |
| Speed | ⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| Cost | $$$$$ | $$$ | $ |
| Coding | Excellent | Excellent | Good |
| Reasoning | Best | Very Good | Basic |
| Writing | Best | Excellent | Good |
| Latency | 10-30s | 3-10s | 1-3s |
Decision Tree
Use this flowchart to choose your model:
Is the task complex and requires deep reasoning?
├── Yes → Is budget flexible?
│ ├── Yes → Use Opus 4
│ └── No → Use Sonnet 4 with extended thinking
└── No → Do you need high speed or high volume?
├── Yes → Use Haiku 3.5
└── No → Use Sonnet 4
Practical Cost Comparison
Same task (summarizing a 2,000-word article) on each model:
| Model | Input Tokens | Output Tokens | Cost | Latency |
|---|---|---|---|---|
| Opus 4 | ~3,000 | ~500 | $0.0825 | ~15s |
| Sonnet 4 | ~3,000 | ~500 | $0.0165 | ~5s |
| Haiku 3.5 | ~3,000 | ~500 | $0.0044 | ~2s |
Opus is 19x more expensive than Haiku for the same task!
Use Case Examples
Use Opus when:
- Building an automated code review system that needs deep architectural understanding
- Analyzing complex legal contracts
- High-quality research writing
Use Sonnet when:
- Building a customer support chatbot
- Translating documents
- Building productivity tools
Use Haiku when:
- Classifying thousands of messages (positive/negative/neutral)
- Extracting data from invoices
- Building a simple auto-reply system
Switching Models in Code
// Super easy — just change the model name
const model = "claude-sonnet-4-20250514"; // or claude-opus-4-20250514 or claude-haiku-3-5-20241022
const response = await client.messages.create({
model: model,
max_tokens: 1024,
messages: [{ role: "user", content: "Your question here" }],
});Python Example
import anthropic
client = anthropic.Anthropic()
# Easy to switch between models
model = "claude-sonnet-4-20250514"
response = client.messages.create(
model=model,
max_tokens=1024,
messages=[{"role": "user", "content": "Your question here"}],
)
print(response.content[0].text)Pro Tip: Model Routing
Many successful applications use different models for different tasks:
async function smartRoute(task, complexity) {
let model;
if (complexity === "high") {
model = "claude-opus-4-20250514";
} else if (complexity === "medium") {
model = "claude-sonnet-4-20250514";
} else {
model = "claude-haiku-3-5-20241022";
}
return await client.messages.create({
model,
max_tokens: 2048,
messages: [{ role: "user", content: task }],
});
}Advanced: A/B Testing Models
async function abTestModels(prompt) {
const models = [
"claude-opus-4-20250514",
"claude-sonnet-4-20250514",
"claude-haiku-3-5-20241022",
];
const results = await Promise.all(
models.map(async (model) => {
const start = Date.now();
const response = await client.messages.create({
model,
max_tokens: 1024,
messages: [{ role: "user", content: prompt }],
});
const latency = Date.now() - start;
return {
model,
latency,
inputTokens: response.usage.input_tokens,
outputTokens: response.usage.output_tokens,
response: response.content[0].text,
};
})
);
results.forEach((r) => {
console.log(`Model: ${r.model}`);
console.log(`Latency: ${r.latency}ms`);
console.log(`Tokens: ${r.inputTokens} in, ${r.outputTokens} out`);
console.log("---");
});
return results;
}Quick Summary
- Opus 4: Best quality, slowest, most expensive — for critical tasks only
- Sonnet 4: Perfect balance — the default choice for most applications
- Haiku 3.5: Fastest and cheapest — for simple tasks and high volume
- Start with Sonnet, upgrade to Opus only when needed, downgrade to Haiku when possible
Next: We'll learn how to use Claude Code in your Git workflow.