In the Claude API, the context window is the total capacity a model can handle in one request. Your input — system prompt, conversation history, attached documents, tool results — and the model’s generated output all count against the same limit. This guide covers what goes into the context window, what happens when you exceed it, and how to plan and manage tokens, based on the official docs. (Per-model limits and behavior may change — see the official context windows docs.)
🟢 Model references match the current lineup · model notice · Fable subscription
Fable 5 and 5.1 subscription (updated September 7, 2026): Claude Fable 5.1, released September 1, 2026, is the current Fable model and Fable 5 is now legacy. Plan terms are the same for both — Max and Team Premium plans include Fable at up to 50% of the weekly usage limit; Pro and Team Standard use usage credits (
What counts against the window
Tokens in a request are not just the reply text. The system prompt, the accumulated conversation history (every prior user and assistant turn), attached documents and images, tool definitions, and tool results all count as input tokens — and the output the model generates must fit inside the same limit. The context window varies by model — current top models (Opus 5, Sonnet 5, Fable 5.1) support 1M tokens, while Haiku 4.5 supports 200K tokens (subject to conditions — check the official model comparison table). In multi-turn conversations and agentic workflows, tool results accumulate at every step, so the real thing to manage is usually cumulative growth rather than a single request.
Thinking blocks depend on the model. With extended thinking, thinking tokens are billed as output within max_tokens, but whether previous turns’ thinking blocks stay in the context varies by model as of the September 2026 docs: current models — Opus 4.5 and later Opus, Sonnet 4.6 and later Sonnet, Fable 5.1 — keep them by default and they count toward the context window like any other input tokens, while earlier Opus/Sonnet models and all Haiku models have them stripped automatically by the API. To drop them on current models, use thinking block clearing in context editing.
What happens when you exceed the limit
Per the official docs, behavior differs by model generation. On Claude 4.5 models and newer, the API accepts a request even if input + max_tokens exceeds the window; if generation actually reaches the limit, it stops with stop_reason: "model_context_window_exceeded". Earlier models returned a validation error instead (a beta header opts into the newer behavior). If the response is cut off by max_tokens, you get stop_reason: "max_tokens". In both cases, check stop_reason in your code and handle it — warn the user, continue generation, and so on. For error handling in general, see the errors and rate limits guide.
Token counting API — count before you send
The starting point for limit management is the token counting API. It accepts the same structured input as message creation (including system prompts, tools, images, and PDFs) and returns the total input token count. Call it before the real request to avoid overflows and unintended long-context costs. Since tokens are cost, pair this with the cost optimization guide (prompt caching and batches).
max_tokens and rate limits
max_tokens caps output length. Per the official rate limits docs, output-tokens-per-minute (OTPM) limits are evaluated in real time on actually generated tokens; the max_tokens value itself does not factor into OTPM. So setting it generously to avoid truncation carries no rate-limit downside.
Long conversations: use compaction
As a conversation approaches the limit, the official docs recommend server-side compaction (summarizing the history) as the primary strategy, with context editing for finer control such as clearing tool results and thinking blocks. For app-side tips on long chats in claude.ai, see keeping context in long conversations. For choosing and pinning model IDs, see model IDs and versioning.
The limits here (200K, 1M) and behaviors reflect the official documentation as of September 2026 (re-checked against the context-windows and models overview docs); they vary by model and plan and may change. For exact per-model context sizes, see the official docs and the model comparison table. This site is not an official Anthropic site.
Curious what your usage would cost? Try the API cost calculator — pick a model and token counts for an instant estimate.
Related articles
- Claude API Model IDs and Versioning: Aliases, Pinned Snapshots, and Migration
- Claude Model Comparison: Opus 5, Sonnet 5, Haiku 4.5, Fable 5.1
- Getting Started with the Claude API: Your First Call (Developer Intro)
- Claude API Keys: Getting a Key, Pricing & Usage (2026)
- Claude Losing Context? How to Keep Long Conversations on Track (2026)