This model's maximum context length is: fixing context_length_exceeded

The window is not just your prompt. System instructions, tool definitions, the whole message history, and on reasoning models the invisible thinking tokens all compete for the same budget. Once you can measure the split, the fix picks itself.

By the Continuum team. We build a workbench that runs Claude Code, Codex, and their peers, so the model rates quoted here are the ones our own cost analytics ship with.

The short version

Every provider rejects an over-long request differently. OpenAI returns a 400 context_length_exceeded naming both the limit and your token count; Anthropic returns prompt is too long: N tokens > M maximum; Google returns a 400 in the invalid_request family. What they share is the accounting: system prompt, tool schemas, full message history, output reservation, and reasoning tokens all count. Current windows are large enough that most of these errors are now history-management bugs rather than genuine limits, with GPT-5.6 at 1,050,000 tokens, Claude 5-series models at 1M, and the Gemini 3.x line at 1,048,576. The fixes, in ascending order of effort, are trimming, compaction, retrieval, and routing to a bigger window.

What you need to know
  • The window holds everything: system, tool schemas, history, output reservation, and reasoning tokens.
  • Reasoning tokens count, and you cannot see them. This is why a request that fit yesterday fails today.
  • Tool definitions are resent on every single call. Twenty verbose schemas is a permanent tax on every turn.
  • On Claude 4.5 and newer, input plus max_tokens over the window is accepted and stops with model_context_window_exceeded.
  • GPT-5.6 has a 922,000 max-input cap under a 1,050,000 window. You can blow the input cap first.
  • Cross the 272K input mark on GPT-5.6 and you pay 2x input and 1.5x output on the whole request.
  • Bigger windows are slower and dearer, and recall degrades long before the limit. A fit is not a good idea.

This model's maximum context length is N tokens

Three providers, three wordings, one condition. Search traffic clusters around the OpenAI phrasing because it is the oldest and the most quoted, but knowing all three saves you when your gateway abstracts the provider away.

How each provider says it.checked aug 2026
ProviderStatus and codeMessage shape
OpenAI400, code: context_length_exceededThis model's maximum context length is N tokens. However, your messages resulted in M tokens...
Anthropic400, invalid_request_errorprompt is too long: 206767 tokens > 200000 maximum
Google (Interactions API)400, code: "invalid_request"A message naming the offending field
OpenRouter400, error_type: context_length_exceededNormalized across upstream providers

The most useful property of the OpenAI wording is that it gives you both numbers. The gap between them tells you which fix you need: 300 tokens over is a trimming problem, 300,000 over is an architecture problem, and treating the second like the first is how people end up with a truncation function that quietly destroys the beginning of every conversation.

What actually counts toward the window

People budget for the prompt and get surprised by everything else. OpenAI defines the window across three categories, verbatim: input tokens, output tokens, and reasoning tokens, the last being tokens "used by the model to plan a response". That third category is the one you cannot see and cannot easily predict.

The full accounting for a single agent turn.
ComponentCounts?Notes
System promptYesConstant per call. Every word is paid for on every turn
Tool and function schemasYesResent in full on every request. Verbose JSON Schema is expensive
Full message historyYesGrows without bound unless something manages it
Tool resultsYesThe usual runaway: one unpaginated file read can be 50k tokens
Images and documentsYesTokenized by dimensions, not by file size
Reasoning tokensYesInvisible in the response, counted in the window, variable per request
Output reservationYesYour max_tokens is held against the window on most providers
Cached prefixYesCaching cuts the price, not the token count

Prompt caching is worth a sentence here because it is regularly misunderstood as a context fix. It is not. A cached prefix costs a fraction of the price, typically a tenth on read, and occupies exactly the same number of tokens in the window. Caching solves cost and latency. It does nothing for this error.

The current limits, and the caps hiding inside them

Windows grew enormously through 2026, which changed the character of this error: it is now far more often a history-management bug than a real ceiling.

Context and output limits, checked August 2026 against each vendor's model pages.
ModelContext windowMax outputNotes
gpt-5.6-sol1,050,000128,000Max input 922,000
gpt-5.6-terra1,050,000128,000Max input 922,000
gpt-5.6-luna1,050,000128,000Max input 922,000
claude-fable-51M128k
claude-opus-51M128k
claude-sonnet-51M128k
claude-haiku-4-5-20251001200k64kThe small model is the one to watch
gemini-3.7-flash1,048,57665,536Same shape across the 3.x line
gemini-3.1-pro-preview1,048,57665,536Prices step up above 200k input
  • The 922,000 input cap on GPT-5.6 is separate from the window. You can be inside 1,050,000 and still rejected for input alone. Two limits, two failure modes.
  • Anthropic no longer gates 1M behind a beta header. The docs are explicit: for every model with a 1M window, 1M is the default, no header, and long-context requests are billed at standard rates. If your code still sends context-1m-2025-08-07, delete it.
  • Gemini 3.1 Pro prices in two bands, $2 and $12 per million up to 200k input and $4 and $18 above it. The window does not change; the invoice does.
  • GPT-5.6 has a price cliff at 272K input: past it, the whole request bills at 2x input and 1.5x output. A 280k-token request costs disproportionately more than a 270k one.

Measure before you fix

Counting tokens before you send is cheap, and both major providers give you an endpoint for it. Guessing at four characters per token is fine for a rough sanity check and useless for a limit that rejects you at one token over.

