Coderhouse goes global

🌍

Read more

What Is a Context Window and Why LLM Apps Hit Token Limits

AI Engineering

Build and ship real applications with LLMs, agents and automation.

8 weeks · Live online · View course →

Data Analytics

Go from zero to job-ready analyst with SQL, Python and BI tools.

10 weeks · Live online · View course →

Dan Patiño

AI Strategy & Innovation at Coderhouse

Artificial Intelligence

What Is a Context Window and Why LLM Apps Hit Token Limits

A context window is the maximum amount of text—measured in tokens—that a large language model can take into account in a single request. Everything the model “sees” at once has to fit inside it: the system prompt, the conversation history, any retrieved documents or tool results, and the answer the model is writing. Whatever falls outside the window simply does not exist for the model in that call.

Why it matters now: model providers keep advertising bigger windows, and many teams assume that means they can paste in entire knowledge bases and stop worrying. Research says otherwise. The well-known “Lost in the Middle” study found that models use information best when it sits at the beginning or end of the prompt and noticeably worse when it is buried in the middle (Liu et al.: Lost in the Middle). A later study showed that performance can drop by 13.9% to 85% as input length grows—even when the model can perfectly retrieve the relevant facts (Context Length Alone Hurts LLM Performance Despite Perfect Retrieval). Understanding the context window is the first step to building AI apps that stay accurate, fast, and affordable.

How a context window works

Language models do not read words; they read tokens, small chunks of text that are usually a few characters long. Every request is turned into a sequence of tokens, and the context window is the ceiling on how long that sequence can be, counting both input and output.

A typical request to an AI assistant or agent is built from several layers that all compete for the same space:

  • System prompt: instructions, rules, persona, and output format.

  • Conversation history: every previous user message and model reply that you choose to resend.

  • Retrieved context: documents or passages pulled in by search or RAG.

  • Tool definitions and results: the schemas of the tools an agent can call and the data those calls return.

  • The response: the tokens the model generates also count toward the limit.

Models are stateless between calls. What feels like “memory” in a chat app is the application resending the history each time, which is why long conversations eventually hit the limit or get trimmed.

What happens when you hit the limit

When a request is too long, one of a few things happens depending on the API and the app: the request fails with an error, the oldest messages are silently dropped, or the output gets cut off because there is no room left to generate. Each of these causes problems that look like “the model forgot” or “the answer stopped mid-sentence,” and they are easy to misdiagnose as model quality issues.

Bigger is not automatically better

A large window is a ceiling, not a target. Three practical costs grow with every token you add:

Accuracy

As prompts get longer, models are more likely to miss details, follow instructions less reliably, or get distracted by irrelevant material. Practitioners often call this gradual decline “context rot.” Anthropic’s engineering team describes context as a finite resource with diminishing returns and recommends finding the smallest set of high-signal tokens that gets the job done (Anthropic: Effective context engineering for AI agents).

Latency

The model has to process every input token before it starts answering, so long prompts mean slower first responses—a real problem for chat interfaces and multi-step agents.

Cost

Most APIs bill per input and output token. Resending a long history or a large document on every turn multiplies the bill. Techniques like prompt caching reduce the cost of repeated prefixes, but they do not fix the accuracy problem.

How teams manage the context window

  • Retrieve instead of stuffing: use RAG to send only the passages relevant to the question. Good chunking and reranking decide which passages make the cut.

  • Summarize or compact history: replace old turns with a short running summary so long conversations keep the important facts without the bulk.

  • Put critical information where models use it best: keep key instructions at the start and repeat the question or constraints near the end of long prompts.

  • Trim tool output: return only the fields an agent needs from an API or database query, not the full raw payload.

  • Use external memory: store facts, preferences, and task state outside the model and load them only when needed. Our guide on AI agent memory and state covers the main patterns.

  • Split work across sub-agents: give each subtask its own clean context and pass back only the result.

Together these practices are known as context engineering: deciding deliberately what goes into the window, in what order, and what stays out.

Context window vs. training data vs. memory

  • Training data is what the model learned before release. It is fixed and can be out of date.

  • The context window is the temporary workspace for a single request. It disappears after the call.

  • Memory in AI products is an application feature: stored information that the app chooses to put back into the context window on later requests.

FAQ

Is the context window the same as the model’s memory?

No. The context window only holds what is sent in the current request. Any long-term memory comes from the application saving information and re-inserting it into later prompts.

Does a bigger context window make RAG unnecessary?

Usually not. Sending everything is slower and more expensive, and accuracy tends to fall as prompts grow. Retrieving a focused set of passages is still the more reliable approach for most applications.

How do I know how many tokens my prompt uses?

Most providers offer a tokenizer tool or a token-counting endpoint, and API responses report input and output token usage. Logging those numbers per request is the easiest way to spot prompts that are growing out of control.

Who needs to understand context windows?

Anyone building with LLMs: AI engineers designing assistants and agents, developers integrating APIs, and data professionals who prepare the documents and tables that end up in prompts.

Want to build AI applications that use context wisely and the data foundations behind them? Explore these Coderhouse courses:

Dan Patiño

I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.

© 2026 Coderhouse. All rights reserved.

© 2026 Coderhouse. All rights reserved.

© 2026 Coderhouse. All rights reserved.