The error, verbatim
Jump to the fix ↓Prompt is too long
# in the debug log:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long: 326082 tokens > 200000 maximum"}}
# the same oversized request on a long-context model:
Usage credits are required for long context requests.
Tested on
- Claude Code
- 2.1.138
- Models
- default (long context) and claude-haiku-4-5
- OS
- Windows 11 Pro
Contents
“Prompt is too long” means one request to the model was bigger than the model accepts. In Claude Code, that request isn’t only what you typed: it’s the system prompt, your CLAUDE.md files, the conversation so far and any tool output, all sent together. The fix is to find which of those got big.
Find the cause first
Run one request with a debug log:
claude -p "hi" --debug-file debug.txtSearch debug.txt for API error. The real API message has the numbers:
API error (attempt 1/11): 400 {"type":"error","error":{"type":"invalid_request_error",
"message":"prompt is too long: 326082 tokens > 200000 maximum"}}If a tiny prompt like hi is already too long, the problem is in what Claude Code sends before your message, and that’s almost always CLAUDE.md.
1. A big CLAUDE.md breaks every message
Claude Code loads CLAUDE.md into every request. I put 1.3 MB of text in a project’s CLAUDE.md and asked for nothing more than reply with just: ok:
| Model | Result |
|---|---|
claude-haiku-4-5 |
Prompt is too long (API: 326082 tokens > 200000 maximum) |
| the default model | Usage credits are required for long context requests. |
Same file, same one-line prompt, two different errors. The second appears on models that accept long context: the request is too big for the normal limit, and long-context requests need usage credits on a Claude subscription. On a model without long context, the request simply fails.
This is the trap: Claude Code guards files it reads during a task, and that guard doesn’t apply to CLAUDE.md. When I asked it about the same 1.2 MB file with @docs/reference.txt, it refused to load it whole:
File content (1.2MB) exceeds maximum allowed size (256KB). Use offset and limit parameters
to read specific portions of the file, or search for specific content instead
and read it in parts instead. As CLAUDE.md, the same content went into every request unchecked.
Keep CLAUDE.md to instructions. Move reference material (logs, specs, data dumps, long docs) into normal files, and tell Claude where they are:
# Project notes
Long reference material lives in docs/reference.txt. Read it only when a task needs it.2. Asking for credits instead: “Usage credits are required for long context requests”
That’s the same problem on a long-context model, as the table above shows. You have two ways out:
- Make the request smaller (section 1, or start a fresh session). Nothing else changes.
- Allow it: add usage credits to your account, if you really need that much context. The error’s own details said
can_user_purchase_credits: trueon my account.
3. A huge paste is usually handled for you
Piping 1.3 MB of text into claude -p did not fail. Claude Code hit the same long-context 429 on the first attempt, then saved the input to a file and read it in parts, and answered. That cost time (78 seconds here) and usage, but no error. If a paste does fail, the same rule applies: put it in a file and point Claude at it.
4. A long conversation
The conversation counts too. Claude Code compacts it automatically as it fills up, and /compact does it on demand. When even that fails with “Prompt is too long”, the session is past saving: start a new one with /clear and carry over only what you need. I didn’t reproduce this case, because filling 200,000 tokens of real conversation would burn a lot of usage for a known answer.
“Input is too long for requested model”?
That’s the same limit, worded by a different service. The string isn’t in Claude Code 2.1.138 at all. Of the GitHub issues that quote it, most involve Amazon Bedrock, where the cloud provider’s API words the rejection its own way. I couldn’t test Bedrock, but the cause is the same, a request bigger than the model’s context, so the same checks apply.
What didn’t work
How this was tested
Claude Code 2.1.138 on Windows 11, signed in with a Claude subscription, run with claude -p and --debug-file. The oversized content was 1.3 MB of generated text (about 326,000 tokens), used once each as CLAUDE.md, as an appended system prompt, as piped input and as an @-mentioned file, on the default model and on claude-haiku-4-5. Requests over the limit are rejected before any work is done; the piped-input run did complete and used normal usage. Error text is copied from the output and debug logs.
— N.K., end of entry No.041