Tokens, Context Windows & Why They Matter
Introduction
Every model, local or in the cloud, has one hard limit: how much text it can take in at once. That limit is the context window, and it is measured in tokens.
It decides how much you can give a model in one call, why a long chat seems to forget how it began, what each call costs, and why a call can be refused. Tokenization: How Text Becomes Numbers (BPE) showed how text becomes tokens; here tokens become the budget of every API call.
You'll learn:
- How many tokens your text is: the rule of thumb, and what counting shows
- What the context window holds: everything in the call, the reply included
- Why models are stateless, and what sending the whole chat every time costs
- How big windows are in November 2026, and what happens when a call does not fit
- How this shapes cost, memory and design
Tokens, Counted
A tokenizer cuts text into tokens: a common word is one token, a rare word several, and spaces and punctuation count too. OpenAI's help page gives the rule of thumb for English: "1 token is approximately 4 characters. 1 token is approximately three-quarters of a word. 100 tokens are approximately 75 words." It adds: "These are estimates, not exact counts."
Counted on real text, the rule bends. The prose of the 280 lessons of the seven AI Engineering courses (their text, without the code blocks) holds 3,545,186 characters and 563,975 words, which GPT-2's tokenizer cuts into 925,215 tokens: 3.83 characters a token, close to the rule, but only 0.61 words a token, fewer than three quarters. The tokenizer matters as much as the text. Anthropic's page on Claude's models says a million tokens "is roughly 555k words or 2.5M Unicode characters on the current tokenizer (introduced with Claude Opus 4.7)", while "models before it fit about 750k words in 1M tokens".
So the rule is a first guess, and a real count comes from the provider's own tokenizer. Two facts carry through everything below: everything is measured in tokens, and what you send and what the model writes both count.
The Context Window: Everything in One Call
The context window is how many tokens one call can hold, and everything in the call shares it. Anthropic's page: "The “context window” refers to all the text a language model can reference when generating a response, including the response itself." And: "Everything in the request counts toward the context window: the system prompt, every message in messages (including tool results, images, and documents), and your tool definitions." OpenAI says the same of its own windows: "This max tokens number includes input, output, and reasoning tokens."
So one budget holds:
- the system prompt;
- the whole conversation so far;
- your new message;
- room for the reply, which the model writes into the same window;
- and, where they are used, tool definitions and a reasoning model's thinking.
The figure follows one chat through four calls: Foundations of AI Engineering's own quiz questions and answers, counted with GPT-2's tokenizer, sent to a window of 1,024 tokens with 256 kept for the reply. Each call carries everything before it, so the history takes more of the window with every turn:

