Foundations Guide 03 of 25

Tokens, context windows and the economics of attention

A million-token window is a capacity limit, not a quality guarantee. Here is how tokens are counted and priced, and why attention gets costly and unreliable as context grows.

  • 9 min read
  • Updated 
  • 8 sources

Key takeaways

  • Tokens are model-specific. A newer tokenizer can turn the same text into about 30% more tokens, and some languages need several times more tokens than English.
  • A context window is a ceiling, not a guarantee. Published tests show accuracy slipping well before the limit, especially when the answer sits mid-context.
  • As of October 2026, OpenAI and Google double the input rate on flagship models above 272K and 200K tokens, and cached input costs 90–95% less.
  • Agents re-send their history every turn, so billed input tokens grow roughly with the square of the turn count while the window grows only linearly.
  • Budget context like memory: measure it on real traffic, cap it below the window, put stable content first, and test quality at your real lengths.
On this page 6 sections

Every request to a large language model (LLM) is counted in tokens. Tokens decide what a request costs, how long it takes, and whether it fits at all. As of October 2026, Anthropic’s Claude 4.6 and later models offer a one-million-token context window at standard per-token prices, according to Anthropic’s pricing documentation. By the same page’s sizing of an average web page, that is room for roughly 400 of them.

A number that big invites a tempting design: skip the retrieval pipeline, put everything in the prompt, and let the model sort it out. It works in the demo. In production it runs into three separate limits — the bill, the latency, and the model’s ability to actually use what it was given — and all three scale with tokens.

This guide explains what a token is, what counts against the window, and why attention gets expensive as context grows. It then covers what the published evidence says about quality at length, and how to budget context as the scarce resource it is.

What is a token?

Models don’t read characters or words. A tokenizer first splits text into pieces from a fixed vocabulary, and the model only ever sees the integer identifiers of those pieces. Most modern tokenizers use byte-pair encoding (BPE) or a related subword scheme; BPE starts from bytes or characters and repeatedly merges the most frequent neighboring pairs in its training text into new vocabulary entries. Common words become single tokens; rare words, identifiers, and long numbers are split into several.

The familiar rule of thumb — about four characters, or three-quarters of an English word, per token — appears in the questions section of Anthropic’s pricing page. The same page estimates an average 10 kB web page at about 2,500 tokens and a 500 kB research paper at about 125,000. Treat these as napkin math for English prose. Three things break them in practice:

  • Tokenizers differ by model, even within one vendor. Anthropic says the newer tokenizer in its Claude 4.7 and later models turns the same text into about 30% more tokens, with the exact figure depending on content (Anthropic). So a lower price per token does not guarantee a lower price per task. At October 2026 list prices, Claude Opus 5.5’s $4 input rate undercuts Opus 4.6’s $5 per million tokens, but 30% more tokens can erase the gap.
  • Languages differ sharply. A University of Oxford study found that the tokenizer then behind ChatGPT and GPT-4 needed about 1.6 times as many tokens for Italian as for English. The ratio was 3 times for Arabic and up to 15 times for Shan (Petrov et al., 2023). That premium raises cost and latency and shrinks how much fits in the window.
  • Format changes the count. Markup, whitespace, JavaScript Object Notation (JSON) keys, and code identifiers all consume tokens, and symbol-heavy text often departs from the prose ratio. The same facts can cost noticeably more as verbose markup or JSON than as plain sentences.

The practical rule: count with the provider’s own token counter, on your own data, per model and per language, before you set any budget.

What counts against the context window?

The context window is the maximum number of tokens a model can process in a single call, prompt and output together. It is working space, not memory. The model keeps nothing between calls, so whatever it should know must be inside the window on every request, even when a provider stores the conversation for you.

Everything in the request counts, which surprises most teams the first time they inspect real usage:

  • the system prompt and standing instructions;
  • tool definitions, which travel with every call — declaring Anthropic’s browser toolset with its default tools costs roughly 6,600 input tokens on each request (Anthropic);
  • conversation history, retrieved documents, images, and tool results;
  • everything the model writes back, including hidden reasoning, which Google’s price sheet bills as output.

Window sizes have grown fast. In research tests for its 2024 Gemini 1.5 report, Google found retrieval stayed near-perfect, above 99%, out to at least 10 million tokens (Gemini team, 2024). As of October 2026, OpenAI, Google, and Anthropic all sell requests well beyond 200K tokens. The window, though, is a hard ceiling — not a promise about what the model does near it.

