
LLM Context Window: Size Your Prompts for GPT, Claude and Gemini
RAG, multi-turn agents, system prompts: calculate context-window usage and remaining headroom before calling the API.
Sizing your prompts before you call the API
An LLM's context window caps how many tokens you can send and receive in one request. A long system prompt, twenty RAG chunks, a multi-turn history and the expected answer all share the same budget, not separate quotas. Exceed the limit and most APIs return a 400 error. Some pipelines truncate the start or the end of the context instead, without an explicit warning. On FastMinify, the context window calculator measures your prompt against the GPT, Claude and Gemini models in its table, entirely in your browser. Pair it with the LLM token counter and the JSON formatter for API message payloads. See also the LLM token cost estimation guide and the AI & LLM tools hub.
Common mistakes with overflow, truncation and reading the gauge
A "128k" model does not offer 128k input tokens if you expect a reply of 8k tokens. Without an output reserve, you think you fit while generation gets clipped.
Keep in mind — Set a 15–20% output reserve in the context window calculator before validating a large RAG paste.
Some pipelines truncate the start, which holds the system prompt, or the end, which holds the recent chunks, when the context exceeds the limit. No HTTP error is raised. The model still replies, but on incomplete context.
Keep in mind — Aim for Safe (below 80% of the effective budget) on critical RAG workflows. Near limit calls for a reduction margin.
Word or character counters do not reflect billing or window limits. Code, JSON and non-Latin text diverge sharply from word/token ratios.
Keep in mind — Use the LLM token counter on the target model: an Exact badge for OpenAI, an Estimate badge for Claude and Gemini.
Ten short messages plus tool definitions can cost hundreds more tokens than equivalent plain text. A JSON parse error also hides missing keys.
Keep in mind — Format the messages payload with the JSON formatter, then switch to API messages mode in the calculator.
Honest limits and best practices
FastMinify helps plan the context budget in the browser. It does not simulate the exact runtime behavior of a provider.
Counting often reveals avoidable bulk in system prompts and duplicated context.
Counting runs 100% client-side, which is fine for prompts with proprietary code, PII or internal specs.
What actually matters about the context window and tokens
Providers advertise limits in tokens, for example 128k, 200k or 1M, not in words or characters. A token can be a whole word, a fragment or punctuation. The LLM token counter runs js-tiktoken for OpenAI, with an Exact badge, and a characters-per-token heuristic for Claude and Gemini, with an Estimate badge (±5–15%).
The context window calculator subtracts a configurable output reserve (10%, 15% or 20%, with 15% as the default) before computing the effective input budget. If your prompt uses 85% of that budget, you are Near limit even when the raw window still shows headroom.
In API messages mode, a [{"role","content"}] array adds ChatML overhead (+3 tokens per message, +1 per name, +3 response priming). Format and validate the structure with the JSON formatter before pasting into the calculator. For RAG, count the injected context on top of the user message, and do not stop at the final question.
A workflow with the context calculator, the token counter and the JSON formatter
Open the context window calculator. Paste plain prompt text or a messages JSON array. Pick the output reserve (10, 15 or 20%) and the encoding, either Auto or an o200k_base or cl100k_base override. The Model fit table lists tokens, usage and verdict for every model. The detail line shows the effective budget with the used and remaining tokens.
To inspect the BPE detail (OpenAI, Exact) or compare input tokens before pricing, open the LLM token counter with the same text. Both tools share the countTokensAsync pipeline, so totals should match for the same model and format.
Chat Completions integrations often send a messages JSON blob. Paste it into the JSON formatter to catch trailing commas, invalid quotes or a bad structure. Then reload the formatted JSON in API messages mode in the context calculator.
You inject 40 vector chunks, a system prompt and 6 turns of history for Claude Sonnet.
Assemble full context
Paste the system prompt, chunks, history and question into the calculator, or the equivalent messages array. Read the Anthropic rows of the table, and use a 20% reserve if answers often exceed 4k tokens.
Read verdict and headroom
If the verdict is Won't fit, trim chunks (lower top-k), summarize the history or switch to a model with a larger window. If it is Near limit, plan for truncation or request splitting.
Validate messages JSON
Format the final payload in the JSON formatter, recount in API messages mode, then cross-check the token and API cost guide for the USD projection.
Conclusion
Sizing a prompt means subtracting an output reserve, counting tokens on the right model and reading the verdict before the API call. The FastMinify context window calculator combines a multi-provider model table, a configurable reserve and the Safe, Near limit and Won't fit verdicts, all locally. Add the token counter for detail and the JSON formatter for message payloads. The token and cost guide and the AI hub cover the rest of the workflow.
Check whether your prompt fits the context window
Related Articles

Paste a token and a JWKS to check an RS256, ES256 or HS256 signature in your browser. How kid picks the key, measured errors and the claims to check.

HTTP/2 and HTTP/3 change how files travel, not how big they are. Measured sizes, compile times and bundling tests show what minification still saves.

Convert a Unix epoch to a readable date and back, tell seconds from milliseconds, and avoid time zone, JWT and clock change traps, all in your browser.