Context Window Calculator
Whether a system prompt, a set of documents, the conversation history and room for the answer fit inside a model’s context window — how many documents fit, and the input cost of each call.
Everything the model sees counts against one limit: the system prompt, every document you attach, the whole conversation so far, and the space you must leave for the reply.
How the context window calculator works
Everything the model sees counts against one limit: the system prompt, every document you attach, the whole conversation so far, and the space you must leave for the reply. Add them up against the window; if they do not fit, the calculator says how many documents do. Each call pays for all the input tokens again, so a long system prompt or history multiplies cost across a conversation — which is what prompt caching is for.
Formula: used = system + docs × tokens per doc + history + reserved output; fits if used ≤ window
Worked examples
| Inputs | Context used | Note |
|---|---|---|
| 128k window, ten 8k documents, 12k history | 97.5 thousand of 128 thousand (76%) | 97.5k — fits, 13 docs at most |
| A 32k window with the same load | 97.5 thousand of 32 thousand (305%) | does not fit — 1 document at most |
| Short prompt, no documents | 3.5 thousand of 8 thousand (44%) | 3.5k — fits |
FAQFrequently asked questions
How many tokens is a document?
About 1.3 tokens per English word, or 4 characters per token — a page of text is 500–700 tokens, a 20-page PDF 10,000–15,000. Code and non-English text run higher. Use the tokenizer of the model for exact counts.
Why reserve tokens for the answer?
Most APIs share one window between input and output: fill it with input and the reply is cut off. Reserve at least what the longest answer needs.
Does a bigger window solve it?
It fits more, at a cost: every call pays for every input token, and models attend less reliably to details buried in very long contexts. Retrieval — sending only the relevant passages — is usually cheaper and better than sending everything.
What does prompt caching change?
The system prompt and any stable prefix can be cached so repeat calls pay a fraction of the input price for them. The context still has to fit; only the cost falls. The prompt caching calculator quantifies it.
Where these figures come from
- Vaswani et al. (2017) — Attention Is All You Need — the transformer architecture the memory arithmetic follows
- Kaplan et al. (2020) — Scaling Laws for Neural Language Models — the compute relationship used for training estimates
- Hoffmann et al. (2022) — Training Compute-Optimal Large Language Models — the tokens-per-parameter guidance ("Chinchilla")
- IEEE 754 — Standard for Floating-Point Arithmetic — the numeric formats behind bytes per parameter
- National AI Centre — Australia's national AI body
Last checked: September 2026. The relationships here are architectural, not vendor-specific: bytes per parameter follow the numeric format, KV-cache size follows the transformer definition, and token-per-word ratios come from published tokeniser behaviour.