Skip to content
AI Dev Toolkit.
Esc
  • Loading…

Guide · Tokens & costs

Context windows explained: what counts, what happens at the limit, and how to check fit

A context window is the most tokens a model can handle in one request: the system prompt, tool definitions, the conversation so far, any documents, and the reply it writes, all sharing one budget. If the input alone is too big, the request fails; if the reply runs out of room, it is cut off mid-answer.

By Tahir NazirUpdated 12 min read

On this page
  1. What is a context window?
  2. What counts toward the context window?
  3. Context window vs max output tokens vs token limit
  4. What happens when you exceed the context window?
  5. How big is a 200K or 1-million-token context window?
  6. Is a bigger context window better?
  7. Which models have the biggest context windows?
  8. RAG or long context: which should you use?
  9. Will it fit? A long PDF, a codebase and a chat history
  10. How to check whether your text fits
  11. Questions people ask

What is a context window?

The context window is everything a model can look at while it writes one response, including the response itself. Anthropic calls it the model’s “working memory”: it is separate from what the model learned in training, and it’s measured in tokens, not words or characters.

The whole request has to fit: what you send, plus the reply. For a one-paragraph definition, see the context window glossary entry; the rest of this guide covers what fills the window, what happens at the limit and how to check fit.

What counts toward the context window?

Everything in the request, plus everything the model writes back. Anthropic’s documentation lists it plainly: the system prompt, every message (including tool results, images and documents), your tool definitions, and the output, including thinking. OpenAI describes the window the same way: input, output and, on reasoning models, reasoning tokens.

An example request, sized to show the parts. The documents dominate, but the tools, history and the room kept for the reply all come out of the same window.

Two things catch people out. First, the room for the reply: OpenAI suggests reserving at least 25,000 tokens for reasoning and output when you start with its reasoning models. Second, the hidden parts. Tool definitions are re-sent with every request, and connecting many MCP servers can add thousands of tokens before you type anything. The example’s 478,000-token prompt is also past GPT-6.1 Sol’s 272,000-token long-context threshold, so it would be billed at the higher rate.

  • Earlier turns are re-sent in full each time, so a conversation grows with every message.
  • Thinking from earlier turns stays in context on current Claude models and counts as input; older models strip it automatically.
  • Cached tokens still count. Prompt caching changes what you pay for a repeated prefix, not whether it takes up room.

Context window vs max output tokens vs token limit

The context window is the total budget for one request. Max output is a separate, usually much smaller cap on how many tokens the model can generate in one reply, and it includes any thinking. A model can have a million-token window and still stop after its output limit. Where a provider publishes no separate cap, the reply still has to fit in what’s left of the window. In Claude Code, a reply that hits its cap ends with “response exceeded the output token maximum”.

“Token limit” is used loosely for either of those, and sometimes for a third limit: rate limits, which cap how many tokens your account can send per minute across all requests. A request can fail on any of the three, and each has a different fix: shorten the input, raise the reply limit, or slow down and retry.

You set the reply limit yourself on each request (max_tokens on Claude, max_output_tokens on OpenAI), up to the model’s maximum. If the model reaches it, the reply ends early: OpenAI marks the response incomplete with the reason max_output_tokens, and Claude stops with stop_reason: "max_tokens". With a reasoning model, a low limit can be used up by thinking before any answer appears.

What happens when you exceed the context window?

It depends on which part overflows and on who manages the conversation.

  • The input is too big. Anthropic’s API rejects it with a 400 invalid_request_error, “prompt is too long”, on every model. Nothing is generated.
  • The reply runs out of room. On Claude 4.5 models and newer, a request whose input plus max_tokens exceeds the window is accepted, and generation stops with stop_reason: "model_context_window_exceeded" if it reaches the limit. OpenAI warns that tokens beyond the window “may be truncated”.
  • In chat apps and agents, the app usually handles it: it drops the oldest messages or summarises them. That keeps the conversation going, but the model quietly stops seeing whatever was dropped.

Summarising old turns is called compaction. Anthropic and OpenAI both offer it on the server: Claude replaces older turns with a summary it writes itself (in beta), and OpenAI’s Responses API can compact once a token threshold you set is crossed. In Claude Code, /compact does the same by hand; see our fix for “Prompt is too long”, and how to reduce Claude Code token usage for keeping an agent’s context small in the first place.

How big is a 200K or 1-million-token context window?