Why does long context cost more? The economics of attention

The cost curve comes from the Transformer’s core operation. When the model reads a prompt, a phase called prefill, every token attends to every token before it. In standard full attention, that part of the work grows with the square of the length: double the prompt and attention does roughly four times the work. At short lengths the rest of the network dominates the compute; at hundreds of thousands of tokens, attention typically does.

Generation adds a memory cost. To produce each new token, the model reads stored keys and values for every earlier token, a structure known as the key-value (KV) cache. That cache grows linearly with context and lives in scarce graphics processing unit (GPU) memory. A 500K-token request ties up memory that could otherwise serve many short requests at once, and its long prefill delays the first token of the reply.

Price sheets reflect these costs, though not uniformly. Here are representative rates per million tokens as of 6 October 2026, standard tier:

ModelInput / outputAbove the long-context thresholdCached input (short context)
OpenAI gpt-6-astra$10 / $50 up to 272K input tokens$20 / $75$1.00
OpenAI gpt-6.1-sol$2 / $10 up to 272K input tokens$4 / $15$0.10
Google Gemini 3.1 Pro Preview$2 / $12 up to 200K tokens$4 / $18$0.20, plus $4.50 per million tokens per hour of storage
Anthropic Claude Opus 5.5$4 / $20No surcharge up to 1M$0.20
Anthropic Claude Sonnet 5.5$2 / $10No surcharge up to 1M$0.20

Sources: OpenAI, Google, and Anthropic price pages. Three patterns matter more than any single number:

  1. Output is the expensive side. At the short-context rates above, output costs five to six times as much as input. Verbose answers and long reasoning add up quickly.
  2. Long-context surcharges are cliffs, not slopes. On OpenAI’s and Google’s sheets, a request past the threshold is billed at the higher rate: double for input, 1.5 times for output. On Gemini 3.1 Pro Preview, growing a prompt from 190K to 210K tokens adds about 10% more tokens but more than doubles its input cost. Anthropic’s flat pricing removes the cliff, not the latency or quality costs.
  3. Reuse is the real discount. Prompt caching keeps the processed state of a repeated prefix, so later requests skip most of the prefill. Cached input is 90–95% cheaper in every row. Writing to the cache costs extra — 1.25 times the input rate for Anthropic’s five-minute cache and on OpenAI’s newest models — and Google adds an hourly storage charge.

Agent loops multiply everything

Agents make token economics nonlinear. Each turn re-sends the system prompt, the tool definitions, and the entire history, then appends new tool results. Billed input therefore grows roughly with the square of the number of turns, even though the window only grows linearly.

# Input tokens billed by an agent that re-sends its
# history every turn. base = prompt + tools.
base, per_turn, turns = 10_000, 5_000, 40
billed = sum(
    base + per_turn * t for t in range(1, turns + 1))
window = base + per_turn * turns
print(f"{window:,} in the window, {billed:,} billed")
# 210,000 in the window, 4,500,000 billed

At Claude Sonnet 5.5’s $2 per million input tokens, that run costs $9.00 in input alone. With caching, each turn reads the earlier prefix at $0.20 per million and writes only its new tokens at $2.50 per million, so the same run’s input costs about $1.38. That assumes every turn lands inside the five-minute cache lifetime (Anthropic).

One design consequence follows. Caching rewards an append-only history, while pruning or rewriting an earlier turn invalidates everything cached after it. Compact context in occasional large steps rather than small edits on every turn.

Does quality hold up as context grows?

Fitting is not the same as using. Many headline long-context results come from needle-in-a-haystack tests: hide one fact in a long document, then ask for it. The Gemini 1.5 figure above is of this kind. Real tasks are harder in three ways the research has documented.

Position matters. In the 2023 “Lost in the Middle” study, led by Stanford researchers, models often did best when the relevant document came first or last, and worst when it sat mid-context (Liu et al., 2023). For GPT-3.5-Turbo, burying the answer mid-context could cut accuracy by over 20%. At the worst positions it scored below its own no-documents baseline of 56.1%, with only a few thousand tokens of input.

Literal matching flatters the benchmarks. NoLiMa, a benchmark from Adobe Research and Ludwig Maximilian University of Munich, rebuilt the needle test so the question and the hidden fact share almost no wording (Modarressi et al., 2025). Of 13 models claiming windows of at least 128K tokens, 11 fell below half their short-context score by 32K tokens. GPT-4o, among the best performers, still slid from 99.3% to 69.7%.

