Context Window

A context window is the maximum amount of input and output, measured in tokens, that a language model can process in a single request, including instructions, conversation history, documents and its reply.

Also known as: Context length, context size

Related terms in this glossary

How it works

Everything the model sees in a request counts against the window: the system prompt, tool definitions, prior messages, retrieved documents, images and the answer it generates. Anything beyond the limit must be dropped, summarized or retrieved on demand. Window sizes have grown fast. Current frontier models from Anthropic, OpenAI and Google offer windows from a couple of hundred thousand tokens to a million or more, depending on the model; check each provider's model page, since limits change between versions.

  • Output length has its own, smaller cap.
  • Longer inputs cost more and take longer, since pricing and latency scale with tokens.
  • Providers may price very long prompts at a higher rate.

Why it matters

A large window lets a model read a full contract, a codebase or a long support history in one pass. It does not guarantee the model uses all of it well. Research such as Lost in the Middle (Liu and colleagues, 2023) found that models retrieve information less reliably from the middle of long inputs, and quality can degrade as context fills with loosely relevant material. For most business applications the better approach is context engineering: retrieve only what the task needs, summarize old conversation turns, and keep instructions near the top. Long windows then serve as headroom rather than a dumping ground. Prompt caching can reduce the cost of re-sending large, stable context. See AI cost optimization.

Context Window in depth

Planning a context budget

Treat the context window as a budget you allocate deliberately. For each request type, list what goes in and roughly how many tokens each part uses:

  • System instructions and policies
  • Tool definitions (agents with many tools can spend a large share here)
  • Conversation history or agent step history
  • Retrieved documents or records
  • Room reserved for the model's output and any reasoning tokens

Measure these with the provider's token counting endpoint or tokenizer rather than estimating from word counts, especially for Hindi and other Indic scripts, which often use more tokens per word than English.

Example: a long-running support conversation

Example: a hypothetical support agent handles a customer who has been messaging for several days about a delayed replacement. Sending the full history every turn would grow cost and latency with each message and push early details into the middle of a long prompt. Instead the application keeps the last several turns verbatim, a running summary of earlier turns that records key facts (order number, promised dates, what was already tried), and fresh lookups from the order system on each turn. The stable system prompt and tool definitions sit at the start so prompt caching can reuse them.

Context engineering techniques

TechniqueUse it when
Retrieval instead of stuffingThe knowledge base is larger than a few documents; see RAG
Summarizing old turnsConversations or agent runs are long
Tool result trimmingAPIs return large payloads; keep only fields the task needs
Loading tools on demandAn agent has many tools but uses few per task
Sub-agents with fresh contextA sub-task needs heavy reading; return only its conclusion
OrderingPut instructions and the question where the model attends well, not buried mid-prompt

How to test long-context behavior

Do not rely on the advertised limit. Build evaluation cases where the needed fact sits at different positions and amounts of context, and check accuracy as the prompt grows. Measure cost and time to first token at each size. Often a retrieval approach with a smaller context matches or beats a full-document approach on accuracy while being faster.

Record token counts for each part of the prompt on every request, not just the total. When cost or latency rises, this breakdown shows immediately whether history, tool definitions or retrieved documents grew, which turns a vague complaint into a specific fix.

Common mistakes

  • Sending entire documents "because the window is big enough", then paying for it on every request.
  • Silent truncation: the application cuts history at the limit without telling anyone, and the model loses the customer's original problem.
  • Forgetting that output and reasoning tokens share the same window.
  • Assuming the same limits and behavior after switching models or versions.

The context window is measured in tokens, filled through chunking and retrieval, and shaped by prompt engineering. Our agent running cost estimator shows how context size drives spend. We design context strategies in AI cost optimization and AI-powered search.

Questions about Context Window

Something else? Send us your question and an engineer replies with next steps.

Does a bigger context window remove the need for RAG?

Not for most business systems. A large window lets you include more material, but every token is paid for and processed on every request, so sending a whole knowledge base each time is slow and wasteful. Models also use very long inputs less reliably than short, focused ones. Retrieval selects the few passages that matter and supports access control, freshness and citations. Long windows are most useful as headroom, for example reading one long contract in full, rather than as a replacement for retrieval.

What happens when a conversation exceeds the context window?

The API rejects requests that are too long, so the application must decide what to drop before that happens. Simple systems cut the oldest messages, which can lose important early details. Better designs summarize older turns into key facts, keep recent turns in full and fetch current data from systems of record on each turn. Some agent frameworks also compact their history automatically. Whatever the method, test it on long conversations, because this is where assistants often start repeating questions or forgetting commitments.

Articles that mention Context Window

All articles

Jump to

↑↓ to move↵ to open