A 200,000-token window holds roughly 111,000 to 173,000 words of English prose, about 220 to 350 single-spaced pages. A 1-million-token window holds five times that. The range comes from the tokenizer: the same text takes more tokens on current Claude models than on GPT’s.

Roughly how much English prose fits
WindowWords on GPT (o200k_base)Words on current ClaudeWords on Claude before Opus 4.7Single-spaced pages
128K tokens111,00071,00096,000140–220
200K tokens173,000111,000150,000220–350
1M tokens866,000555,000750,0001,110–1,730

GPT: 1,747 words came to 2,017 tokens on our English sample. Claude: Anthropic’s published figures. Pages at 500 words each. The whole window is shown; leave room for the system prompt and the reply.

Code, tables, JSON and non-English text use more tokens per word, so they fit less. Measure your own material, or use the tokens to words converter for ratios measured by tokenizer, language and kind of text.

Is a bigger context window better?

Bigger lets you send more, but sending more has three costs, so use the space you need rather than all of it.

  1. Money. You pay for every input token on every request. On Claude Sonnet 5.5, one request with a 900,000-token prompt and a 1,000-token answer costs $1.81, against $0.05 with a 20,000-token prompt (prices as of 2026-11-22). Caching a repeated prefix brings the big one down to about $0.12, and some models charge a higher rate for long prompts.
  2. Speed. Google’s long-context guide notes that longer queries generally have higher latency, measured as time to the first token.
  3. Recall. Models don’t use every part of a long context equally well. Anthropic’s docs say accuracy and recall degrade as the token count grows, which it calls “context rot”, and Google says accuracy drops when you look for several pieces of information at once rather than one.

The best-known study is “Lost in the Middle” (Liu and others; posted in 2023, published in TACL in 2024). Testing multi-document question answering and key-value lookup, it found performance was often highest when the relevant information sat at the beginning or end of the input, and dropped significantly when it was in the middle, even for models built for long contexts. The models tested are now old, so treat it as a reason to test your own task, not as a current score.

Which models have the biggest context windows?

In our data today (2026-11-22), the biggest context window is 2,000,000 tokens, on Grok 4.20 and Grok 4.20 Multi-Agent. Of the 324 text models listed, 123 accept at least 1,000,000 tokens and 100 accept fewer than 200,000. Here are some popular models, with the separate limit on how much each can write in one reply:

Context window and maximum output (2026-11-22)
ModelContext windowMax output per reply
Claude Sonnet 5.51,000,000 tokens128,000 tokens
Claude Haiku 5.51,000,000 tokens128,000 tokens
GPT-6.1 Sol1,050,000 tokens128,000 tokens
GPT-6 Luna1,050,000 tokens128,000 tokens
Gemini 3.8 Flash1,048,576 tokens65,536 tokens
Gemini 3.5 Flash Lite1,048,576 tokens65,536 tokens
Llama 4 Maverick524,288 tokens32,768 tokens

From our daily data (OpenRouter models API and LiteLLM). The model comparison table lists every model and filters by minimum window.

The biggest window is rarely the deciding factor: the price per token, the long-context surcharge some models apply and how well the model recalls details deep in a long prompt matter more. The model comparison sorts models by window and price together.

RAG or long context: which should you use?

Use long context when the model needs to read the whole thing at once, and retrieval when it only needs the relevant parts. RAG (retrieval-augmented generation) means searching your documents first and sending only the best-matching passages with the question.

  • Long context suits one-off analysis of a single document, questions that need the whole text (a summary, a contract review, “what changed between these two versions”), and corpora small enough to fit and cache.
  • RAG suits collections bigger than any window, many questions against the same material, content that changes often, and apps that must answer quickly and cheaply or cite their sources.
  • Both together is common: retrieve generously, then let a long-context model read twenty passages instead of three.

Chunking: how to split what doesn’t fit

Whether you retrieve or process a document in parts, you need chunks. Split on the document’s own structure (sections, headings, functions) rather than at a fixed character count, keep each chunk understandable on its own, and attach where it came from (title, section, page) so answers can cite it. A small overlap between neighbouring chunks stops a sentence that spans a boundary from being lost. For map-style jobs like summarising a long report, process each chunk, then combine the partial results in a final request. How big each chunk should be, and how much to overlap, is covered in RAG chunk size and overlap.

Will it fit? A long PDF, a codebase and a chat history

Here are three common jobs, checked against three real windows with 8,192 tokens kept for the reply and 3,000 for a system prompt:

