LLM API Guide

API Error: 400 Input is too long in Claude Code

The conversation no longer fits the model's context window, in Amazon Bedrock's wording. Update to Claude Code v2.1.217 or later, then run /compact to shrink the session.

Summary

  1. Before v2.1.217, Claude Code did not recognize Bedrock's wording, so auto-compact never ran and /compact failed with the same 400.
  2. When a gateway or wrapper rewrites the message, Claude Code cannot tell it is a too-long error; run /compact yourself.
  3. If /compact says Not enough messages to compact, one prompt is too big; run /clear and resend with less pasted text or fewer attachments.
  4. Behind a gateway, set CLAUDE_CODE_AUTO_COMPACT_WINDOW to the gateway's limit so compaction starts before the 400.
On this page

Update Claude Code, then compact

Amazon Bedrock reports a full context window as Input is too long for requested model., and shorter forms of the same text show up as API Error: 400 Input is too long. Claude Code's own name for the condition is Prompt is too long. According to the Claude Code error reference, versions before v2.1.217 did not recognize the Bedrock wording, so auto-compact never triggered and /compact failed with the same error. That is the message people see as:

text
Error during compaction: API Error: 400 Input is too long.

Check your version and update:

bash
claude --version
claude update

On the stable release channel, claude update stops at the newest stable release, which can lag the latest one. Once you are on v2.1.217 or later, run /compact in the stuck session. Claude Code then treats Bedrock's message like Prompt is too long and compacts on its own when the window fills.

Free room in the context window

If the error comes back after compacting, look at what fills each request:

  • Run /context for a breakdown of system prompt, tools, memory files and messages.
  • Turn off MCP servers you are not using with /mcp disable <name>; each one adds its tool definitions to every request.
  • Trim a long CLAUDE.md, or move instructions into path-scoped rules that load only when relevant.
  • Auto-compact is on by default. If you switched it off in /config or with DISABLE_AUTO_COMPACT, turn it back on, or run /compact yourself before the window fills.

When /compact fails too

/compact can fail for reasons the error reference spells out:

  • Prompt is too long · automatic compaction failed: <the underlying error> names a second problem, such as an unavailable model or an authentication failure. Fix that one first; /compact keeps failing until you do.
  • Not enough messages to compact. means the conversation is a single exchange, so there is nothing earlier to condense. Run /clear and send the request again with less pasted text, smaller attachments, fewer tools or a shorter memory file.
  • If the error appeared right after you stopped Claude while it was compacting, the conversation is unchanged and still too large. Run /compact and send your message again; v2.1.304 and later no longer end the turn this way.

Images and attachments hit a different limit. Request too large (max 32MB) is about the raw request size before tokenization; press Esc twice to step back past the turn that added the large content, or run /compact, which drops accumulated images and attachments.

Through a gateway or a wrapper

Some setups pass the error through another layer first, as in failed to call llm service: invoking wrapper: http response error statuscode: 400, validationexception: input is too long. Claude Code only compacts automatically on too-long errors it recognizes. Anthropic's gateway troubleshooting table says that when a gateway enforces a smaller context than the model's own and rewrites the error in its own words, Claude Code does not compact and retry by itself. Recover with /compact, then stop it from recurring:

bash
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=<gateway-limit-in-tokens>

Replace the placeholder with the gateway's limit. Claude Code clamps it to at least 100,000 tokens and at most the model's context window, so for a gateway limit below 100,000, /compact stays the recovery. Also keep CLAUDE_CODE_MAX_OUTPUT_TOKENS below the gateway model's output limit.

A related trap: when Claude Code does not recognize the model ID your gateway uses, it assumes a 200K window. If the real window is larger, give Claude Code the real size as the model configuration page describes, with a modelOverrides entry, a [1m] suffix for a 1M model, or CLAUDE_CODE_MAX_CONTEXT_TOKENS. For the other 400 messages Claude Code prints, see our Claude Code API Error 400 page. If you run Claude on a cloud provider, Claude models on Google Cloud covers how that path is set up.

Sources and checks

  1. Claude Code error reference
  2. Connect Claude Code to an LLM gateway
  3. Claude Code model configuration