Skip to content
Cosvexa – Cosvexa home

Research · Foundations

What is a context window?

A context window is the maximum amount of text, measured in tokens, that a language model can take into account at once when producing a response. It covers everything the model sees in a request: system instructions, the conversation so far, attached documents, tool results and the reply being written. Anything outside the window is invisible to the model unless the application puts it back in.

Cosvexa team · Published

Abstract editorial illustration of a long scroll of text passing behind a bright rectangular frame, with only the section inside the frame clearly lit.

Key points

  • The context window is the model's working memory for one request, measured in tokens.
  • Instructions, history, documents, tool output and the reply all count toward it.
  • Windows grew from about 2,000 tokens (GPT-3, 2020) to hundreds of thousands or more in some current models.
  • Longer contexts cost more compute and memory, and models do not use every part equally well.
  • Applications manage the window with truncation, summaries and retrieval.

What a context window is

A large language model has no memory between requests. Every time it generates a reply, it works only from the sequence of tokens it is given in that request. The context window, also called context length, is the upper limit on how long that sequence can be. A model with a 128,000-token window can attend to at most 128,000 tokens of input and output combined in a single request, depending on how the provider counts the reply.

A helpful analogy is a desk rather than a filing cabinet. The model's trained parameters are like long-term knowledge; the context window is the desk on which the current task is laid out. Everything the model needs to see right now has to fit on the desk. When a chat app appears to "remember" an earlier message, that is because the app sent the earlier message again as part of the context.

What counts toward the window

Part of the requestExampleCounts toward the window?
System promptInstructions about tone, rules, tools availableYes
Conversation historyEarlier user messages and model repliesYes, as far as the app includes them
Attached contentDocuments, pasted code, transcribed audio, images converted to tokensYes
Tool calls and resultsSearch results, database rows, code outputYes
Reasoning tokensHidden intermediate reasoning in some reasoning modelsUsually yes, while the reply is generated
The replyThe tokens the model writesYes; many APIs also set a separate maximum for output

A worked example

Suppose a model has a 128,000-token window and you ask it to review a long contract. The application's system prompt uses 2,000 tokens. The contract, once tokenized, is 95,000 tokens. Earlier messages in the conversation add 15,000 tokens. That leaves roughly 16,000 tokens for the reply and any tool results, which is plenty for a detailed review. If you then attach a second contract of similar length, the total no longer fits. The application must drop or summarise something, such as older messages, or the request will fail with a context-length error. Note that the same contract can produce different token counts on models with different tokenizers, and text in some languages, such as Turkish, usually takes more tokens than the same content in English.

Why context windows are limited

  • Attention cost. In standard attention, every token is compared with every other token, so the computation grows roughly with the square of the sequence length. Efficient kernels reduce memory use and speed things up, but the basic scaling remains.
  • Memory for the KV cache. During generation, the model stores keys and values for every token in the context. This KV cache grows linearly with context length and with model size. With long contexts and many requests served at once it can take more accelerator memory than the model's weights: Pope et al. (2022) give an example of a very large model whose KV cache was three times the size of its parameters.
  • Training. A model must be trained, or at least adapted, on long sequences to use them well. Long training sequences are expensive and long, high-quality documents are relatively scarce.
  • Position handling. Transformers need positional information. Models trained on short sequences often degrade sharply on longer ones unless their positional scheme is designed or adjusted for it.

How context windows grew

Early transformer language models had short windows: GPT-2 (2019) handled 1,024 tokens and GPT-3, described by Brown et al. in 2020, 2,048 tokens. Since then, windows have grown by orders of magnitude. Several current commercial models accept hundreds of thousands of tokens, and some accept a million or more, enough for whole books or large codebases in one request. Exact limits change often and differ by model and provider, so the model's documentation is the place to check.

Several techniques made this growth possible:

  • Better positional encodings. Rotary position embeddings (RoPE, Su et al., 2021) encode relative position in the attention computation and can be stretched. Chen et al. (2023) showed that interpolating positions lets a model trained on shorter sequences be extended to much longer ones with relatively little extra training.
  • Efficient attention kernels such as FlashAttention, which compute exact attention without storing the full attention matrix.
  • Smaller KV caches through grouped-query or multi-query attention and quantised caches.
  • Architectural variants such as sliding-window attention in some layers, or hybrids that mix attention with linear-time layers.
  • Long-context training stages, in which a pretrained model is further trained on long documents.

Advertised versus effective context

Fitting text in the window is not the same as using it well. Liu et al., in "Lost in the Middle" (2023), tested models on multi-document question answering and key-value retrieval. They found that performance was often highest when the relevant information was at the beginning or end of the input and dropped when it was in the middle. Later benchmarks such as RULER (Hsieh et al., 2024) went beyond simple "needle in a haystack" tests, which ask a model to find one inserted fact, and reported that many models' performance declined well before their advertised maximum length on harder tasks such as tracing variables or aggregating information.

