Skip to content

What is a context window?

Mykhailo Poliarush

Definition

A context window is the maximum number of tokens a language model can handle in one request, counting the system prompt, messages, tool definitions, tool results and the response it writes. Input beyond it is rejected or has to be dropped. In November 2026, flagship models from Anthropic, OpenAI and Google offer about 1 million tokens.

What counts toward the context window?

Everything in the request, plus the answer. Anthropic's context windows documentation lists the parts:

  • the system prompt;
  • every message, including tool results, images and documents;
  • the tool definitions;
  • the output the model generates for the turn, including extended thinking.

Two details catch teams out. Cached prompt prefixes still occupy the window: caching changes what you pay for those tokens, not whether they count. And each API response reports what the request used in its usage field, so you can measure instead of guessing. To check a request before you send it, use a token counting endpoint rather than a word count, because tokens are not words.

The same page calls the window the model's "working memory." It is separate from the training data, which the model learned from once and cannot see as text.

How big are context windows in 2026?

Flagship models from Anthropic, OpenAI and Google now sit at about 1 million tokens. Sizes from each provider's model documentation, checked on 2026-11-19:

ProviderModelsContext windowMax output per requestSource
AnthropicClaude Opus 5.5, Sonnet 5.5, Haiku 5.5 and other current models1M tokens128k tokensClaude docs
AnthropicClaude Sonnet 4.5 (deprecated) and other older models200k tokensNot listed on that pageClaude docs
OpenAIGPT-6.2 Astra, GPT-6.2 Sol, GPT-6.1 Terra, GPT-6 Luna1.05M tokens128K tokensOpenAI models
GoogleGemini 4 models (Carbon, Neon, Hydrogen, Argon)1M tokensListed as "64K / 1M"Gemini models

These numbers move with every model release, so treat the table as a snapshot and check the provider page before you design around a limit.

Size and price are linked. On Claude, 1M is the default with no beta header and is billed at standard rates, except on Claude Haiku 5.5, where prompts over 100,000 tokens cost more. A request can also hit a different limit first: up to 600 images or PDF pages per request on 1M-token Claude models, and 100 on the 200k ones.

What happens when a request is too big?

The rules differ by case. On the Claude API:

CaseWhat happens
The input alone is larger than the windowThe API rejects it with a 400 invalid_request_error ("prompt is too long")
Input fits, but input plus max_tokens is largerClaude 4.5 and newer accept the request; output stops with stop_reason: "model_context_window_exceeded" if it reaches the limit
The same case on older modelsA validation error, unless you send the opt-in beta header

Chat apps hide this from you. The docs note that interfaces such as claude.ai can drop the oldest turns on a "first in, first out" basis. An API integration has to make that choice in its own code.

Is a bigger context window always better?

No. The Claude docs say it directly: "more context isn't automatically better", because accuracy and recall drop as the token count grows.

Two 2026 studies show how far apart the advertised size and the usable size can be:

  • More input, lower accuracy. A February 2026 paper tested Grok-4, GPT-4, Gemini 2.5 and GPT-5 on classifying social media posts in bulk. Past 5,000 posts (about 70,000 tokens), every model degraded significantly, and accuracy fell to around 50 to 53% at 20,000 posts. The same authors report that the "lost in the middle" problem is largely resolved in newer models.
  • Dense input fails sooner. A June 2026 paper held length fixed at about 12,000 tokens and raised the density of distinct information instead. Open-weight models from 9B to 685B parameters that were near-perfect on sparse inputs dropped below a 60% retrieval score on dense ones.

Both test narrow tasks, so read them as warnings to measure your own case, not as rates you will see.

So a large window is room, not a strategy. What you put in it is context engineering.

Context window vs training data vs memory

Context windowTraining dataAgent memory
What it isTokens sent with this requestText the model learned from before releaseNotes or records stored outside the model
Who controls itYou, per requestThe model providerYour application
When it changesEvery callOnly with a new modelWhen the agent or your code writes to it
Size limitThe model's windowNone you can use directlyYour storage

Memory only helps when it is loaded back into the window. Our guide on how to build AI agents covers when to add it.

Example: check a request before you send it

This script applies the overflow rules above to three requests. Feed it real input_tokens from a token counting call.

# window.py: check a request against a context window before you send it.
# Sizes and overflow rules from Anthropic's context windows page (checked 2026-11-19).
# Get input_tokens from the token counting API, not from a word count.
WINDOWS = {"claude-opus-5-5": 1_000_000, "claude-sonnet-4-5": 200_000}

def check(model, input_tokens, max_tokens):
    window = WINDOWS[model]
    if input_tokens > window:
        return "rejected: 400 prompt is too long"
    if input_tokens + max_tokens > window:  # Claude 4.5 and newer accept this
        return f"accepted, but output may stop early ({window - input_tokens:,} tokens left)"
    return f"fits ({window - input_tokens - max_tokens:,} tokens spare)"

requests = [
    ("claude-opus-5-5", 180_000, 64_000),   # long agent session
    ("claude-sonnet-4-5", 180_000, 64_000), # same request, smaller window
    ("claude-sonnet-4-5", 240_000, 8_000),  # input alone is too big
]
for model, inp, out in requests:
    print(f"{model:18} in={inp:>7,} max_out={out:>6,} -> {check(model, inp, out)}")

Output under Python 3.11:

claude-opus-5-5    in=180,000 max_out=64,000 -> fits (756,000 tokens spare)
claude-sonnet-4-5  in=180,000 max_out=64,000 -> accepted, but output may stop early (20,000 tokens left)
claude-sonnet-4-5  in=240,000 max_out= 8,000 -> rejected: 400 prompt is too long

The second line is the one to watch. The request goes through, and the answer can end mid-sentence 20,000 tokens later. Check stop_reason on every response.

What should you check before relying on a large window?

  1. Count, do not estimate. Use the provider's token counting and usage fields.
  2. Reserve output room. Leave space for max_tokens, and thinking if it is on.
  3. Handle the stop reason. Treat a window-exceeded stop as an incomplete answer, not a result.
  4. Test recall at your real input size. A model that works at 20k tokens may miss facts at 400k.
  5. Plan for long runs. Agents that outgrow the window need compaction or a handoff, usually built into the agent harness.

SDCLabs builds AI agents with a test set of real examples, evals that score every change, and traces and cost dashboards for every run.

Frequently asked questions

How many words fit in a context window?

There is no fixed ratio, because tokens are not words and each provider uses its own tokenizer. Count tokens with the provider's token counting endpoint, or read the usage field of a real response.

Does the context window include the model's answer?

Yes. The output, including any thinking tokens, counts toward the same limit as the input, which is why you need to leave room for max_tokens.

Does a model remember past chats outside the context window?

Not by itself. Anything the model should use has to be in the current request. Apps that seem to remember store notes elsewhere and load them back into the window.

Which model has the largest context window?

On 2026-11-19, OpenAI listed 1.05M tokens for its four flagship GPT-6 models, and Anthropic and Google listed 1M for current Claude and Gemini 4 models. Check the provider pages, because sizes change with each release.

Building with AI agents? Talk to an engineer.