LLM Context Window Planner
Every LLM call has a hard budget: the model's context window. Your system instructions, the conversation so far, every retrieved document and the reply you expect all draw from the same pool of tokens - and when the total crosses the limit, the API rejects the call or your provider silently truncates the oldest messages. Plan the budget here before you ship: pick a model, budget each component in tokens, and see exactly how much headroom is left, how many more turns fit, and what to trim if it does not.
Model and estimation
Pick the model you are planning against (typical published values - override either number if your provider or local runtime differs) and choose how densely your text packs into tokens.
Rough average; real tokenizers vary by a few percent either way, which is what the safety reserve covers.
Chat-template markers, role tags and special tokens the API adds around your messages.
System instructions
Paste the system prompt (or developer message) you send on every call. It is billed in full on every request, so it is usually the first place to trim.
Conversation history
Budget the chat so far as turns: how many user messages and assistant replies are in the context, and how long each one averages. Every turn stays in the window until you summarize or drop it.
Retrieved documents (RAG)
If your pipeline injects retrieved chunks, citations or reference files into the prompt, list them here. Sizes are in characters; the planner converts with the text profile above.
| Document | Size (chars) | Estimated tokens |
|---|
Expected response
How long the model's reply is expected to be. It counts against the same window as everything above - on most APIs the output tokens are part of the context, and if prompt + output exceeds the limit the call fails or the output is cut short.
Where to trim
Does it fit on other models?
Your current budget, checked against every preset model at the same reserve. A quick way to see whether switching models is a cheaper fix than trimming content.
| Model | Window | Total needed | Free after reserve | Verdict |
|---|
What a context window is, and why it fills up
A large language model does not see your whole conversation as a chat log; it sees one long string of tokens - system instructions first, then every prior user message and assistant reply in order, then any documents or tool results you inject, and finally the space reserved for the new reply. The context window is the maximum length of that string. When the total exceeds it, the API either rejects the request outright (the classic "maximum context length exceeded" error) or, on some providers, quietly drops the oldest messages - which is how a support bot starts forgetting the customer's name mid-conversation with no error in your logs.
The trap is that the budget is shared and asymmetric. A 2,000-token system prompt costs 2,000 tokens on every single call, forever. Retrieved documents are often the biggest line item - a RAG pipeline that stuffs five long chunks into the prompt can spend more context on evidence than on the actual conversation. And the expected response is not free: it is part of the same window, so a model configured to write 8,000-token answers has 8,000 fewer tokens available for input.
How the estimates are calculated
This planner converts characters to tokens with a per-text-type ratio, because exact tokenization requires running the model's own tokenizer and that is what the dedicated LLM Token Counter on this site is for. The ratios below are the averages you will see in practice; the safety reserve (default 10%) exists precisely because the real count can land a few percent higher than the estimate.
| Text profile | Chars per token | Typical content |
|---|---|---|
| Plain English prose | ~4.0 | Chat messages, articles, support transcripts |
| Technical writing / mixed | ~3.6 | Docs with numbers, paths, identifiers interspersed |
| Code-heavy text | ~3.2 | Source code, JSON, logs - dense symbols tokenize finely |
| CJK (Chinese/Japanese/Korean) | ~1.8 | Each CJK character is usually its own token or a pair of them |
Component math: system instructions are the pasted prompt's character count divided by the ratio; history is (user turns x average user length) plus (assistant replies x average reply length), converted the same way; each retrieved document converts on its own and the totals sum; the expected response is entered in tokens directly because you usually plan it as a budget, not a text. Template overhead covers the role markers and special tokens the API wraps around your messages - typically 20-100 tokens for a standard chat template, more for tool-calling schemas.
How to use this planner
- Pick your model from the dropdown. The window and max-output fields pre-fill with typical published values; correct them if you run the model locally (a llama.cpp server started with a small
-ccontext is smaller than the model's theoretical window) or behind a provider that truncates. - Paste your real system prompt and set the text profile to match your dominant content. If your traffic is half code, half prose, pick the denser ratio - overestimating input tokens is the safe direction.
- Budget history at the conversation length you actually expect in production, not the two-turn demo you tested with. A support bot that runs for 30 turns has a very different budget than one that answers a single question.
- List every document your pipeline injects - retrieved chunks, pinned references, tool schemas. Use the quick-add chips for typical sizes or enter exact character counts from your chunker's config.
- Set the expected response to the longest reply you will tolerate (your
max_tokenssetting is the honest number here), and keep the 10% safety reserve unless you have measured your real tokenizer error. - Read the verdict. Plenty of headroom means you are done. Tight or over budget means look at "Where to trim" - the suggestions are ranked by how many tokens each one saves - and check the model-fit table if switching is an option. Then take the numbers with you: copy the text report, download the CSV for a capacity spreadsheet, or share the link so your team reviews the same setup.
A worked example
Take a support bot on a 32,768-token window (the Custom preset) with a 10% reserve: 29,491 tokens are usable. The system prompt is 204 characters of English prose - 51 tokens at the prose ratio. The conversation runs to 60 turns, averaging 250 characters of user text and 600 characters of assistant reply per turn: (60 x 250 + 60 x 600) / 4 = 12,750 tokens. The retriever injects a wiki article (9,000 chars, 2,250 tokens), a code reference (12,000 chars, 3,000 tokens) and a manual chapter (60,000 chars, 15,000 tokens): 20,250 tokens. The expected response is budgeted at 2,000 tokens, plus 64 of template overhead. Total: 35,115 tokens against 29,491 usable - over budget by 5,624 tokens, and the planner will show a red bar and refuse to pretend it fits.
The trim list does the diagnosis: dropping the manual chapter saves 15,000 tokens, which lands the total at 20,115 with 9,376 tokens of headroom left - comfortable. But if that chapter is genuinely required, the model-fit table shows the same workload fits GPT-4o (128K), Llama 3.1 8B (131K) or Gemini 1.5 Pro (2M) with large headroom, so the real decision is "chunk the manual down to the relevant section" versus "move to a bigger window". Either way you made that choice in five minutes on paper instead of discovering it as a 400 error at 2 a.m.
Common mistakes when planning context budgets
- Planning for the demo, not the production conversation. A two-turn test fits any window. The failure mode is turn 40 of a support chat, or the long-tail customer who pastes their whole error log. Budget history at your p95 conversation length, and remember every turn is permanent until you summarize it away.
- Forgetting that output is part of the window. Setting a high
max_tokensshrinks your input budget by exactly that amount. If your prompt already uses 95% of a 128K window, an 8K response budget is what pushes the call over - not the next user message. - Trusting one tokenizer's count for another model. A prompt that is 100K tokens in Claude's tokenizer might be 92K or 108K in GPT's. That is what the safety reserve is for - and why a budget at 80% of the window with a 10% reserve is a good target, not 99%.
- Stuffing whole documents instead of chunks. RAG exists because you cannot paste the whole manual. If your "retrieved documents" line is bigger than your conversation, the retriever is doing more harm than help - chunk smaller or rank harder.
- Mixing text profiles. Estimating a 24,000-character code file at the prose ratio (4.0 chars/token) undercounts it by ~25% - code tokenizes denser. When in doubt, use the code profile for anything with brackets and semicolons.
- Ignoring the runtime's actual limit. A locally served Llama 3.1 has a 128K theoretical window, but if the server started with a 8,192-token context, that is your real number. Enter what the runtime enforces, not what the model card says.
Reading the "context length exceeded" error
When you do cross the limit, most APIs tell you exactly where: a typical response looks like this -
{"error": {"message": "This model's maximum context length is 128000 tokens.
However, your messages resulted in 131452 tokens (98765 in the
messages, 32687 in the completion). Please reduce the length..."}}
Note that it splits the total into input and completion - which confirms both halves draw from the same window. Feed those two numbers back into this planner (your measured input count as the component sum, your max output as the expected response) and the trim list will tell you which line item to cut first.
Privacy
This tool is entirely client-side. The token estimates, the budget math and the model comparison all run in JavaScript inside your own browser tab, so your prompts and transcripts never touch a server. There is no account, no tracking of your inputs, and no data retention - close the tab and everything is gone.
Related tools
The rest of the local-LLM and prompt workflow:
Suggested
Luke Keam | techgeek.biz