model parameter: which Claude to use
Why this matters
Picking the wrong Claude model wastes money on overcapacity or produces worse results on complex tasks. Claude Opus handles reasoning, Sonnet balances speed and capability, Haiku is cheap for simple tasks: you need to match the task, not default to the most expensive option.
Explanation
The model parameter tells the Anthropic API which Claude version to execute your request against. You pass it as a string like 'claude-opus-4-6' in the messages.create() call. Anthropic maintains three tier: Opus (most capable, slowest), Sonnet (balanced), and Haiku (fastest, cheapest). Under the hood, each model is a different neural network trained with different data and optimization targets: Opus was trained to solve harder problems, Haiku was optimized for latency and cost.
The model parameter is required: there is no default. If you omit it, the API returns an error. Current valid models as of April 2026 are 'claude-opus-4-6', 'claude-sonnet-4-6', and 'claude-haiku-4-6'. The version number (4-6) indicates the training generation. Older models like 'claude-3-opus' are still available but no longer recommended.
Use Opus for math, coding, complex reasoning, and multi-step research. Use Sonnet for balanced workloads: customer support, content generation, Q&A. Use Haiku for classification, simple summarization, and high-volume tasks where latency is critical. Pricing scales roughly 3x from Haiku to Sonnet to Opus per token, but Opus solves harder problems in fewer tokens.
Request code
import os
from anthropic import Anthropic
api_key = os.getenv('ANTHROPIC_API_KEY')
if not api_key:
raise ValueError('ANTHROPIC_API_KEY environment variable not set')
client = Anthropic(api_key=api_key)
message = client.messages.create(
model='claude-opus-4-6',
max_tokens=1024,
messages=[
{
'role': 'user',
'content': 'Prove that the square root of 2 is irrational.'
}
]
)
print(message.content[0].text) Authentication
Set your API key as an environment variable before instantiating the client: export ANTHROPIC_API_KEY='sk-ant-...' (Linux/Mac) or $env:ANTHROPIC_API_KEY='sk-ant-...' (PowerShell). The Anthropic SDK reads this automatically when you create Anthropic(): no explicit passing required. If the key is missing, you'll get AuthenticationError at request time.
Response shape
| Field | Description |
|---|---|
id | msg_abc123...: unique request ID |
type | message |
role | assistant |
content | [object Object] |
model | claude-opus-4-6: echoes back the model you requested |
stop_reason | end_turn or max_tokens |
stop_sequence | |
usage | [object Object] |
Field guide
model Always equals the model parameter you sent: useful to log which variant actually ran if you're A/B testing.
usage The hidden field. Input tokens are cheap, output tokens cost 3x more. If you're optimizing cost, watch this: Opus may produce shorter answers (fewer output tokens) on hard problems, making it cheaper than Sonnet despite higher per-token pricing.
Setup trap
The ANTHROPIC_API_KEY environment variable must be set before you run the Python script or import the Anthropic module in your REPL. If you set it after importing, the client will fail silently during instantiation with a cryptic error. In a notebook, set the key in the first cell before any Anthropic imports. In a script, export it in your shell or .env loader before running python.
Cost
As of April 2026, Opus costs ~$15 per 1M input tokens and ~$45 per 1M output tokens. Haiku costs ~$0.80 and ~$4. On a 10k-request batch with 500 output tokens each, Opus = ~$225, Haiku = ~$20. For high-volume applications (chatbots, bulk processing), using Haiku instead of Opus can save 10x+ monthly spend. Always prototype on Haiku, then upgrade to Sonnet/Opus only if output quality requires it.
Rate limits
Opus has stricter rate limits than Haiku: typically 40 requests per minute vs. 100+ for Haiku on free tier. If you're doing batch processing, use Haiku or implement exponential backoff. Rate limit headers are returned in the response; check <code>response.headers['anthropic-ratelimit-requests-remaining']</code> to avoid hitting the wall.
Common gotcha
Developers often hard-code 'claude-3-opus' or 'claude-2.1' because that's what worked in their tutorial from 2024. The API will reject these with Invalid model: claude-3-opus. The current models as of April 2026 are the -4-6 versions. Check your error logs for 'Invalid model' and update to the latest generation.
Error recovery
AuthenticationErrorInvalidRequestError with 'Invalid model'OverLoadedErrorRateLimitErrorExperienced dev note
The real win: use the usage field in the response to dynamically pick your next model. If a task used more Haiku output tokens than expected, route the next one to Sonnet. If Sonnet solved it in < 100 tokens, downgrade future similar tasks to Haiku. This feedback loop cuts costs 30-50% over time without sacrificing quality. Build a simple metrics collector that bins requests by model and output token count: you'll find patterns that let you automate model selection.
Check your understanding
You have a batch of 1000 customer support tickets. Each ticket is a short question (100 tokens). You want to classify each into 5 categories with high accuracy. Would you use Opus, Sonnet, or Haiku, and why? What would you measure to decide if your choice was right?
Show answer hint
Haiku is sufficient for classification on simple tasks: Opus is overkill. Measure accuracy and cost-per-ticket. If Haiku hits 95%+ accuracy, you've saved 10x on compute. If it drops to 80%, move to Sonnet. The key is not to assume the most expensive model is 'safer': measure actual performance.
-4-6 suffix indicates the fourth generation, sixth revision (April 2026 release). If you see code using claude-3-opus or claude-2, it's from 2024 or earlier. The API will reject these with 'Invalid model'. Always check the official Anthropic models list (console.anthropic.com) before deploying: model versions are updated quarterly.