[BUG] API Error: 400 Input is too long for requested model.

Status Fixed / completed
Maintainer reply ✓ Yes — bcherny
Activity 14 comments · opened Apr 10, 2025 · closed Jun 10, 2025
💡 Likely answer: A maintainer (bcherny, collaborator) responded on this thread — see the highlighted reply below.

Environment

  • Platform (select one):
  • [ ] Anthropic API
  • [x] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: 0.2.67
  • Operating System: macOs 15.3.2
  • Terminal: Warp

Bug Description

<img width="1153" alt="Image" src="https://github.com/user-attachments/assets/91410083-9a0f-40a4-b6e7-5b5bea3ea5e9" />

Getting this error after an attempt of reading the large file, /compact does not help. Have to exit and open claude code again

Steps to Reproduce

  1. Get context to fill up to about 70%
  2. Make claude read file of about 100k+ tokens
  3. See the error, API Error: 400 Input is too long for requested model.
  4. try to compact, see the error Error: Error during compaction: Error: API Error: 400 Input is too long for requested model.

Expected Behavior

Compact should work regardless of volume of used context

Actual Behavior

All subsequent promts returns an error API Error: 400 Input is too long for requested model.

Additional Context

<!-- Add any other context about the problem here, such as screenshots, logs, etc. -->

View original on GitHub ↗

14 Comments

bcherny collaborator · 1 year ago

As a workaround:

  1. Hit esc twice to jump back to the previous message
  2. Run /compact
  3. Hit up arrow to get your old prompt back and send it
stepango · 1 year ago

Thanks @bcherny I'll try that if issue pops up again.

nadzinski · 1 year ago

Thanks @bcherny - unfortunately the workaround doesn't work for me, as the error appears when Claude is handing my initial message. Here is a sample:

> Please remove the `<flag name>` gargoyle flag from the codebase.

  You should only need to examine these files:
  <file1>
  <file2>
  <file3>
  <file4>
  <file5>

● I'll remove the <flag name> gargoyle flag from the codebase. Let me examine the
  files you mentioned.

● Read(<file1>)…
  ⎿  Read 318 lines (ctrl+r to expand)

● Read(<file2>)…
  ⎿  Read 2438 lines (ctrl+r to expand)

● Read(<file3>)…
  ⎿  Read 5677 lines (ctrl+r to expand)

● Read(<file4>)…
  ⎿  Read 3483 lines (ctrl+r to expand)

● Read(<file5>)…
  ⎿  Read 3707 lines (ctrl+r to expand)
  ⎿  API Error: 400 Input is too long for requested model.

Any tips for getting this to work, short of breaking these large files apart? Thanks!

jonathancaevans · 1 year ago

+1 on this error.

This causes early exit when in headless mode. I'm imagining context window overflow is covered for Anthropic first party API. Would be nice to have recovery behavior for Bedrock.

jmanhype · 1 year ago

having this issue with regular base claude code!

sid374 contributor · 1 year ago

We've made a bunch of improvements to context management recently, and this should feel a lot better. Feel free to reopen if you're still seeing issues.

earaya · 1 year ago

I just got this today with 60% context use. Just in case anyone is interested in still trying to address this. I switched to Bedrock today and had never encountered this before today.

@sid374 do you want me to open a new bug?

rsteiger · 1 year ago

Still seeing this as well with bedrock with --continue

goel-akas · 1 year ago

same here - bedrock suffers from this issue

jswny · 1 year ago

Also seeing this still with Bedrock Claude 4 Sonnet

rithik351 · 1 year ago

Got a fix - just got to the prompt that caused the 400, double click which makes it editable, edit and send.

in my case i asked cline to read a file which caused 400, i edited to not read that . it did not try to read in the next run and was able to chat again. no need to compact the context.

samagana · 1 year ago

I'm still facing the same issue but do not have permissions to reopen this ticket cc: @sid374
The same prompt when inside claude is working fine but when using claude -p $PROMPT (or pipe), I'm getting the following error

$ claude --allowedTools Task,Glob,Grep,LS,exit_plan_mode,Read,Edit,MultiEdit,Write,NotebookRead,NotebookEdit,WebFetch,TodoRead,TodoWrite -p "$PROMPT"
API Error: 400 Input is too long for requested model.
alexcam1901 · 1 year ago

Having the same issue, using Bedrock. In my case, once Claude Code throws it will continue to throw the error for any prompt of any length until I exit and restart. Happens 100% of the time on specific calls no matter the context size Claude Code is dealing with.

I did some logging and got a hot take from Claude Code. Seems that Claude Code can't recover when a (obviously) too large context is sent:

I can see that the server is processing requests successfully, including:
    - get_my_channels returning 133,609 characters/bytes (line 7, 246, 590)
    - batch_get_conversation_history returning much larger responses:
        - Line 12: 671,375 characters/bytes 
      - Line 633: 206,973 characters/bytes
      - Line 676: 671,412 characters/bytes
  2. The issue appears to be that when fetching conversation history from Slack channels (especially channel **** which seems to be the **** channel), the responses are extremely large - over 670,000 characters.
  3. This large response is then being sent to an AI model (likely Claude) which has input token limits, causing the "400 Input is too long for requested model" error.
  4. The server is successfully authenticating with Slack and fetching data, but the data volume is exceeding the model's context window.

The problem is clear: the Slack channel history being fetched contains too much data to fit within the AI model's input token limits.

⏺ Looking at the logs, the issue is clear. Your Slack MCP server is successfully fetching large amounts of data from Slack channels, but the responses are too large for the AI model's context window.

  Key findings from slack_client.log:

  Large Response Sizes:
  - get_my_channels: 133,609 characters
  - batch_get_conversation_history: 671,412 characters (multiple instances)
github-actions[bot] · 1 year ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.