Anthropic API 400 "prompt is too long: N tokens > 200000 maximum" in Claude Code: causes and fixes
Anthropic's docs are exact about this one: if the input alone already exceeds the model's context window, the API returns a 400 invalid_request_error ("prompt is too long") on every model. The number after the colon is your input; the number after the greater-than sign is the window the API applied. What surprises people is which window that is. Claude Code's sub-agents run on a 200K model even when your main session is on a 1M one, and inherit every MCP tool definition you have configured; one user counted 209K tokens of tool schemas before a single prompt. And clients that do not send the 1M header get 200K on models that could do five times that.
Last verified September 21, 2026 against Anthropic docs: context windows, anthropics/claude-code #37793: sub-agents fail with prompt is too long when the user has many MCP servers, anomalyco/opencode #26005: 1M tokens for Opus 4.6, GitHub: 607 issues with the message since January 2026 · 5 min read
| Provider | Anthropic API, in Claude Code, opencode, the SDKs and every tool built on them |
| HTTP status | 400 Bad Request, type invalid_request_error |
| Message | prompt is too long: 209117 tokens > 200000 maximum, with your numbers |
| Cause | The input alone, before any output, exceeds the model's context window. Anthropic: 200K on older models, 1M on the current Opus, Sonnet and 5-series models |
| How common | 607 GitHub issues since January 2026; the sub-agent thread has 26 upvotes and the "GitHub issue prompt too long" thread 38 |
| Can you wait it out? | No. The same input will be too long tomorrow |
- Sub-agents failing instantly with 0 tool uses: too many MCP servers at user level. Trim them or scope them per project; the tool schemas alone are the prompt.
- Long session:
/compact, or a fresh session with a summary. Auto-compaction should have caught it; if it did not, that is a Claude Code bug worth a report. - One huge input: split it, or send it to a model whose window is 1M by default (fix 3).
- "> 200000" on a 1M-capable Claude model: your client is not enabling 1M. Turn it on there.
What it looks like
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long: 209117 tokens > 200000 maximum"},"request_id":"req_011CZ..."}
Prompt is too long (Claude Code's short form)Read both numbers. If the second is 200000 and you believe you are on a 1M model, the request went out without the 1M context flag, or to a model that does not have it: Claude Code sends sub-agent work to a smaller model than the main session.
Where the tokens come from
| Where it comes from | What fills the window | Fix |
|---|---|---|
| Sub-agents (Explore, Plan, general-purpose) fail at once with 0 tool uses | They inherit every MCP tool schema from the parent. 34 servers with about 566 tools came to 209K tokens before the first prompt (#37793, 26 upvotes) | Fewer MCP servers at user level; move rarely used ones to project scope. The requested fix, deferred tool loading for sub-agents, is open |
| A long session on a 200K model | Conversation plus tool output; auto-compaction did not run in time | /compact, or start a new session with a summary |
| A single huge input: a GitHub issue thread, a big file, a paste | The input alone exceeds the window | Split it, or use a 1M-window model |
| An opencode or SDK client on a 1M-capable Claude model | The client never sends the 1M beta header, so the API applies 200K (opencode #26005, 25 upvotes) | Enable 1M in the client, or use a model whose window is 1M by default |
Fix 1: fewer tool definitions
Every MCP tool is sent as a full JSON schema on every request, to the main session and to each sub-agent. Dozens of servers means tens of thousands of tokens before you type. Keep user-level MCP servers to the ones every project needs and add the rest per project in .mcp.json. Claude Code's /context shows how much of the window tool definitions occupy.
Fix 2: compaction and splitting
For a long session, /compact summarises the history and frees the window. For one large input, split it: paste a GitHub issue thread in parts, or point Claude Code at the file and let it read sections. If the error appears mid-task without auto-compaction having run, the thread #37793 and its duplicates are where that is tracked.
Fix 3: a model with a 1M window by default
DeepSeek V4 Flash, V4.1 Flash and V4 Pro, and GLM 5.3 and 5.3 Flash, have a 1,048,576-token window with nothing to enable. Claude Code uses them through our Anthropic-format endpoint; the [1m] suffix tells Claude Code the window size so it does not compact at 200K:
export ANTHROPIC_BASE_URL="https://api.inferenceapis.com"
export ANTHROPIC_AUTH_TOKEN="your-inferenceapis-key"
export ANTHROPIC_MODEL="zai-org/GLM-5.3[1m]" # [1m] tells Claude Code the window is 1M, so it stops compacting at 200K
export ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-ai/DeepSeek-V4.1-Flash[1m]"
claude| Model | Context window | Per 1M tokens in / out |
|---|---|---|
deepseek-ai/DeepSeek-V4-Flash | 1,048,576 | $0.19 / $0.38 |
deepseek-ai/DeepSeek-V4.1-Flash | 1,048,576 | $0.40 / $1.60 |
deepseek-ai/DeepSeek-V4-Pro | 1,048,576 | $1.60 / $3.40 |
zai-org/GLM-5.3, zai-org/GLM-5.3-Flash | 1,048,575 | $1.82 / $5.72 · $0.20 / $0.66 |
MiniMaxAI/MiniMax-M3 | 524,288 | $0.39 / $1.56 |
moonshotai/Kimi-K2.7-Code, Qwen/Qwen3-VL-235B-A22B-Instruct | 262,144 | $0.89 / $4.42 · $0.26 / $1.15 |
openai/gpt-oss-120b, meta-llama/Llama-3.3-70B-Instruct-Turbo | 131,072 | $0.20 / $0.80 · $0.20 / $0.50 |
Sub-agents follow ANTHROPIC_DEFAULT_HAIKU_MODEL and the other defaults, so the 209K of tool schemas that broke a 200K sub-agent fits with room to spare. Verified on September 21, 2026 with Claude Code 2.1.278: a fix-the-tests task completed on GLM 5.3 in 6 turns and 3 seconds. The Claude Code guide has per-project setup and results for eight models. A very large prompt is billed as input tokens; at $0.19 per million on DeepSeek V4 Flash, a 500K-token prompt is about ten cents.
Frequently asked questions
Which Claude models have a 1M window?
Anthropic's docs list the current Opus, Sonnet and Claude 5-series models at 1M, with 128K maximum output; older ones such as Sonnet 4.5 have 200K. Whether a given request gets 1M also depends on the client sending the right flag.
Why did my sub-agent fail when the main session was fine?
Sub-agents run on a different, smaller-window model by default and receive the full tool list. The main session on a 1M model fits 209K of schemas; the sub-agent on a 200K model does not.
Does max_tokens count?
For this error, no: it fires when the input alone is over the window. On Claude 4.5 and newer, input plus max_tokens over the window is accepted and generation stops at the limit. On OpenAI-format endpoints, including ours, max_tokens does count; see the context_length_exceeded entry.
Where Inference APIs fits
Fix 3 is what we sell: DeepSeek V4 and GLM 5.3 models with a 1,048,576-token window by default, served on the Anthropic Messages API so Claude Code uses them unchanged, and on the OpenAI format for everything else. Not Claude, but a five-times larger window with nothing to enable. US GPUs, zero retention, prepaid; a new account starts with $1 of credit.
Something changed or wrong? Tell us and we will re-verify the entry.