Anthropic exposes a dedicated counting endpoint. Count the request as you will actually send it, tools included.
count = client.messages.count_tokens(
    model="claude-sonnet-5",
    system=SYSTEM_PROMPT,
    tools=TOOLS,          # schemas count, and people forget them
    messages=messages,
)
print(count.input_tokens)

The number that matters is not the total, it is the breakdown. Log the four components separately, once, on a representative conversation:

  1. System prompt. Fixed cost, paid every turn. If it is above a couple of thousand tokens, it is worth an edit.
  2. Tool schemas. Also fixed, also every turn, and usually the most compressible thing in the request. Descriptions written for a human reader are the usual culprit.
  3. History. The part that grows. If this is 80% of your total, no amount of prompt editing will help you.
  4. The largest single message. Nine times out of ten it is one tool result: a whole file, an unpaginated query, a full HTML page from a fetch.

Four fixes, cheapest first

1. Trim the history

Drop the oldest turns until you fit. Fast, stateless, and it silently loses whatever was decided early in the conversation, which for a coding agent is usually the requirements. Two rules make it survivable: never split a tool exchange, because a tool_use without its tool_result is an immediate 400 on Anthropic, and always keep the first user turn, because it usually carries the actual task.

2. Compact

Summarize the older half of the conversation into a single message and continue. This is what Claude Code does at its context threshold and it is the best general answer for long-running agent sessions: it preserves decisions and discards transcript. The cost is one extra model call and the permanent loss of exact wording, which matters if the conversation contained precise identifiers or code that will be referenced verbatim later.

3. Move the bulk out of context entirely

If you are pasting a corpus into every request, retrieval is the right answer and the window is not your problem. Chunk, embed, and fetch the three passages that matter per turn. This is more infrastructure than the other options and it is the only one that scales past a window of any size. It also fails differently: instead of an error you get a confident answer based on the wrong chunk, so it needs evaluation in a way trimming does not.

4. Route to a bigger window

The escape hatch, and the one to reach for last. It works, it is one line, and it hides the underlying growth until you hit the bigger limit too. Two costs to weigh: money, since GPT-5.6 doubles input pricing past 272K and Gemini 3.1 Pro steps up past 200k, and quality, because recall across very long contexts degrades well before the hard limit. A conversation that only fits in a million tokens is usually a conversation that should have been compacted. If you do route up, the cards for Claude Fable 5 at 1,000,000 input tokens and gpt-5.6-sol at 1,050,000 carry the exact window and output ceiling for each.

Choosing between them.
SituationReach for
Slightly over, occasionallyTrimming, plus a tool-output cap
Long agent session, gradual growthCompaction at a threshold
One enormous document per requestRetrieval, or a long-context model if it is genuinely one-shot
Large static corpus, many questionsRetrieval. Nothing else scales
Genuinely needs a million tokens, onceA long-context model, and accept the bill
Growing history and a small modelCompaction first, then reconsider the model

Questions people ask

What does context_length_exceeded mean?

Your request needs more tokens than the model can hold in one call. The count includes the system prompt, every tool schema, the entire message history, any output you reserved with max_tokens, and on reasoning models the invisible thinking tokens. The provider rejects the whole request rather than truncating it, except on Claude 4.5 and newer where an over-long output reservation is accepted and generation stops with model_context_window_exceeded instead.

Do reasoning tokens count toward the context window?

Yes. OpenAI defines the window as input tokens, output tokens, and reasoning tokens together, describing the last as tokens used by the model to plan a response. This is why an identical request can succeed once and fail the next time: reasoning length varies with the difficulty of the problem, and you cannot see it in the response.

How do I count tokens before sending a request?

Anthropic exposes a count_tokens endpoint that accepts the same system prompt, tools, and messages you are about to send, so count the request exactly as you will send it rather than counting the prompt alone. Rough character-based estimates are fine for a sanity check and useless near the limit. What matters most is logging the breakdown across system, tools, history, and largest single message.

Does prompt caching help with context length errors?

No. Caching reduces the price of a repeated prefix, typically to a tenth on read, and occupies exactly the same number of tokens in the window. It is a cost and latency optimization, not a capacity one.

What is the largest context window available in August 2026?

Around a million tokens across all three major providers: GPT-5.6 models at 1,050,000 with a separate 922,000 max-input cap, the Claude 5-series at 1M, and the Gemini 3.x line at 1,048,576. Note that using a large window is not free. GPT-5.6 charges 2x input and 1.5x output above 272K input tokens, and Gemini 3.1 Pro prices differently above 200k.

Should I just switch to a bigger model?

It is the fastest fix and rarely the best one. Recall degrades across very long contexts well before the hard limit, the request gets slower, and the pricing bands make a very large request cost disproportionately more. A conversation that only fits in a million tokens is usually one that should have been compacted, and switching models just defers the same failure to a larger number.

Sources

Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.

  1. OpenAI conversation state and context the three-category definition of the context window
  2. OpenAI token counting max_output_tokens covering non-visible tokens
  3. Claude context windows prompt-too-long, model_context_window_exceeded, 1M without a beta header
  4. GPT-5.6 Sol model reference window, max input, and the 272K pricing band
  5. Gemini API models input and output token limits for the 3.x line
  6. Gemini API pricing the 200k input pricing step on Gemini 3.1 Pro
Try it

Find the turn
that ate the window.

Continuum drives Claude Code, Codex, and peers under your own subscriptions, with live quota gauges and spend by repo. The app is free. Mac is stable; Windows and Linux desktop are beta.

free app · your subscriptions · local-first