๐ง What is a Context Window?
Think of the context window as the model's working memory โ it's the maximum amount of text the LLM can see and process at any one time. ๐๏ธ
๐ฆ What Fits Inside It?
Everything gets counted toward the limit:
๐ฌ Your current message
๐ The full conversation history
๐ค The model's previous replies
โ๏ธ Tokens being generated in the current response
โ ๏ธ What Happens When It's Full?
Once the total tokens exceed the limit, the model simply cannot process any further โ it's like trying to pour water into an already full glass. ๐ฅ
๐ก The Simple Way to Think About It
Just like humans can only hold so much information in their head at once, an LLM can only "see" a limited chunk of the conversation at any given moment. ๐งฉ
๐ How LLMs Generate Responses
LLMs don't write responses all at once โ they build them one token at a time, like constructing a sentence brick by brick. ๐งฑ
๐ Example: Watch It Unfold
๐ค User asks: "What is my name?"
Step | What the model sees |
|---|---|
1๏ธโฃ |
|
2๏ธโฃ |
|
3๏ธโฃ |
|
4๏ธโฃ | ...and so on until the response is complete โ |
Each new token gets added to the sequence, which then feeds back in to predict the next one.
โ ๏ธ Why Context Window Size Matters
A bigger context window means the model can:
๐ฃ๏ธ Remember longer conversations
๐ Reference details mentioned much earlier
๐ Handle large documents with ease
๐ง Perform deeper, more accurate reasoning
๐ ๏ธ Support advanced prompting techniques
๐ก The bigger the window, the more the model can "hold in its head" at once!
๐งจ Important Use Cases
Multi-shot prompting
Giving several examples before the actual task
RAG (Retrieval-Augmented Generation)
Injecting external knowledge into prompts
Agent systems
Long-running workflows and memory chains
๐ฐ How API Pricing Actually Works
Chat products like OpenAI and Anthropic offer free and paid plans โ but APIs are different. With APIs, you pay for exactly what you use, based on token consumption. ๐งฎ
๐งพ What You're Actually Paying For
1๏ธโฃ Input Tokens โ Everything you send to the model:
๐ Full conversation history
โ๏ธ System prompts
๐ง Memory & RAG data
๐ฌ Current user message
2๏ธโฃ Output Tokens โ Everything the model generates:
โ๏ธ The visible response text
๐ Hidden reasoning traces (in reasoning models)
โ ๏ธ Even if the reasoning is invisible to you, the computation still happens โ and you still get billed for it!
๐ Costs Grow With Conversation Length
The longer a conversation gets, the more tokens get reprocessed with every single message. This is simply how transformers work โ they look back at all prior tokens every time. ๐
๐ง Reasoning Models Can Get Pricey
Reasoning models think deeply before responding โ generating large internal reasoning traces behind the scenes. You pay for:
โ The answer you see
๐ธ The reasoning you don't
๐ก Always factor in hidden reasoning costs when budgeting for reasoning models!
โก Prompt Caching โ A handy Cost Saver!
Some API providers offer prompt caching โ a smart optimization that kicks in when the same input is sent repeatedly.
Instead of recomputing everything from scratch, the provider reuses previous computations, making repeated inputs significantly cheaper ๐ฐ and faster โก.
โ Best part? In some systems this happens completely automatically โ no extra setup needed! ๐
๐ Context Window, Pricing, Speed & More โ Model Comparison
๐ https://www.vellum.ai/llm-leaderboard

โ Special Note
Understanding which model to use โ based on context window, pricing, and speed โ is an essential skill for any great AI engineer. Every use case is unique and demands a different solution.