Claude 4 API Error Codes Complete Reference
Every Claude 4 API error code explained with exact JSON responses, root causes, and specific fixes. Bookmark this page — you'll need it when your code breaks after June 15.
🚨 Claude 4 was retired on June 15, 2026. All API calls to claude-4-opus and claude-sonnet-4 now return errors. Fix: change the model name to claude-opus-4-8 or claude-sonnet-4-6.
⚡ Jump to Error Code
The most common error after June 15. Claude 4 Opus and Sonnet 4 have been permanently removed from Anthropic's infrastructure.
The model ID claude-4-opus or claude-sonnet-4 no longer exists. Anthropic retired these models on June 15, 2026.
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "model 'claude-4-opus' has been retired"
}
}
Change the model name in your code:
| Retired Model | Replace With | Price Change |
|---|---|---|
claude-4-opus | claude-opus-4-8 | $15/$75 → $5/$25 (67% cheaper) |
claude-sonnet-4 | claude-sonnet-4-6 | $3/$15 → $3/$15 (same price, 5x context) |
# Python — change one line response = client.messages.create( model="claude-opus-4-8", # was "claude-4-opus" messages=[{"role": "user", "content": "Hello"}] ) # Node.js — change one line const response = await client.messages.create({ model: "claude-opus-4-8", // was "claude-4-opus" messages: [{ role: "user", content: "Hello" }] });
Some SDK versions validate model names client-side before sending the request, producing a different error format.
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Invalid model name: claude-4-opus"
}
}
Same as 410 — update the model name. Also update your SDK to the latest version:
# Python pip install --upgrade anthropic # Node.js npm update @anthropic-ai/sdk
This error occurs when you send parameters that the new model doesn't support, or when you mix old and new parameter formats.
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens: 1000000 exceeds model maximum of 8192"
}
}
Check the max output tokens for your new model:
| Model | Max Output Tokens | Max Input Tokens |
|---|---|---|
| claude-opus-4-8 | 32,768 | 1,000,000 |
| claude-sonnet-4-6 | 64,000 | 1,000,000 |
| claude-haiku-4-5 | 8,192 | 200,000 |
Your input tokens exceed the model's context window. The new models have larger context windows (1M tokens), so this is less common — but still possible with very large inputs.
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "input length exceeds maximum context length of 1000000 tokens"
}
}
- Truncate your input or summarize long documents
- Use
max_tokensto limit output, freeing input space - Switch to a model with a larger context window if needed
Your API key is missing, invalid, or being passed in the wrong format. This is usually not related to the model migration — it's a separate authentication issue.
{
"type": "error",
"error": {
"type": "authentication_error",
"message": "invalid x-api-key"
}
}
- Check
ANTHROPIC_API_KEYenvironment variable is set - Ensure you're using the
x-api-keyheader (notAuthorization: Bearer) - Generate a new key from console.anthropic.com
# Correct header format curl https://api.anthropic.com/v1/messages \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -d '{"model": "claude-opus-4-8", "messages": [...]}' # ❌ WRONG — this causes 401 curl https://api.anthropic.com/v1/messages \ -H "Authorization: Bearer $ANTHROPIC_API_KEY" \
Your API key is valid, but you don't have access to the requested model. This can happen with restricted models or organization-level permissions.
{
"type": "error",
"error": {
"type": "permission_error",
"message": "you do not have access to model 'claude-opus-4-8'"
}
}
- Check your Anthropic plan — some models require higher tiers
- Verify organization permissions in the Anthropic Console
- Contact Anthropic support if you believe you should have access
You're calling the wrong API endpoint. This usually happens when using an outdated base URL or SDK version.
{
"type": "error",
"error": {
"type": "not_found_error",
"message": "endpoint not found"
}
}
Verify your base URL:
# Correct base URL https://api.anthropic.com/v1/messages # ❌ Common mistakes https://api.anthropic.com/v1/chat/completions # OpenAI format https://api.anthropic.com/messages # Missing /v1
You've exceeded your rate limit. Each model has its own rate limit bucket — migrating to a new model means a fresh bucket.
{
"type": "error",
"error": {
"type": "rate_limit_error",
"message": "Rate limit exceeded. Please retry after 60 seconds."
}
}
- Add retry logic with exponential backoff
- Check your rate limits in the Anthropic Console
- Request a rate limit increase if needed
# Python — retry with backoff import time def call_with_retry(fn, max_retries=3): for i in range(max_retries): try: return fn() except anthropic.RateLimitError: if i == max_retries - 1: raise time.sleep(2 ** i) # 1s, 2s, 4s
Anthropic's servers encountered an error. This is not your fault — it's an Anthropic infrastructure issue.
{
"type": "error",
"error": {
"type": "api_error",
"message": "internal server error"
}
}
- Retry after 30-60 seconds
- Check status.anthropic.com for incidents
- If persistent, switch to a fallback model
Anthropic's API is at capacity. Common during high-traffic periods (like right after the Claude 4 shutdown when everyone migrates at once).
{
"type": "error",
"error": {
"type": "overloaded_error",
"message": "API is temporarily overloaded"
}
}
- Retry with exponential backoff (start at 5 seconds)
- Implement a fallback model (e.g., GPT-5 or Gemini)
- Avoid peak migration hours if possible
The API didn't respond within your timeout window. Common with very long prompts or during high-load periods.
# Python SDK error anthropic.APITimeoutError: Request timed out # Node.js SDK error Anthropic.APITimeoutError: Request timed out after 60000ms
- Increase your timeout (default is 600s in Python, 60s in Node)
- Reduce input length
- Use streaming for long outputs
# Python — increase timeout client = anthropic.Anthropic(timeout=300.0) # 5 minutes # Node.js — increase timeout const client = new Anthropic({ timeout: 300000 }); # 5 minutes
Errors that occur during streaming responses. The connection may drop mid-stream, or you may receive incomplete JSON.
# Common streaming errors anthropic.APIError: stream closed unexpectedly anthropic.APIError: incomplete JSON at position 0 # Node.js Anthropic.APIError: stream closed unexpectedly
- Implement stream reconnection logic
- Handle partial responses gracefully
- Use
max_retriesparameter for automatic retries
# Python — enable auto-retries client = anthropic.Anthropic(max_retries=3) # Node.js — enable auto-retries const client = new Anthropic({ maxRetries: 3 });
Quick Reference: All Error Codes
| HTTP Code | Error Type | Common Cause | Fix |
|---|---|---|---|
410 | Gone | Model retired (June 15) | Change model name to claude-opus-4-8 |
400 | Bad Request | Invalid model or parameters | Check model name and parameter limits |
401 | Unauthorized | Invalid API key | Check x-api-key header and env var |
403 | Forbidden | No access to model | Check plan tier and permissions |
404 | Not Found | Wrong endpoint URL | Use /v1/messages |
429 | Rate Limit | Too many requests | Add retry with backoff |
500 | Server Error | Anthropic infrastructure issue | Retry after 30-60s |
529 | Overloaded | API at capacity | Retry with exponential backoff |
Diagnostic: Find All Deprecated References
Run these commands to find every reference to deprecated Claude 4 models in your codebase:
# Find all Claude 4 Opus references grep -r "claude-4-opus" . --include="*.js" --include="*.py" --include="*.ts" \ --include="*.json" --include="*.yaml" --include="*.yml" --include="*.env" # Find all Claude Sonnet 4 references grep -r "claude-sonnet-4" . --include="*.js" --include="*.py" --include="*.ts" \ --include="*.json" --include="*.yaml" --include="*.yml" --include="*.env" # Find all deprecated model references at once grep -rE "claude-4-(opus|sonnet)" . --include="*.js" --include="*.py" --include="*.ts"
Also check these often-missed locations:
- Environment variables —
.env,.env.local,.env.production - Docker configs —
docker-compose.yml,Dockerfile - CI/CD pipelines — GitHub Actions, Vercel env vars, AWS Parameter Store
- Prompt templates — any file that hardcodes a model name in a string
- Database records — stored model preferences in your database
- Third-party libraries — check if your AI framework has cached model names
Complete Model Name Mapping
| Retired Model | Replacement | Price (Input/Output per 1M) | Context Window |
|---|---|---|---|
claude-4-opus | claude-opus-4-8 | $5 / $25 | 1,000,000 |
claude-sonnet-4 | claude-sonnet-4-6 | $3 / $15 | 1,000,000 |
claude-haiku-3-5 | claude-haiku-4-5 | $0.80 / $4 | 200,000 |
Good news: Migrating doesn't just fix errors — it saves money. Claude Opus 4.8 is 67% cheaper than Claude 4 Opus, with a 5x larger context window. You're not just fixing a bug; you're upgrading.
Calculate Your Migration Savings
See exactly how much you'll save by switching from Claude 4 to the new models or alternatives.
Free Calculator → Compare All Alternatives →Related Resources
- Claude 4 Error? Fix It in 60 Seconds — Quick visual fix guide
- Claude 4 API Errors After June 15 — Detailed error walkthrough
- Claude 4 Migration Hub — Complete migration resource center
- Claude 4 Alternatives Comparison — Side-by-side pricing and features
- Deprecation Calculator — Calculate your exact savings
- Migration Tool — Compare all 42 alternatives
📚 Bookmark this page. You'll need it when your code breaks after June 15. Or better yet — migrate now and avoid the errors entirely.