prompt is too long

prompt is too long means your input alone exceeds the Claude context window. Count tokens, compact the history, or pick a wider-window model.

Checked 2026-11-22

·All fixes·Models

prompt is too long is the message Anthropic returns inside a 400 invalid_request_error when the input you send is, by itself, larger than the model's context window. It fails on whichever model you aim it at, and resending the same body changes nothing, because the request is the problem rather than a passing upstream hiccup. The way out is to measure your tokens, trim or compact the conversation you carry forward, or move to a model whose window is wide enough for the job. When your client points at https://api.uplinkswitch.com/v1, the model claude-sonnet-5-5 publishes its ceiling in the catalog's context_window field (1M), so a client can read the limit before it ever puts a byte on the wire.

What it means, per Anthropic's docs

Anthropic's context-windows reference describes the overflow behaviour directly. When the input alone is over the window, the request is rejected with a 400, and this holds on every model: there is no model you can swap to that will quietly accept an oversized input. Per Anthropic's docs (read 2026-11-22), on Claude 4.5 and newer there is a softer case worth knowing. If the input fits but the input plus your requested max_tokens would run past the window, the call is accepted and the model simply stops early, reporting stop_reason: model_context_window_exceeded rather than failing. Earlier models treat that same combination as a validation error. So the hard 400 you are reading is specifically the input-alone case, not the output-budget case.

Sizes matter here. Per that same reference, the current Claude models listed carry a wider window than the older entries; in this catalog claude-sonnet-5-5 reads 1M tokens and the older claude-haiku-4-5 reads 200K. The errors reference files this under invalid_request_error, the typed 400 that covers malformed or oversized requests, and that is the type you will see in the body.

If you hit this inside Claude Code rather than through a raw SDK call, the surface is different. Claude Code's error reference shows the same underlying limit as Context limit reached, with a prompt to run /compact or /clear to continue. That is the same ceiling reached from the other side: a session whose accumulated history has grown past what one request can hold.

What the gateway changes

These are the gateway behaviours that bear on this error, taken from the published OpenAPI description. A 400 points at the request, so it is never retried elsewhere and never handed to another route or to the next models entry; the gateway treats it as Anthropic does, a request that cannot succeed unchanged. The Anthropic-format response comes back in Anthropic's own error shape with the error code appended to the message, so a client that already reads Anthropic errors needs no new parsing. A request id also comes back in its headers, the handle to quote if you open a support thread.

One nearby limit is easy to confuse with this one: the gateway turns back any request body past 10 MB with a 413, a size-of-payload limit rather than a token-count one. A giant pasted transcript can trip the 413 before the model ever evaluates its token window, so check which of the two you are actually hitting.

A word of caution on the "just use a bigger model" instinct. The current Claude, GPT and Gemini 3.8 windows published in the catalog are close in size, so moving families is not a reliable escape from a context overflow; if your input overruns one of those windows it will likely overrun the others too. Treat a wider window as headroom for a genuinely large but bounded input, not as a way to avoid trimming an unbounded one.

On the 2026-11-23 catalog claude-sonnet-5-5 read ok and claude-haiku-4-5 read ok.

How to fix it

  • Count before you send. Run your text through a tokenizer for the target model and compare the total against the catalog context_window for that id. This turns a guess into a check you can put in code.
  • Trim or compact the history. Drop stale turns, summarise earlier context into a short brief, or keep only the messages the current step needs. In Claude Code, /compact condenses the session and /clear resets it; both are the intended response to Context limit reached.
  • Separate input from output budget. On a model older than Claude 4.5, an input that fits can still fail once a large max_tokens is added, and on 4.5 and newer it stops early instead; either way, lower max_tokens so input plus output stays inside the window.
  • Move the heavy material out of the prompt. Retrieval over a document store, or chunking a long source and processing it in passes, keeps any single request inside the window.
  • Move up only when the input is bounded: read the catalog's context_window and pick an id with genuine headroom, keeping in mind the families are close in size.
  • Check the 413 too: if the body is huge rather than just token-heavy, the 10 MB cap may be the true blocker, so cut the payload itself.

The sibling case on the OpenAI side is context_length_exceeded, which is the same overflow expressed as an OpenAI code; if you run both providers behind one client, the two pages together cover the whole surface. For the underlying concept, how the context window and the output cap differ, read context window vs max output tokens, which owns that explanation; this page owns the error.

Questions and answers

Not toward this particular 400. prompt is too long is raised when the input alone overruns the window. Per Anthropic's context-windows doc, max_tokens enters the picture separately: on Claude 4.5 and newer, if the input fits but input plus max_tokens would exceed the window, the call is accepted and stops with stop_reason: model_context_window_exceeded, while older models reject that combination as a validation error.

It is the same ceiling, surfaced by the tool instead of the raw API. Claude Code's error reference shows Context limit reached with a suggestion to run /compact or /clear, which condense or reset the session so the next request fits inside the window again.

No. By the gateway's OpenAPI a 400 is a request problem, never retried or failed over, and no models list rescues it. The catalog's context_window field helps you avoid the error by checking the ceiling before sending, but nothing on the server side makes an oversized input fit.
Join on Telegram
Help