Every extra token is a potential distraction. Chroma’s “Context Rot” report of 14 July 2025 tested 18 models, including GPT-4.1, Claude 4, Gemini 2.5, and Qwen3 (Hong et al., 2025). Reliability fell as inputs grew, even on simple retrieval and copying tasks; one plausible-but-wrong passage lowered accuracy, and four compounded the damage. On a conversational-memory benchmark, models did consistently better with a focused prompt of about 300 tokens than with the full 113K-token history.

These studies tested models from 2023 to mid-2025 that have since been superseded, so their exact numbers will not carry over to today’s frontier models. The direction of the evidence is consistent, though: accuracy starts slipping well before the advertised limit, and how fast depends on the task. Treat the window as capacity, and treat your own evaluation at realistic lengths as the only quality guarantee.

Long context or retrieval: when should you fill the window?

Long context and retrieval-augmented generation (RAG) are not rivals; they answer different questions. Long context is about how much the model can consider at once. Retrieval is about choosing what deserves its attention.

SituationLean toward
One bounded body of material — a contract set, a code module, a long transcript — that needs reasoning across its partsLong context, with the material cached
A large or fast-changing corpus queried many times a dayRetrieval, then a modest context
Answers must cite sources or respect per-user access rulesRetrieval, so you control what enters the window
One-off analysis where engineering time costs more than tokensLong context
High-volume, latency-sensitive trafficRetrieval and a small window

Our default in production is to retrieve generously, rerank, and pass tens of thousands of well-chosen tokens rather than hundreds of thousands of unfiltered ones. The big window is headroom for the cases where retrieval misses. It should not be the plan.

What this means for your team

  1. Measure tokens on real traffic. Log input, cached, and output tokens per call, per feature, and per model. Rules of thumb are fine for estimates, not for budgets.
  2. Set a context budget well below the window. Choose a working ceiling for each feature from evaluation, not the spec sheet. Run your evals at several lengths, such as 8K, 32K, and 128K tokens, and plot quality against length.
  3. Order context for caching and attention. Put stable material — instructions, tool definitions, reference documents — first so it caches, and volatile material last. Keep the question and critical instructions at the start or end, where the position research shows models do best.
  4. Watch the price cliffs. On a tiered price sheet, alert when requests approach the 200K or 272K threshold.
  5. Prune agent context deliberately. Drop stale tool results and summarize finished subtasks, in batches that preserve cache hits. Our context engineering guide covers the techniques.
  6. Re-benchmark on every model switch. A new tokenizer changes cost, latency, and usable capacity at once. Compare cost per completed task, not price per token.
  7. Test every language you serve. Token premiums become higher bills, slower responses, and less usable context for non-English users.

A token budget is the cheapest reliability feature you can buy: shorter, better-ordered context costs less, answers sooner, and often scores higher. When SurgeX Labs builds retrieval and agent systems, the budget for each call is written down before the first prompt.

Sources

  1. Lost in the Middle: How Language Models Use Long Contexts (opens in new tab) — Stanford University, UC Berkeley and Samaya AI (TACL, arXiv), 2023 arxiv.org

  2. Language Model Tokenizers Introduce Unfairness Between Languages (opens in new tab) — University of Oxford (NeurIPS 2023, arXiv), 2023 arxiv.org

  3. Gemini 1.5: Unlocking multimodal understanding across millions of tokens of context (opens in new tab) — Gemini Team, Google (arXiv), 2024 arxiv.org

  4. NoLiMa: Long-Context Evaluation Beyond Literal Matching (opens in new tab) — LMU Munich and Adobe Research (ICML 2025, arXiv), 2025 arxiv.org

  5. Context Rot: How Increasing Input Tokens Impacts LLM Performance (opens in new tab) — Chroma, 2025 trychroma.com

  6. Pricing (opens in new tab) — Anthropic (Claude Platform Docs), 2026 platform.claude.com

  7. Pricing (opens in new tab) — OpenAI (OpenAI API docs), 2026 developers.openai.com

  8. Gemini Developer API pricing (opens in new tab) — Google AI for Developers, 2026 ai.google.dev

Where this shows up in our work

Building this? Talk to an engineer.

If this guide maps to a system you’re planning, send a short brief. A senior engineer replies within one business day.