Engineering Guide

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.

Claude context window and max output tokens by model — a per-model reference table

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):

ModelContext windowMax output (Messages API)Batches API output
Claude Opus 4.8 claude-opus-4-81,000,000128,000300,000 (beta)
Claude Sonnet 5 claude-sonnet-51,000,000128,000300,000 (beta)
Claude Fable 5 claude-fable-51,000,000128,000
Claude Haiku 4.5 claude-haiku-4-5-20251001200,00064,000
Claude Sonnet 4.5 (legacy)200,000300,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:

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.

How this is sourced. The context-vs-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).
1M context window = everything the model holds at once Input: system prompt + messages + tools + docs + images Output (incl. thinking) ← counts toward the context window → max_tokens caps only this slice — the output — at 128k max_tokens ≤ 128k
The context window covers input and output together; max_tokens limits only the output slice. Source: Anthropic Context-windows docs, 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 windowApprox. tokensLeft in the 1M budget
System prompt + tool definitions~10,000990,000
A large codebase (~40k lines)~500,000490,000
Long conversation history~200,000290,000
Reserve for a 128k max output128,000162,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:

SituationAPI behaviourSignal
Input alone exceeds the context windowRequest rejected400 invalid_request_error — “prompt is too long”
Input + max_tokens exceeds the windowAccepted; generation may stop at the limitstop_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:

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.

Written by
Kevin Fan

Founder of DataLLM Lab, the unified LLM gateway. Kevin tests models the boring way — same prompts, real costs, unedited outputs — and writes up what the runs actually show.

One API for every model

One API, every model.

Get a single API key for Claude Opus 4.7, GPT-5.4, and 300+ more — with automatic price comparison and routing to the best model for every request.