Does it fit in one request?
JobTokensClaude Sonnet 5.5 (1,000,000)Mistral Small 4 (262,144)Llama 4 Maverick (524,288)
A 200-page PDF (text only)300,000–600,000Fits (61% of the window)Too large (split into 3 parts)Too close to call (split into 2 parts)
A 50,000-line codebaseabout 560,000Fits (57% of the window)Too large (split into 3 parts)Too large (split into 2 parts)
A 150-turn chat150,000Fits (16% of the window)Fits (61% of the window)Fits (31% of the window)

Token counts are estimates: the PDF uses Anthropic’s per-page range, the codebase our measured lines-to-tokens ratio, the chat 1,000 tokens per turn. Parts are the number of pieces the text would need, each sent with the same system prompt and reply room. Verdicts use the same rules as our context window checker.

  • A long PDF. Anthropic says each PDF page typically uses 1,500 to 3,000 tokens of text, and each page is also sent as an image, which costs more tokens on top. Claude accepts up to 600 pages per request (100 when the window is under 1M), so a big report can hit the page limit before the token limit.
  • A codebase. We counted this site’s own code: 20,062 lines of TypeScript came to 224,859 tokens with OpenAI’s o200k_base tokenizer, about 11 tokens per line. Coding agents usually don’t send a whole repository; they search for and read the files a task needs, which is cheaper and keeps the context focused.
  • A chat history. At about 1,000 tokens per turn (a question and its answer), Llama 4 Maverick’s window holds roughly 513 turns with the same reply room. Long before that, it’s worth summarising older turns, because each new message resends all of them.

How to check whether your text fits

Count the tokens, add what else goes in the request, and leave room for the reply. Our token counter counts text in your browser. For the closest count, use the provider’s own counter: Anthropic’s token counting endpoint (free to call) and Gemini’s countTokens method take the same request you would send, and OpenAI’s tokenizers are published for its older models. For a quick check across many models at once, use our checker:

Free toolContext window checkerPaste text or enter a token count, set the reply room and other tokens, and see which models it fits, with the number of parts if it doesn’t.

If the request fits but is large, check the price too: the LLM cost calculator shows what a long prompt costs per day and month, and the model comparison table lets you filter models by minimum context window.

FAQ

Questions people ask

How big is a 200K context window?

About 111,000 to 173,000 words of English, or roughly 220 to 350 single-spaced pages at 500 words a page. The low end is current Claude models (Anthropic’s figure), the high end GPT’s o200k_base tokenizer on our English sample. The system prompt and the reply share that budget, and code or non-English text fits less.

How many words fit in a 1-million-token context window?

Roughly 555,000 to 866,000 words of English, depending on the tokenizer. Anthropic gives about 555,000 words for current Claude models and about 750,000 for models before Opus 4.7, and GPT’s o200k_base tokenizer fits about 866,000 on our English sample. Code and non-English text fit fewer words.

Which AI has the biggest context window?

It changes with each model release, so we compute it from our daily model data instead of naming a permanent winner. On 2026-11-22 the biggest window in our data was 2,000,000 tokens, on Grok 4.20 and Grok 4.20 Multi-Agent. The context window checker lists each model’s limit and tells you whether your text fits. A model’s maximum output is usually far smaller than its window.

What is the difference between a context window and a token limit?

“Token limit” is used loosely. The context window (also called context length) is the total budget for one request, input and output together. A separate max output tokens limit caps how long one reply can be, and rate limits cap how many tokens your account sends per minute. A request can fail on any of the three, and each has a different fix.

Does the model’s reply count toward the context window?

Yes. The reply, including any hidden thinking or reasoning tokens, is generated inside the same window as your prompt. That’s why you need to leave room for it: a prompt that fills the window leaves nothing for the answer, and a reply that runs out of room stops mid-sentence.

What happens when a chat fills the context window?

A model only sees what is in the current request, so chat apps resend earlier turns and, near the limit, usually drop or summarise the oldest ones, which is why a long chat can “forget” early details. Through the API, Anthropic rejects an oversized prompt with an error, and OpenAI and Anthropic both offer server-side compaction that you switch on yourself.

Do cached tokens count toward the context window?

Yes. Prompt caching makes a repeated prefix cheaper and faster to process, but those tokens are still part of the request and still take up room in the window. Anthropic’s documentation states this directly: caching changes what you pay, not whether the tokens count.

Try it

Tools from this guide

Glossary

Key terms in this guide

Keep reading

Keep exploring