[BUG] OAuth tokens 500 on Sonnet/Opus via Python SDK on Max 20x plan — 5x plan works fine
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Environment:
- Claude Code v2.1.76
- Python anthropic SDK v0.84.0
- Windows 11, PowerShell 7.5.4
- Started after the 1M context window update
What works:
- Haiku via SDK with 20x OAuth token (200 OK)
- Sonnet/Opus via Claude Code CLI internally on 20x (works fine)
- Sonnet/Opus via SDK with 5x Max plan OAuth token (200 OK)
What Should Happen?
Claude Max 20x plan OAuth tokens return HTTP 500 (Internal Server Error) on all Sonnet and Opus models when called via the Python SDK. The identical OAuth flow on a 5x Max plan works perfectly for the same models.
Environment:
- Claude Code v2.1.76
- Python anthropic SDK v0.84.0
- Windows 11, PowerShell 7.5.4
- Started after the 1M context window update
What works:
- Haiku via SDK with 20x OAuth token (200 OK)
- Sonnet/Opus via Claude Code CLI internally on 20x (works fine)
- Sonnet/Opus via SDK with 5x Max plan OAuth token (200 OK)
What fails:
- Sonnet/Opus via SDK with 20x Max plan OAuth token (500 every time)
Tested with:
- auth_token parameter + anthropic-beta: oauth-2025-04-20 header
- Raw httpx Bearer token calls bypassing SDK entirely
- Multiple model strings: claude-sonnet-4-20250514, claude-sonnet-4-6, claude-opus-4-20250514
- With and without additional beta headers (claude-code-20250219, context-1m-2025-08-07)
- Fresh tokens after claude auth logout/login
All return 500. Auth succeeds (not 401/403) but server crashes during model routing/billing for the 20x tier. This appears to be a 20x plan-specific routing bug introduced with the 1M context update.
Error Messages/Logs
anthropic.InternalServerError: Error code: 500 - {'type': 'error', 'error': {'type': 'api_error', 'message': 'Internal server error'}}
Tested via raw httpx (bypassing SDK):
Status: 500
Response: {"type":"error","error":{"type":"api_error","message":"Internal server error"}}
Steps to Reproduce
- Have a Claude Max 20x plan account authenticated via Claude Code (claude auth login)
- Run this Python script:
import json, anthropic
t = json.load(open(r'C:\Users\<user>\.claude\.credentials.json'))['claudeAiOauth']['accessToken']
c = anthropic.Anthropic(
auth_token=t,
default_headers={"anthropic-beta": "oauth-2025-04-20"}
)
r = c.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=10,
messages=[{"role": "user", "content": "hi"}]
)
print(r.content[0].text)
- Result: 500 Internal Server Error
- Change model to claude-haiku-4-5-20241022 — works fine (200 OK)
- Use the same script with a 5x Max plan OAuth token — Sonnet works fine (200 OK)
- Claude Code CLI itself works on Sonnet/Opus with the same 20x token (claude -p --model sonnet "hi" succeeds)
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.74
Claude Code Version
2.1.76 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
Key finding: The same OAuth flow works perfectly on a 5x Max plan but fails on a 20x Max plan. This proves the issue is tier-specific, not a general OAuth limitation.
Claude Code CLI itself works fine on the 20x plan for Sonnet/Opus (claude -p --model sonnet "hi" succeeds), confirming the OAuth token is valid. Only direct Python SDK calls fail.
The 500 occurs after successful authentication — the server accepts the token but crashes during what appears to be model routing/billing for the 20x tier. This began after the 1M context window update rollout.
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