- Gestión automatizada de sesiones
- Dirígete a cualquier ciudad de 195 países
- Sesiones simultáneas sin límite
Context Window
TLDR: A context window is the maximum amount of text, measured in tokens, that a language model can consider in a single request. It covers the input and the generated output together.
The context window is a hard architectural limit. Everything the model can reason about in one call must fit inside it: system instructions, conversation history, retrieved documents, the current question, and the response being generated. When the limit is reached, something has to be removed, and what gets removed determines what the model can no longer see.
What Consumes the Window:
- System prompt: Instructions, role definitions, formatting rules, and tool descriptions, all present on every request.
- Conversation history: Prior turns, which accumulate continuously in a multi turn session.
- Retrieved context: Documents injected by a retrieval system, usually the largest and most variable component.
- Current input: The user’s immediate request.
- Output: Reserved space for the response, which cannot exceed what remains.
The last point is often overlooked. A request that fills 98 percent of the window leaves almost no room for an answer, and the model will truncate mid sentence rather than refuse.
Tokens, Not Words:
Windows are measured in tokens, which are subword units rather than words or characters. Common English words are typically one token. Rare words, technical terms, and names split into several. Whitespace, punctuation, and formatting all consume tokens.
For English prose, a rough working figure is around 0.75 words per token, though this varies by tokenizer and by text type. Code, JSON, and heavily formatted markup tokenize far less efficiently than plain prose, which is a direct reason to strip markup before sending content to a model.
For accurate counts, use the tokenizer that matches the target model rather than estimating. Estimation errors compound badly in pipelines that batch many documents.
What Happens at the Limit:
| Handling | Behavior | Risk |
|---|---|---|
| Hard error | Request is rejected | Visible failure, easy to handle |
| Truncate oldest | Earliest history is dropped | Model forgets earlier instructions |
| Truncate newest | Recent input is cut | The actual question may be lost |
| Summarize history | Older turns compressed | Detail loss, added latency and cost |
| Drop retrieved context | Fewer documents included | Answer loses grounding |
Silent truncation is the dangerous case. The model still answers, the answer still reads fluently, and nothing in the response indicates that half the supporting material was removed before it was generated.
Budgeting the Window:
def build_prompt(system, history, documents, question, limit):
reserved_output = 1000
budget = limit - reserved_output
used = count_tokens(system) + count_tokens(question)
budget = budget - used
# Documents get priority over old conversation turns
included_docs = []
for doc in documents:
cost = count_tokens(doc)
if cost > budget:
break
included_docs.append(doc)
budget = budget - cost
# Fill remaining space with history, most recent first
included_history = []
for turn in reversed(history):
cost = count_tokens(turn)
if cost > budget:
break
included_history.insert(0, turn)
budget = budget - cost
return assemble(system, included_history,
included_docs, question)
Output space is reserved first, then components are added in priority order. Which component holds priority is a design decision: retrieval heavy applications favor documents, conversational applications favor history.
Larger Windows Are Not a Solution:
Model context windows have grown substantially, and the growth makes some problems disappear. It does not make context management unnecessary, for three reasons.
Cost scales with usage. Filling a large window on every request multiplies the price of every call, whether or not the extra content was useful.
Latency scales with input. More input means slower responses, which matters in interactive applications.
Attention is uneven. Published research has repeatedly found that models attend more reliably to information at the beginning and end of long inputs than to material buried in the middle. Placing critical content in a large window does not guarantee it will be used.
The practical consequence is that selecting the right context remains more valuable than supplying more of it, which is the subject of context engineering.
Context Windows and Web Data:
Web content is the component most likely to overflow a window, and the one most responsive to preparation.
A raw HTML page can consume a large fraction of a window in markup alone. Converting through HTML to Markdown and applying boilerplate removal typically reduces that by an order of magnitude, and document chunking then allows only the relevant portion to be retrieved rather than the whole page.
Bright Data’s Crawl API and Search and Extract return pre cleaned Markdown, which removes most of the avoidable token overhead before content reaches the model.