What are tokens and context windows? Why does AI "forget" and how are costs calculated

December 5, 2026

Updated:

Guide
What are tokens and context windows? Why does AI "forget" and how are costs calculated

What is a Context Window?

A context window is all the text that a language model can reference when generating a response, including the response itself; a token is the small unit the model uses to count this text. According to Anthropic's "Context windows" documentation (read on 25/10/2026), this window is the "working memory" of the model, different from the training data repository, and for some models can reach up to 1 million tokens depending on the model. This post explains what tokens and context windows are, what counts toward the window, why AI "forgets", how to estimate costs, and OPCAIOS's experience.

Diagram of context window: system prompt, tools, history, documents and response all occupy the window; tokens in and out are charged; how to handle when about to fill
Everything in the request, plus the response, occupies the context window. Diagram: OPCAIOS.

What is a token?

A token is a unit of text the model processes, usually a piece of a word, a character, or punctuation rather than exactly one word. AI model pricing and limits are mostly calculated by tokens, so understanding tokens helps you estimate costs.

The number of tokens for the same text differs between models and between languages because each model has its own tokenizer; I don't give a fixed word-to-token ratio for Vietnamese since we haven't measured it. The sure way is to use the token counter from the provider; Anthropic has an API to count tokens to estimate before sending.

What is a context window and what does it include?

According to the documentation, everything in the request counts toward the window: system prompt, each message (including tool results, images, documents) and tool definitions. The part the model generates, including thinking content when reasoning mode is on, also counts.

The process each turn: input includes the entire history plus the new message; output is generated then becomes part of the input for the next turn. So the longer the conversation, the fuller the window. When a new message arrives, the model doesn't "remember" in the sense of storage; it reads the entire history sent along again.

Why does AI "forget" or give worse answers in long conversations?

Two reasons: the application may trim old history when about to fill up, and even if not trimmed, accuracy degrades as token count increases, a phenomenon Anthropic calls "context rot". More context doesn't automatically mean better.

The documentation also notes that the chat interface may manage the window in a "first in, first out" way, meaning old messages get pushed out. For a proper approach, see what is context engineering. "Forgetting" differs from AI hallucination: forgetting is losing input information, hallucination is generating wrong information.

Size limits and how to handle when about to fill

According to documentation read on 25/10/2026, some recent Claude models have 1 million token windows and a request can generate up to 128 thousand tokens of output; other models have 200 thousand windows. A request can include up to 600 images or PDF pages with large-window models. These numbers change by model and over time.

Situation How to handle (per documentation and practice)
Long conversation, about to fill Compression (compaction) server-side, or summarize yourself
Old tool results taking space Delete old tool results (context editing)
Input already exceeded window API returns error "prompt is too long"
Want to know request size beforehand Use token count API
Very large document Retrieve by section (RAG) instead of dumping everything

How is cost calculated by tokens?

Most providers charge separately for input tokens and output tokens, with output tokens usually more expensive; thinking tokens are counted like output. Anthropic's documentation says thinking tokens fall within the max_tokens limit and are charged like output tokens.

To reduce cost: shorten unnecessary context, use smaller models for simple work (choose AI model) and use prompt caching when many requests share the same part. Check specific prices on the provider's pricing page at the time of use; this post doesn't give a price table since it changes fast.

OPCAIOS's experience

We work with agents across many long sessions, so we treat the context window as a resource: important results are written to logs and status files for the next session to read back, rather than hoping the model remembers. The token counter and context compression by working tools handle themselves in many cases.

Limitation: we haven't measured token consumption by task type so we don't post numbers. We also don't rely on a blanket number like "how many words fit", because it depends on model and language. See what is LLM.

Frequently Asked Questions

How many characters equals one token?

It's not fixed; it depends on the model and language. Use the token counting tool from your provider to know exactly.

Does a 1 million token window remember everything?

Not guaranteed. Accuracy can degrade with long context (context rot), and costs are calculated by the number of tokens sent.

Do AI responses count toward the window?

Yes. According to the documentation, the output the model generates, including thinking content, also counts toward the window.

Why do two models report different token counts for the same content?

Because each model has its own tokenizer. Count using the tool from the model you're using.

How do I reduce token costs while maintaining quality?

Cut excess context, use the right model, and implement prompt caching. Need help optimizing your workflow? See AI application training service.

Source: Anthropic, "Context windows" documentation (platform.claude.com), accessed 25/10/2026; window size and pricing vary by model and time; haven't reviewed the detailed pricing page. No token-character ratio given for Vietnamese as it hasn't been measured. Experience is from OPCAIOS.

Translated from Vietnamese with AI. Read the original.

Want to apply this in your business?

Book a free 30-minute call (Vietnam time, in English or Vietnamese).

Book a call