LLM Context Window: Size Your Prompts for GPT, Claude and Gemini

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.

19.08.2026
7 min read
Share this article:
llmcontext-windowpromptragagentsaiTutorial

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.

See effective budget usage % before the API call
Reserve room for the answer (10–20%) to avoid cut-off completions
Compare every model in the FastMinify table on the same text
Safe, Near limit and Won't fit verdicts around an 80% threshold
No prompt is sent to providers, counting is local only

Common mistakes with overflow, truncation and reading the gauge

Confusing raw window with usable budget

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.

Ignoring silent truncation

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.

Counting words instead of tokens

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.

Forgetting message overhead and tools

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

What the calculator does not predict

FastMinify helps plan the context budget in the browser. It does not simulate the exact runtime behavior of a provider.

The model table is maintained by hand, so check the official docs before a critical production release
Estimate tier (Claude, Gemini): ±5–15%, so do not push to the ceiling on an estimate alone
No token rules for images, audio or tool calls
Actual truncation depends on the SDK and the model: Won't fit signals a risk, not a guaranteed HTTP error
No API calls: billing quotas and account limits are not queried
Reduce pressure on the window

Counting often reveals avoidable bulk in system prompts and duplicated context.

Shorten system instructions, since every token repeats on every request
Deduplicate RAG chunks: drop near-identical passages
Summarize multi-turn history instead of resending raw transcripts
Larger window for ingestion, smaller model for synthesis if the pipeline allows
TOON for uniform tables: see when TOON beats JSON (measure, do not assume)
Privacy and sensitive data

Counting runs 100% client-side, which is fine for prompts with proprietary code, PII or internal specs.

Pasted content is not uploaded to OpenAI, Anthropic or Google
No account required, so no link between an identity and a prompt
512 KiB maximum per paste: split very large exports
In production, also instrument your API logs with the usage tokens returned by the provider
AI hub: chain the context calculator, the token counter and the pricing calculator as needed

What actually matters about the context window and tokens

Tokens measured, window published per model

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%).

Context window = cap on input plus output per request (model-dependent)
System prompt, RAG, history and user question add up as input tokens
Tool definitions and structured JSON count as tokenized text
Always compare on the target model, because counts differ across families
512 KiB of UTF-8 at most per paste on the FastMinify AI tools
Effective budget and the output reserve

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.

effectiveLimit = contextWindow − reserveTokens
remainingTokens = effectiveLimit − promptTokens (floored at 0)
usagePercent = promptTokens / effectiveLimit × 100
Verdict Safe below 80% usage, Near limit from 80%, Won't fit on overflow
Multi-turn agents: raise the reserve when completions often exceed 2–4k tokens
RAG, agents and API message prompts

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.

Heavy RAG: the chunks often dominate, not the user question
Multi-turn agents: history grows on each turn, so recount before every call
Stable system prompts: good candidates for prompt caching (see the pricing guide)
Auto-detect tells plain text from a messages JSON array
Model fit table: every listed model side by side

A workflow with the context calculator, the token counter and the JSON formatter

First, paste and count in the context window calculator

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.

Three verdicts: Safe, Near limit from 80%, and Won't fit when the effective budget overflows
Output reserve of 10%, 15% or 20%, with 15% as the default
Plain text or API messages JSON, with auto-detection
An Exact badge for OpenAI or an Estimate badge for Claude and Gemini on each row
512 KiB maximum: split very large payloads before pasting
Then, refine the count with the token counter

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.

Token breakdown for Exact models only
Compare all models: a count table across the listed models
Copy the stats into the pricing calculator when needed
Same 512 KiB limit and Exact/Estimate tiers
Complements the context calculator rather than duplicating it
Finally, prepare API message payloads

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.

Syntax validation before counting, so no surprises when the JSON is read
Readable tree to spot redundant messages
100% local, which suits internal specs or proprietary code
Continue in the context window calculator in messages mode
A multi-turn RAG agent on Claude

You inject 40 vector chunks, a system prompt and 6 turns of history for Claude Sonnet.

1

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.

2

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.

3

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.

Reserve 15–20% for the answer on agents and long chains
Aim for Safe (under 80%) on critical RAG workflows
Recount after each turn of a multi-turn history
Treat Estimate as planning, not as official Anthropic or Google limits
Cross-check the token and API cost guide for the USD projection
Share this article
Share this article: