Claude Context Window: Every Model's Limit
The current Claude models — Opus 4.8, Sonnet 5, and Fable 5 — each ship a 1M-token context window with a 128k max output on the synchronous Messages API; Haiku 4.5 is 200k / 64k, and the older Claude line (including Sonnet 4.5, Opus 4.5, and Opus 4.1) sits at 200k. But the number people actually trip over is not the window — it is the difference between the context window (all input plus the generated output, combined) and max_tokens (a per-request cap on output alone). This guide is the per-model reference table, the context-vs-max_tokens distinction spelled out, what a 1M window actually holds, and how to use it without burning cost.
Every Claude model's context window and max output
The current models — Opus 4.8, Sonnet 5, and Fable 5 — are 1M context / 128k output; Haiku 4.5 is 200k / 64k; the older line is 200k. The single reference table, from Anthropic's model overview (synchronous Messages API limits):
| Model | Context window | Max output (Messages API) | Batches API output |
|---|---|---|---|
Claude Opus 4.8 claude-opus-4-8 | 1,000,000 | 128,000 | 300,000 (beta) |
Claude Sonnet 5 claude-sonnet-5 | 1,000,000 | 128,000 | 300,000 (beta) |
Claude Fable 5 claude-fable-5 | 1,000,000 | 128,000 | — |
Claude Haiku 4.5 claude-haiku-4-5-20251001 | 200,000 | 64,000 | — |
| Claude Sonnet 4.5 (legacy) | 200,000 | — | 300,000 (Sonnet 4.6, beta) |
| Claude Opus 4.5 / 4.1 (legacy) | 200,000 | — | — |
| Older Claude 3.x line (legacy) | 200,000 | — | — |
The 300k Batches figure applies to Opus 4.8, Opus 4.7, Opus 4.6, Sonnet 5, and Sonnet 4.6 via the output-300k-2026-03-24 beta header. Source: Anthropic model overview (verified July 2026). Choosing between the two tiers of Sonnet and Opus? See Claude Sonnet vs Opus.
The current 1M-window models
Opus 4.8, Sonnet 5, and Fable 5 each carry a 1M-token context window — and it is the default, not an opt-in. The 1M window is available on the Claude API, Amazon Bedrock, Google Cloud, and Microsoft Foundry, and no beta header is required to use it. That matters because earlier 1M-context rollouts were gated behind a beta flag; on the current generation you get the full window on a plain request. Each of the three caps a single synchronous request's output at 128k tokens. If you are picking a default model for long-context work, our best LLM API roundup covers where each fits.
Context window vs max_tokens — the distinction that trips people
The context window is the whole working memory; max_tokens caps only the output of one request. These are constantly confused, so pin them down:
- Context window is all the text the model can reference when generating a response — including the response itself. It holds the full conversation history plus the new output the model generates. Everything in the request counts: system prompt, all messages (tool results, images, documents), and tool definitions — plus all generated output, including extended thinking.
max_tokensis the output-generation limit for a single request. It is a subset of, and distinct from, the total context window. A 1M-window model like Fable 5 still caps one request's generated output at 128k viamax_tokens, while the full 1M covers input plus output combined.
So the mental model is: context window ≥ input + output, and separately output ≤ max_tokens ≤ 128k. You can have a 1M window and still only ever emit 128k tokens in one shot.
max_tokens definitions, the “includes the response itself” wording, and the per-model numbers are from Anthropic's official Context windows and Models overview docs (verified July 2026).Claude 3.7 and the older 200k line
The older Claude 3.x-generation and other legacy models have a 200k-token context window. If you are searching for the “Claude 3.7 context window,” the answer is 200k — the figure that has held across the older Claude line. Anthropic's current docs no longer list named Claude 3.x models in a legacy table, so we corroborate the 200k figure via the still-listed 200k legacy entries: Claude Sonnet 4.5, Claude Opus 4.5, and Claude Opus 4.1. The jump to 1M only lands on the current three (Opus 4.8, Sonnet 5, Fable 5). If you are on an older model for cost reasons, compare against the current line in our cheapest LLM API guide.
How big is 1M tokens, really
Roughly 750,000 English words — a token averages about three-quarters of a word. That is on the order of a 3,000-page book, or several large codebases held in memory at once. But the practical number is smaller than the headline, because the window is shared: input and output live in the same 1M budget, and everything counts toward it — system prompt, every message, tool definitions, images, documents, and all generated output including extended thinking. A concrete budget for a 1M-window model:
| What you put in the window | Approx. tokens | Left in the 1M budget |
|---|---|---|
| System prompt + tool definitions | ~10,000 | 990,000 |
| A large codebase (~40k lines) | ~500,000 | 490,000 |
| Long conversation history | ~200,000 | 290,000 |
| Reserve for a 128k max output | 128,000 | 162,000 headroom |
Illustrative budget, not an Anthropic figure — the word/token ratio and “everything counts” rule are from the Context windows docs; the token counts here are rounded estimates to show how the shared budget divides. The lesson: reserve output room, or generation can stop early (next section).
What happens when you exceed the context window
On Claude 4.5 models and newer, the behaviour depends on whether it is your input or your input-plus-output that overflows. Two distinct outcomes:
| Situation | API behaviour | Signal |
|---|---|---|
| Input alone exceeds the context window | Request rejected | 400 invalid_request_error — “prompt is too long” |
Input + max_tokens exceeds the window | Accepted; generation may stop at the limit | stop_reason: model_context_window_exceeded |
The practical takeaway: setting a large max_tokens on a near-full window will not error up front — but generation can halt mid-answer once the total reaches the window. Reserve output room, or catch the model_context_window_exceeded stop reason and continue. The full 400-error catalogue and its fixes are in our LLM API error codes reference.
How to actually use a 1M window (cost and caching)
A 1M window is a cost lever before it is a capability — long input is billed input, and caching is how you keep it affordable. Practical moves when you fill a large window:
- Cache the stable prefix. System prompts, tool definitions, and large context documents rarely change between turns — cache them so repeated turns re-read instead of re-paying. Cached reads are billed at a fraction of the input price; the arithmetic is in our cost guide.
- Reserve output headroom. Because input and output share the window, set
max_tokensdeliberately and leave room, or you risk themodel_context_window_exceededstop above. - Do not fill it just because you can. A 1M prompt costs 5× a 200k prompt in input tokens. Retrieve the relevant slice rather than dumping everything; the window is a ceiling, not a target.
- Batch large output jobs. If you need more than 128k of output, the Message Batches API raises the cap to 300k on select models via the
output-300k-2026-03-24beta header.
If you are building agents that stream long tool loops into the window, our agent-model guide covers how context budget interacts with tool-call depth.
Use Claude's 1M window on one OpenAI-compatible key
DataLLM Lab routes to Claude Opus 4.8, Sonnet 5, and Fable 5 — the full 1M context window, prompt caching on by default, and failover across 300+ models when one provider is busy.
Query a model's limits from the API
Do not hard-code token limits — read them at runtime. Model capabilities and token limits can be queried via the Models API, whose response includes max_input_tokens, max_tokens, and a capabilities object for each model. That is the durable way to handle limits when you route across models or migrate to a newer version. Through the gateway it is one OpenAI-compatible call:
from openai import OpenAI
client = OpenAI(
base_url="https://www.datallmlab.com/v1",
api_key="YOUR_DATALLMLAB_KEY",
)
# List models and their metadata, then pick by context budget
for m in client.models.list().data:
if m.id.startswith("anthropic/claude-"):
print(m.id) # route long-context jobs to the 1M-window models
resp = client.chat.completions.create(
model="anthropic/claude-sonnet-5", # 1M context, 128k max output
max_tokens=128000, # output cap — a subset of the window
messages=[{"role": "user", "content": "..."}],
)
The Models API on Anthropic returns max_input_tokens and max_tokens per model (docs); the gateway exposes the equivalent list through the standard OpenAI-compatible /models endpoint.
FAQ
What is Claude's context window?
Opus 4.8, Sonnet 5, and Fable 5 have a 1M-token window (no beta header required, across Claude API, Bedrock, Google Cloud, and Foundry). Haiku 4.5 and the older Claude line are 200k. The window is all the text the model can reference, including the response itself.
Context window vs max_tokens — what is the difference?
The context window is total working memory: input (system prompt, messages, tools, docs) plus generated output, combined. max_tokens caps only the output of a single request. A 1M-window model still caps one request's output at 128k via max_tokens.
What is the max output tokens on the Anthropic API?
On the synchronous Messages API: 128k for Opus 4.8, Sonnet 5, and Fable 5; 64k for Haiku 4.5. On the Batches API, select models reach 300k via the output-300k-2026-03-24 beta header.
What is the Claude 3.7 context window?
200k tokens — the figure that holds across the older Claude line. Anthropic's docs no longer list named 3.x models, but 200k is corroborated by the still-listed legacy entries (Sonnet 4.5, Opus 4.5, Opus 4.1).
How big is a 1M-token window?
Roughly 750,000 English words (a token ≈ three-quarters of a word) — on the order of a 3,000-page book or several large codebases. Input and output share the 1M budget, and everything counts, including extended thinking.
What happens if I exceed the context window?
On Claude 4.5+ models: input alone over the window returns a 400 invalid_request_error (“prompt is too long”). Input + max_tokens over the window is accepted, but generation can stop with stop_reason: model_context_window_exceeded.
How do I read a model's limits at runtime?
Use the Models API — its response includes max_input_tokens, max_tokens, and a capabilities object per model, so you can route by context budget instead of hard-coding limits.
DataLLM Lab