Context Window

What is Context Window?

A context window is the maximum number of tokens a language model can consider at once, covering its instructions, the conversation so far, any supplied documents and the response it generates.

Updated November 2026 · 2 min read


A context window is the maximum number of tokens a language model can consider at once, or how much it can hold in mind for a single response. Everything the model considers for a response has to fit: the system instructions, the conversation so far, any documents or search results, tool definitions and the answer it is writing. Anything beyond the limit must be left out, summarized or handled in another way.

Context windows have grown dramatically. Early large language models around 2020, such as GPT-3, could handle about 2,000 tokens, a few pages of text. By 2024, models such as Google's Gemini 1.5 accepted a million tokens or more, enough for several long books. That growth has made it possible to analyze whole contracts, codebases or document collections in a single request.

Is a bigger context window better?

  • Cost: every token in the context is billed on every request. Filling a large window costs far more than sending only what is relevant. Some providers also charge higher per-token rates once a prompt passes a threshold, such as 200,000 tokens.
  • Speed: longer inputs take longer to process, increasing time to first response.
  • Quality: models do not use all of a long context equally well. Research published in 2023 under the title "Lost in the Middle" found that models were better at using information near the beginning or end of long inputs than in the middle. Newer models have improved, but performance on long contexts still varies.
  • Effective vs. advertised length: a model may accept a million tokens but reason reliably over far fewer.

How to manage context window limits

An example

Consider a hypothetical law firm that builds an assistant to answer questions about a client's contracts. The first version puts all 300 contracts, about 900,000 tokens, into a model with a million-token window for every question. Each question costs several dollars, takes over a minute and sometimes misses clauses buried in the middle. The second version indexes the contracts, retrieves the 20 most relevant passages for each question, around 15,000 tokens, and cites them in the answer. Cost per question falls by about 98%, responses arrive in seconds and accuracy on the firm's test questions improves.

Common pitfalls

  • Filling the window because it is there.
  • Letting conversations grow until they hit the limit and fail.
  • Trusting long-context answers without testing how well the model uses that context.

The memory used to process long contexts is covered in KV cache, and the tokens themselves in AI tokens.

Frequently asked questions

Is a larger context window always better?

No. Every token in the context window is billed on every request, longer inputs slow the first response, and models do not use all of a long context equally well. A model may accept a million tokens but reason reliably over far fewer. Sending only the relevant material usually costs less and often gives better answers.

How do you work within a model's context window limit?

Retrieve only the most relevant passages instead of sending whole documents, summarize older conversation turns and trim boilerplate and unused tool results. Cache repeated context to lower its cost, and design what goes into the context for each step. See retrieval-augmented generation.

What is the lost in the middle problem with long context windows?

Research published in 2023 under the title "Lost in the Middle" found that language models used information near the beginning or end of long inputs better than information in the middle. Newer models have improved, but long-context performance still varies, so test how well a model uses a full context window before relying on it.