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

Claude Code
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"..."}}

Match the message

Message containsCauseFix
model / not found / invalid modelANTHROPIC_MODEL or /model points at a model ID that is not availablePick a model from /model or the models page
prompt is too long / contextThe conversation exceeds the model's context windowRun /compact, or /clear and start fresh
max_tokensAn output-token override is too high for the modelRemove CLAUDE_CODE_MAX_OUTPUT_TOKENS or lower it
Not found / 404 instead of 400Base URL ends in /v1Use https://api.aicodewith.ai exactly
image / fileAn attachment the model can't takeResize or drop the attachment

Step-by-step fix

  1. 1. Read the message

    The text after invalid_request_error names the problem. Match it in the table above.

  2. 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. 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).

Model status and pricesContact supportDocs

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.