Newer models have improved on these tests, but the lesson stands: a long window is capacity, not a guarantee. Practical tips follow from it.

  1. 1

    Put instructions where they are seen

    State the task clearly, and for very long inputs consider repeating the key question after the material as well as before it.

  2. 2

    Include what matters, not everything

    Irrelevant text consumes tokens, adds cost and can distract the model. Select the relevant sections when you can.

  3. 3

    Structure long inputs

    Use headings, document labels or tags so the model can tell sources apart and cite them.

  4. 4

    Check on your own task

    Test whether the model actually uses information from deep inside your typical documents before relying on it.

How applications manage the window

Chat applications and agents run into the limit in long sessions. Common strategies include dropping the oldest messages (a sliding window), replacing old turns with a running summary, storing facts in a separate memory and re-inserting only the relevant ones, and fetching passages on demand with retrieval-augmented generation. Choosing between stuffing everything into a long context and retrieving selectively is a real design decision with trade-offs in cost, latency and accuracy, covered in long context vs RAG.

Why the context window matters

The window determines what kinds of tasks a model can do in a single pass: summarising a full report, answering questions across many files, reviewing a long code change, or keeping a long agent session coherent. It also drives cost and speed. Providers typically charge per input token, so a request that fills a large window costs much more than a short one, and the time to the first output token grows with input length. Caching repeated context, such as a long system prompt or a document asked about repeatedly, is one way providers reduce that cost.

Context windows vary widely between models. Cosvexa's Models pages list the context window of each model in its catalog where it is known, which helps when a task involves long documents.

Common misconceptions

  • "The context window is the model's memory of me." It is only the current request. Persistent memory features are built by the application, which stores information and puts selected parts back into the context.
  • "Bigger is always better." A larger window helps only if you need it. Filling it adds cost and latency, and the model may use the middle of very long inputs less reliably.
  • "Window size equals maximum answer length." Many providers set a separate, smaller limit on output tokens. A model with a very large window may still cap a single reply far lower.
  • "Words and tokens are the same." Limits are in tokens, and the ratio of tokens to words depends on the tokenizer and the language.

Where context windows are going

Windows will probably keep growing, but research attention is shifting from raw length to effective use: models that reason reliably over everything they are given, benchmarks that measure this honestly, and cheaper ways to serve long contexts through cache compression and alternative architectures. At the same time, agent systems increasingly treat the window as a resource to manage, deciding what to load, summarise or forget at each step.

Frequently asked questions

What happens when a conversation exceeds the context window?

The model cannot see anything beyond its limit. Depending on the application, the oldest messages are dropped, earlier turns are summarised, or the request is rejected with an error. This is why very long chats can seem to forget their beginning.

Is a bigger context window always better?

Not necessarily. It lets you include more material, but each extra token adds cost and latency, and research has found that models do not always use information in the middle of long inputs reliably. Retrieving only the relevant parts is often cheaper and can be more accurate.

How many words fit in a 128,000-token context window?

For typical English prose, roughly 90,000 to 100,000 words, using the rule of thumb of about four characters per token. Code, numbers and many other languages use more tokens per word, so less fits.

Does the model's answer count toward the context window?

Yes. The reply is generated inside the same window as the input, and many APIs also enforce a separate maximum number of output tokens. Some reasoning models also use hidden reasoning tokens that count while they are generated.

Is the context window the same as the training data cut-off?

No. The context window limits how much text the model can consider in one request. The training cut-off is the date after which the model's built-in knowledge stops. They are unrelated settings.

References

  1. Nelson F. Liu, Kevin Lin, John Hewitt, Ashwin Paranjape, Michele Bevilacqua, Fabio Petroni and Percy Liang (2023). Lost in the Middle: How Language Models Use Long Contexts
  2. Cheng-Ping Hsieh et al. (2024). RULER: What's the Real Context Size of Your Long-Context Language Models?
  3. Jianlin Su, Yu Lu, Shengfeng Pan, Ahmed Murtadha, Bo Wen and Yunfeng Liu (2021). RoFormer: Enhanced Transformer with Rotary Position Embedding
  4. Shouyuan Chen, Sherman Wong, Liangjian Chen and Yuandong Tian (2023). Extending Context Window of Large Language Models via Positional Interpolation
  5. Tom B. Brown et al. (2020). Language Models are Few-Shot Learners
  6. Reiner Pope et al. (2022). Efficiently Scaling Transformer Inference

More in this section

Start free: 50 Cosvexa-1 questions a day

Every major model in one workspace; on the Free plan Cosvexa-1 answers 50 questions a day. No card needed to start.