Context Window Calculator: Plan an LLM Token Budget
By FindMySum · Last reviewed
A context window calculator plans the token budget of a single request to a large language model. The context window is the most text, measured in tokens, that the model can work with at once: the instructions, the tool definitions, the conversation so far, any documents you retrieve, the new question and, at most providers, the reply itself. This page adds up the parts you enter, keeps a safety margin, and tells you how much room is left and how many more document chunks or conversation turns would fit. The worked example uses the defaults: a 200,000-token window, a chat with ten earlier turns and eight retrieved chunks.
What goes into the window
| Part | What it is | Grows with |
|---|---|---|
| System prompt | Standing instructions for every request | Rarely changes |
| Tool definitions | Names, descriptions and schemas of functions the model may call | Number of tools |
| Conversation history | Earlier user messages and replies | Every turn |
| Documents | Retrieved passages (RAG), files, search results | Chunks × chunk size |
| New message | The user's current question | — |
| Reserved reply | The maximum output you allow | Your max_tokens setting |
The reply is reserved up front because most providers check that the input plus the maximum output fits before they start. Reasoning ("thinking") tokens usually count in that reply budget.
The formula
input = system + tools + turns × tokens per turn + chunks × tokens per chunk + message
left = window × (1 − safety margin) − input − reserved reply
From what is left, the calculator also works out how many more chunks of the same size would fit, and how many conversation turns in total would fit with everything else unchanged.
Worked example
- Input: 2,000 + 1,500 + 10 × 600 + 8 × 800 + 300 = 16,200 tokens.
- With the reply reserved: 16,200 + 4,000 = 20,200 tokens, 10.1% of the window.
- Usable budget: 200,000 less a 5% margin = 190,000 tokens.
- Left: 190,000 − 20,200 = 169,800 tokens.
- More chunks: 169,800 ÷ 800 = 212 (rounded down).
- Turns in total: (190,000 − 14,200) ÷ 600 = 293.
This request uses a tenth of a large window. The same request against a 32,000-token window with 40 chunks would need 45,800 tokens against a budget of 30,400, and fail by 15,400.
Why a safety margin?
Token counts depend on the model's tokenizer, and the same text can differ by several percent between models. Each message also carries a few formatting tokens that are easy to forget. A margin of a few percent absorbs both. If your counts come from the provider's own token counter for the exact request, you can set the margin to zero.
Counting tokens
This page does not run a tokenizer, because each model family has its own. Three ways to get real counts:
- read the input and output token counts the API returns with every response;
- call the provider's token-counting endpoint before sending;
- use the model's tokenizer library on your text.
As a rough guide, English prose runs about three quarters of a word per token, so 1,000 tokens is around 750 words. Code, tables, numbers and many other languages use more tokens per word.
Budgeting tips
- Trim history first. Old turns are the part that grows without limit; keep the last few and summarise the rest.
- Retrieve less, rank better. Eight well-chosen chunks usually beat forty loosely related ones, and cost less.
- Size the reply honestly. A maximum of 4,000 tokens reserves 4,000 tokens even if the answer uses 300; set it near what the task needs.
- Remember the bill. Every input token is charged; the LLM cost calculator shows what this budget costs per request and per month.
More questions
What happens when a request is longer than the context window?
Most APIs reject it with an error that names the limit; some chat products silently drop the oldest messages instead. Either way the model never sees what did not fit, so plan the budget before the request rather than after the error.
Should I fill the whole context window?
Rarely. Every input token is billed and slows the first token down, and answers can get worse when the relevant passage is buried among many others. A budget that leaves room is cheaper and often more accurate.
How big should RAG chunks be?
Common choices run from about 200 to 1,000 tokens per chunk, with some overlap between neighbours. Smaller chunks let you fit more distinct sources; larger ones keep more context around each fact. Try a few sizes on your own questions and measure answer quality.
Do tool definitions really take that many tokens?
They can. Each tool's name, description and JSON schema is sent with every request, and a set of twenty detailed tools can run to several thousand tokens. Check the input token count of a request with tools and without to see your figure.
Does the context window include images?
Yes, at providers that accept images, each image is converted to tokens that count against the window, often hundreds to a few thousand per image depending on its size. This calculator covers text; add your image token estimate to the message or documents line.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.