In this categoryTroubleshooting · 27
- How to Fix an OpenAI 401 'Invalid API Key' ErrorStart
- How to Fix OpenAI 429 Rate Limit Errors With Backoff
- How to Fix Anthropic Claude API 401 Authentication Errors
- How to Fix Google Gemini 'API Key Not Valid' Errors
- How to Fix an API Key That Loads as Undefined
- How to Handle Anthropic 529 'Overloaded' Errors
- How to Fix Rate Limit Errors from an AI API
- How to Fix CORS Errors When Calling an AI API From the Browser
- How to Fix 'Model Not Found' and Deprecated Model Errors
- How to Rotate a Leaked API Key Without Downtime
- How to Fix SSL Certificate Errors When Calling AI APIs
- How to count tokens before sending a prompt to Claude
- How to Fix 'Context Length Exceeded' Token Limit Errors
- How to fix a context length exceeded error in the Claude API
- How to fix a Claude response that gets cut off mid-sentence
- How to reduce Claude hallucinations by grounding answers in your documents
- How to keep a long Claude conversation under the context limit
- How to stop Claude from calling tools when it should not
- How to handle a Claude Fable 5 refusal with a fallback model
- How to choose the right Claude model for cost and quality
- How to cut Claude API costs with prompt caching
- How to halve Claude costs for bulk jobs with the Batch API
- How to cap spend on a Claude agent with a task budget
- How to Debug an MCP Server That Will Not Connect
- How to Ask an Agent to Explain a Bug Before Fixing It
- How to Roll Back a Bad Deploy Quickly
- How to Fix Cursor Not Indexing Your Codebase
How to choose the right Claude model for cost and quality
Match Haiku, Sonnet, Opus, or Fable to your task so you neither overpay nor underpower the job.
Reaching for the most expensive model on every task wastes money, and reaching for the cheapest on a hard task wastes time on bad answers. This guide gives a simple way to pick a Claude model by matching the task to the right tier, then verifying with a quick test.
- A clear description of the task you are automating
- The Anthropic SDK and an API key for a quick test call
- A rough sense of your monthly request volume
Step 1: Learn the current lineup and prices
Prices are per million tokens, input and output. Cheaper models are faster and fine for simple, high volume work. More capable models cost more but handle ambiguity and long agentic tasks.
| Model | Input $/1M | Output $/1M | Best for |
|---|---|---|---|
| claude-haiku-4-5 | 1.00 | 5.00 | Simple, high-volume, latency-sensitive |
| claude-sonnet-4-6 | 3.00 | 15.00 | Balanced speed and intelligence |
| claude-opus-4-8 | 5.00 | 25.00 | Hard reasoning, long agentic work |
| claude-fable-5 | 10.00 | 50.00 | The most demanding reasoning |
Step 2: Classify your task
Sort the job into one bucket. Classification, tagging, short extraction, and simple chat go to Haiku. Most everyday generation, summarization, and tool use go to Sonnet. Multi-step coding, deep research, and tasks where a wrong answer is costly go to Opus. Reserve Fable for the genuinely hardest, long-horizon work where its higher price is justified.
Step 3: Run the same prompt on two tiers
Do not pick from the table alone. Run your real prompt on the cheaper candidate and the next tier up, then compare. If the cheaper one is good enough, you just cut your cost. Default to the cheaper model only when its output passes your bar.
from anthropic import Anthropic
client = Anthropic()
prompt = "Classify this ticket as billing, bug, or feature: 'app crashes on login'"
for model in ["claude-haiku-4-5", "claude-sonnet-4-6"]:
r = client.messages.create(
model=model, max_tokens=64,
messages=[{"role": "user", "content": prompt}],
)
print(model, "->", r.content[0].text)Result: the ticket classifier produced identical labels on Haiku and Sonnet, so it stayed on Haiku at one fifth the input cost. The refactor task was visibly weaker on Sonnet and moved to Opus 4.8, where the diff was correct on the first pass.
Watch related tutorials
23:41
1:42:18
28:14
41:09
9:47
8:23New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.