← Back to blog

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.

410 Gone — Model Retired

The most common error after June 15. Claude 4 Opus and Sonnet 4 have been permanently removed from Anthropic's infrastructure.

Root Cause

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"
  }
}
Fix

Change the model name in your code:

Retired ModelReplace WithPrice Change
claude-4-opusclaude-opus-4-8$15/$75 → $5/$25 (67% cheaper)
claude-sonnet-4claude-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" }]
});
400 Bad Request — Invalid Model Name

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"
  }
}
Fix

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
400 Bad Request — Invalid Parameters

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"
  }
}
Fix

Check the max output tokens for your new model:

ModelMax Output TokensMax Input Tokens
claude-opus-4-832,7681,000,000
claude-sonnet-4-664,0001,000,000
claude-haiku-4-58,192200,000
400 Bad Request — Context Length Exceeded

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"
  }
}
Fix
  1. Truncate your input or summarize long documents
  2. Use max_tokens to limit output, freeing input space
  3. Switch to a model with a larger context window if needed
401 Unauthorized — Authentication Failed

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"
  }
}
Fix
  1. Check ANTHROPIC_API_KEY environment variable is set
  2. Ensure you're using the x-api-key header (not Authorization: Bearer)
  3. 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" \
403 Forbidden — No Access to Model

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'"
  }
}
Fix
  1. Check your Anthropic plan — some models require higher tiers
  2. Verify organization permissions in the Anthropic Console
  3. Contact Anthropic support if you believe you should have access
404 Not Found — Endpoint Not Found

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"
  }
}
Fix

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
429 Too Many Requests — Rate Limit Exceeded

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."
  }
}
Fix
  1. Add retry logic with exponential backoff
  2. Check your rate limits in the Anthropic Console
  3. 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
500 Internal Server Error

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"
  }
}
Fix
  1. Retry after 30-60 seconds
  2. Check status.anthropic.com for incidents
  3. If persistent, switch to a fallback model
529 Overloaded — API at Capacity

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"
  }
}
Fix
  1. Retry with exponential backoff (start at 5 seconds)
  2. Implement a fallback model (e.g., GPT-5 or Gemini)
  3. Avoid peak migration hours if possible
TIMEOUT Request Timeout — No Response

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
Fix
  1. Increase your timeout (default is 600s in Python, 60s in Node)
  2. Reduce input length
  3. 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
STREAM Streaming Errors

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
Fix
  1. Implement stream reconnection logic
  2. Handle partial responses gracefully
  3. Use max_retries parameter 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 CodeError TypeCommon CauseFix
410GoneModel retired (June 15)Change model name to claude-opus-4-8
400Bad RequestInvalid model or parametersCheck model name and parameter limits
401UnauthorizedInvalid API keyCheck x-api-key header and env var
403ForbiddenNo access to modelCheck plan tier and permissions
404Not FoundWrong endpoint URLUse /v1/messages
429Rate LimitToo many requestsAdd retry with backoff
500Server ErrorAnthropic infrastructure issueRetry after 30-60s
529OverloadedAPI at capacityRetry 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:

Complete Model Name Mapping

Retired ModelReplacementPrice (Input/Output per 1M)Context Window
claude-4-opusclaude-opus-4-8$5 / $251,000,000
claude-sonnet-4claude-sonnet-4-6$3 / $151,000,000
claude-haiku-3-5claude-haiku-4-5$0.80 / $4200,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

📚 Bookmark this page. You'll need it when your code breaks after June 15. Or better yet — migrate now and avoid the errors entirely.