Claude Code · Troubleshooting
Claude Code API Error 400 bad request: common causes
A 400 means the API understood who you are but rejected the request itself. The message after invalid_request_error usually says exactly what was wrong; match it against the table below.
Last checked
The error text
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"..."}}Match the message
| Message contains | Cause | Fix |
|---|---|---|
| model / not found / invalid model | ANTHROPIC_MODEL or /model points at a model ID that is not available | Pick a model from /model or the models page |
| prompt is too long / context | The conversation exceeds the model's context window | Run /compact, or /clear and start fresh |
| max_tokens | An output-token override is too high for the model | Remove CLAUDE_CODE_MAX_OUTPUT_TOKENS or lower it |
| Not found / 404 instead of 400 | Base URL ends in /v1 | Use https://api.aicodewith.ai exactly |
| image / file | An attachment the model can't take | Resize or drop the attachment |
Step-by-step fix
1. Read the message
The text after invalid_request_error names the problem. Match it in the table above.
2. Reset model overrides
Remove ANTHROPIC_MODEL and other model overrides from settings.json, restart, and choose a model with /model.
~/.claude/settings.json{ "env": { "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY", "ANTHROPIC_API_KEY": "", "ANTHROPIC_BASE_URL": "https://api.aicodewith.ai" } }3. Shrink the context
Run /compact. If the session is very long, /clear and continue in a fresh one.
Are failed requests charged?
Failed requests (4xx/5xx, timeouts, dropped connections) are not charged — you're only billed for requests that complete successfully. If an upstream failure is automatically retried and succeeds, you're billed once.
Still failing?
- Check the model's page on aicodewith: it shows recent health for each channel.
- Look up the request in your dashboard usage records to see its model, status and cost.
- Email support@aicodewith.com with the time of the error, the model and the error text (never your full API key).
FAQ
What does Claude Code error 400 mean?
The API rejected the request content. The message after invalid_request_error says why: often a wrong model ID or a conversation that is too long.
How do I fix "prompt is too long"?
Run /compact to summarize the session, or /clear and start fresh. Keep CLAUDE.md and pasted logs short.
Does the base URL need /v1?
No. Use https://api.aicodewith.ai; adding /v1 breaks the request path.
Why did it start after I edited settings.json?
A model or token override is the usual cause. Remove overrides, restart, and choose a model with /model.
Which model IDs can I use?
Run /model in Claude Code, or see the models page for every available model and its ID.
Am I charged for failed requests?
Failed requests (4xx/5xx, timeouts, dropped connections) are not charged — you're only billed for requests that complete successfully. If an upstream failure is automatically retried and succeeds, you're billed once.
Ready to try it?
Billing is per token from a prepaid balance. Rate and concurrency limits apply, and you can set daily, monthly or total spend caps on each API key.
Related
Sources
Claude and Claude Code are trademarks of Anthropic PBC. aicodewith is an independent platform and is not affiliated with or endorsed by Anthropic. Error formats are quoted from Claude Code and may change. Checked 2026-10-10.