Models Are Stateless: Every Call Sends It All
A model keeps nothing between calls. OpenAI's page: "each text generation request is independent and stateless". Anatomy of an LLM API Call (Messages, Roles, Params) showed what that means for a chat: your app keeps the conversation and sends all of it with every call, and the model reads it all again each time.
Two things follow, and the lab measured both on the chat in the figure:
- Every call is bigger than the one before. Question 1 sent 36 tokens and question 20 sent 1,013. Over those 20 calls the model read 10,557 tokens, 10.3 times the 1,024 tokens the chat itself held by then: the early turns are sent, and read, again on every later call. Understanding API Pricing (Token Math) turns that into money.
- Sooner or later a call does not fit. Question 21 needed 1,069 tokens in a window of 1,024. Then the call is refused, or the oldest messages are left out of it and the model no longer sees how the chat began.
Keeping the conversation on the provider's servers does not change what the model reads. OpenAI's page says that even when a call names the response before it (previous_response_id), "all previous input tokens for responses in the chain are billed as input tokens in the API".
How Big Is the Window? (November 2026)
Windows have grown fast. As each maker's own page gave them on 21 November 2026:
| Model | Context window | Longest reply |
|---|---|---|
| Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 | 1M tokens | 128K tokens |
| GPT-6.2 Sol | 1,050,000 tokens | 128,000 tokens |
| Gemini 4 Carbon, Neon, Hydrogen and Argon | 1M tokens | see below |
| Llama 4 Scout | 10M tokens | not listed |
| Llama 4 Maverick | 1M tokens | not listed |
Three things to see in it:
- The reply has its own, smaller cap. A window of a million tokens does not mean a reply of a million: Claude's and GPT-6.2 Sol's longest reply is 128K tokens, and GPT-6.2 Sol's page lists "Maximum input tokens: 922,000", its window less that reply. Gemini 4's page lists its longest reply as "64K / 1M tokens".
- Older models had far smaller windows. GPT-2's paper raised the context "from 512 to 1024 tokens" in 2019, and GPT-3's models used "a context window of nctx = 2048 tokens" in 2020.
- A local model gets the window you give it. Ollama's FAQ: "By default, Ollama uses a context window size of 4096 tokens." You raise it with
OLLAMA_CONTEXT_LENGTHfor the server, or withnum_ctxin a chat or a request.
For scale: the prose of the 280 lessons of the seven AI Engineering courses comes to 925,215 tokens with GPT-2's tokenizer, close to one window of a million tokens.
What Happens When a Call Does Not Fit
Over the window, a call meets one of two ends, and the providers document both.
The call is refused. When the input alone is over the window, Anthropic's page says "the API returns a 400 invalid_request_error (“prompt is too long”) on every model". OpenAI's Responses API does the same by default: with its truncation setting at disabled, "If the input size will exceed the context window size for a model, the request will fail with a 400 error."
The oldest messages are left out. With truncation set to auto, OpenAI's API "will truncate the response to fit the context window by dropping items from the beginning of the conversation", and "On some models, trimming can begin earlier because the API subtracts the model's maximum output allowance from its input limit". Chat apps can do the same on their side: Anthropic notes that chat interfaces such as claude.ai "can also manage the context window on a rolling “first in, first out” basis". What is left out does not exist for the model: it cannot use text it cannot see. That is why a long chat seems to forget how it began.
A third case lies between them: the input fits, but not with the room you asked for the reply (max_tokens). Anthropic's page: "On Claude 4.5 models and newer, if input tokens plus max_tokens exceeds the context window size, the API accepts the request." If the reply then reaches the window's end, it stops there, with a stop reason that says so; earlier Claude models refuse such a call with a validation error.
And a window that fits is not a window used evenly. In the paper Lost in the Middle (Liu and others, 2023), models did best "when relevant information occurs at the beginning or end of the input context", and their performance "significantly degrades when models must access relevant information in the middle of long contexts". Context Length: Long-Context Models & Their Limits takes this further.
Why This Matters for You
- It bounds what you can send. A whole document, a long chat, a codebase: count its tokens before you count on it fitting.
- It drives cost and time. Every token in the window is read on every call, and input tokens are billed: a long chat costs more with every turn. Understanding API Pricing (Token Math) does the arithmetic.
- Long chats need managing. Real apps leave out or summarize old turns, and for long conversations Anthropic's page calls server-side compaction "the primary strategy for context management". Managing the Context Window (Selection & Compression) and What Is Context Engineering? (The 2026 Shift) build on this.
- Leave room for the reply. The reply is written in the same window: set
max_tokensto what the reply needs, and keep the input small enough to leave it. - Count before you send. Anthropic's token counting endpoint is "free to use" and counts "under the tokenizer of the
modelyou pass", and for a move to a model with a new tokenizer its advice is "don’t reuse token counts measured on the older model".
Try It Yourself: Fill the Context Window
The chat from the figure is yours to send, all 100 of its questions. Press Send question 1, or Ten questions at a time, and watch each call fill the window: the system prompt, every earlier question and answer, the new question, and the reply written into its room. The bars under it are what each call sent, and the count beside them is what the model has read in all.
- Keep going under Send it all until a call is refused, then give the same question a bigger window: 1,024 tokens is GPT-2's window, 2,048 GPT-3's and 4,096 Ollama's default.
- Switch to Drop the oldest and watch the first messages slide out of the window while your app still holds them; switch back and send, and they all come back.
- Give the reply 512 tokens of room, and see the oldest leave sooner.
The windows are small on purpose, so the chat fills one within its hundred questions. Every count is GPT-2's tokenizer's, on the quiz's own text.

Mental-Model Corrections
- "The model remembers our conversation." No: it keeps nothing between calls. Your app sends the conversation again with every call.
- "Only my message counts toward the window." No: the system prompt, the whole history, your message, the reply and any thinking all share it.
- "A window of a million tokens means a reply of a million." No: the reply has its own cap, 128K tokens for Claude's current models and for GPT-6.2 Sol.
- "A token is three quarters of a word." For English, as a first guess: the AI Engineering courses' text measured 0.61 words a token with GPT-2's tokenizer, and Claude's current tokenizer fits about 555,000 words in a million tokens.
- "If it fits, the model uses all of it equally." No: models use the middle of a long context less well than its start and its end.
Key Takeaways
- Everything is measured in tokens: about 4 characters, or three quarters of a word, in English by the rule of thumb; a real count depends on the tokenizer and the text.
- The context window holds the whole call: the system prompt, the history, the new message and the reply.
- Models are stateless: every call sends the conversation again, so calls grow, cost more and in the end do not fit; then the call is refused, or the oldest messages are left out.
- In November 2026 the large models' windows are about 1M tokens (Llama 4 Scout's 10M), and a reply has its own cap (128K for Claude's current models and GPT-6.2 Sol); Ollama gives a local model 4,096 unless told otherwise.
- A window that fits is not used evenly: the middle of a long context is used least well.
Next: Understanding API Pricing (Token Math): how input and output tokens become money, and how to estimate a feature's cost.