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:
llm
context-window
prompt
rag
agents
ai
Tutorial

Why size your prompts before calling 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, multi-turn history and the expected answer all share the same budget — not separate quotas. Exceed the limit and you get a 400 error; hug the ceiling and the model may truncate the start or end of context without an explicit warning. On FastMinify, the context window calculator measures your prompt against the GPT, Claude and Gemini model registry — 100% in the browser. Pair it with the LLM token counter and 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 output headroom (10–20%) to avoid cut-off completions
Compare every model in the FastMinify registry on the same paste
Safe, Near limit and Won't fit statuses aligned to an 80% threshold
No prompt sent to providers — local counting only

Common mistakes: overflow, truncation and misreading the gauge

Confusing raw window with usable budget

A "128k" model does not offer 128k input tokens if you expect an 8k-token answer. Without an output reserve, you think you fit while generation gets clipped.

Keep in mindSet 15–20% output reserve in the context window calculator before validating a large RAG paste.

Ignoring silent truncation

Some pipelines truncate the start (system prompt) or end (recent chunks) when context exceeds the limit — without an HTTP error. The model still replies, but on incomplete context.

Keep in mindAim for Safe (< 80% of effective budget) on critical RAG workflows; Near limit needs 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 mindUse the LLM token counter on the target model — Exact badge for OpenAI, Estimate for Claude/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 mindFormat the messages payload with 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 context budget in the browser — it does not simulate exact provider runtime behavior.

Model registry maintained manually — verify official docs before critical prod
Estimate tier (Claude, Gemini): ±5–15% — do not hug the ceiling on Estimate alone
No image, audio or tool-call token rules in v1
Actual truncation depends on SDK and model — Won't fit signals risk, not 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 — 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 is 100% client-side — suitable for prompts with proprietary code, PII or internal specs.

No upload of pasted content to OpenAI, Anthropic or Google
No account required — no identity ↔ prompt correlation
512 KiB max per paste — split very large exports
Instrument API logs (usage tokens returned by the provider) in production as a complement
AI hub: chain context calculator → token counter → pricing calculator as needed

Context window vs tokens: what actually matters

Tokens measured, window published per model

Providers advertise limits in tokens (e.g. 128k, 200k, 1M) — not words or characters. A token can be a whole word, a fragment or punctuation. The LLM token counter runs js-tiktoken (Exact badge) for OpenAI and a chars/token heuristic (Estimate badge, ±5–15%) for Claude and Gemini.

Context window = input + output cap 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 — counts differ across families
512 KiB UTF-8 max per paste on FastMinify AI tools
Effective budget: reserve space for output

The context window calculator subtracts a configurable output reserve (10%, 15% or 20% — default 15%) 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 if usage < 80%, Near limit if ≥ 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 structure with the JSON formatter before pasting into the calculator. For RAG, count injected context on top of the user message — not just the final question.

Heavy RAG: chunks often dominate, not the user question
Multi-turn agents: history grows each turn — recount before every call
Stable system prompts: good prompt-caching candidates (see pricing guide)
Auto mode detects plain text vs messages JSON array
Compare all models: table view across the FastMinify registry

Workflow: context calculator, token counter and JSON messages

Step 1 — Paste and count in the context window calculator

Open the context window calculator. Paste plain prompt text or a messages JSON array. Pick the model, output reserve (10 / 15 / 20%) and encoding mode (Auto or o200k_base / cl100k_base override). Compare all models lists usage %, remaining tokens and verdict per model.

Safe, Near limit (≥ 80%) and Won't fit (effective budget overflow) verdicts
Output reserve 10%, 15% or 20% — default 15%
Plain text or API messages JSON with Auto detection
Exact (OpenAI) or Estimate (Claude, Gemini) badge per row
512 KiB max — split very large payloads before pasting
Step 2 — Refine the count with the token counter

To inspect 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 — totals should match for the same model and format.

Token pill visualization for Exact models only
Compare all models — count table across the registry
Copy totals into the pricing calculator when needed
Same 512 KiB limit and Exact/Estimate tiers
Complements the context calculator — not a duplicate
Step 3 — 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 bad structure — then reload formatted JSON in API messages mode in the context calculator.

Syntax validation before counting — avoids parse surprises
Readable tree to spot redundant messages
100% local — handy for internal specs or proprietary code
Chain into context-window-calculator in messages mode
See the <a href="/en/blog/json-formatter-diff-tree-viewer-guide" class="text-primary hover:underline">JSON Formatter, Diff and Tree Viewer guide</a> for deep payloads
Scenario — multi-turn RAG agent on Claude

You inject 40 vector chunks + system prompt + 6 turns of history for Claude Sonnet.

1

Assemble full context

Paste system + chunks + history + question into the calculator (or equivalent messages array). Select the target Anthropic model and 20% reserve if answers often exceed 4k tokens.

2

Read verdict and headroom

If Won't fit: trim chunks (lower top-k), summarize history or switch to a larger window via Compare all models. If Near limit: plan truncation or request splitting.

3

Validate messages JSON

Format the final payload in json-formatter, recount in API messages mode, then cross-check the token and API cost guide for 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. FastMinify's context window calculator combines a multi-provider registry, configurable reserve and Safe / Near limit / Won't fit statuses — all locally. Add the token counter for detail and json-formatter for message payloads; the token &amp; cost guide and AI hub cover the rest of the workflow.

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