Home / Guides / Will my document fit? Context window calculator

Will my document fit? Context window calculator

A practical workflow for checking whether a PDF, prompt pack, or chat history fits a model’s context window before you ship or spend.

Why “will it fit?” is a token question

Product teams still ask how many pages they can paste. Marketing pages answer with a large number like 128K or 1M. That number is a token budget, not a page count, not a word count, and not free space for your file alone.

A context window calculator answers one operational question: for this model, with this input, and with this planned completion length, do I still have headroom?

If you only guess from pages or words, you will undercount code, tables, JSON, and multilingual text. You will also forget system prompts and reserved output. Fit checks that ignore those pieces fail in production even when the raw document looks small.

TokenCalculator’s context window calculator is built for that check. Pair it with the tokenizer when you need exact counts, and with the cost calculator when fit is fine but spend is not.

What the calculator must include

A useful fit tool accounts for everything that competes for the same window. System and developer instructions (static rules, safety text, tool schemas) are present on every call. User content is the obvious part people measure. Retrieved evidence often exceeds the user question. Conversation history grows every message. Reserved output (max completion tokens) shares the same window as input.

If any of those slices is missing from your mental model, your “fits” answer is incomplete. For deeper budgeting in retrieval apps, see the context window budgeting for RAG guide. For how overflow behaves when you miss the mark, see what happens when you exceed the context window.

How to check if a prompt fits before an API call

Gather the text you actually send. Copy the prompt as the API will see it: usually system text plus the document or retrieved chunks, not only the user question. If your app strips headers or OCR noise before send, use the cleaned version. If it does not, use the raw paste your users will produce.

Pick the model you will call. Windows differ by model and host. A document that fits one SKU may overflow another. Advertised maxima are not always the size you should plan for. Quality can fall before you hit the ceiling. Read effective vs advertised context window before you treat the catalog max as a product target.

Tokenize, then read the meter. Run the text through TokenCalculator’s tokenizer or paste into the context window calculator. Exact tokenizers beat word heuristics for shipping gates. Approximate ratios are fine for napkin planning only. See exact vs approximate tokens.

Reserve output tokens explicitly. Decide the maximum completion length your product allows (summary, JSON fields, long answer). Subtract that reservation from the window before you declare success. Why that reservation is mandatory is covered in why you must reserve output tokens.

Interpret headroom, tight, and overflow. Comfortable headroom means you can ship with margin for slightly longer docs or extra history. Tight means redesign before you optimize price. Overflow means the request cannot succeed as designed. Fix fit first, then open the cost calculator.

Check long-context pricing cliffs. Some models still fit after a long prompt but charge a higher rate tier once input crosses a published threshold. Fit and cost are separate questions. Browse long-context pricing and verify rates in the TokenCalculator catalog rather than inventing unit prices from memory.

Worked example: will my PDF fit in a GPT 128K context window?

Imagine a 120 page PDF converted to text, a short system prompt, and a request for a structured 2,000 token summary on a 128K window model (the same workflow applies when you compare OpenAI, Claude, and Gemini windows in the catalog).

Tokenize the PDF text and system prompt. Add 2,000 reserved output tokens. Compare the sum to 128K (or the model’s published window in the catalog). If you are under the window but near a long-context tier threshold, estimate cost with catalog rates, not a spreadsheet guess.

If the sum overflows, do not hope the API truncates nicely. Truncation and rejection are failure modes. Shrink input, summarize offline, retrieve slices, or choose a larger window model after you confirm quality is acceptable at that length.

When a rough words-to-window check is enough

Early planning sometimes needs a quick answer: is this report even in the right ballpark? English prose often lands near a few tokens per word on average. That heuristic fails for code, markup, and many non-English languages. Use it only to decide whether a full tokenize pass is worth doing now. Never use it as a production gate.

Background on windows and shared input/output budgets: the context windows guide. Background on how text becomes tokens: tokenization. Background on how tokens turn into spend: prompt cost.

Common mistakes

Avoid these fit-check mistakes.

  • Measuring pages or words and calling that tokens
  • Tokenizing only the user message and ignoring system, tools, and history
  • Declaring fit without reserving max output tokens
  • Stuffing the whole corpus when retrieval of a few chunks would work
  • Treating advertised window size as the quality target
  • Ignoring long-context rate tiers after a prompt still technically fits
  • Comparing models without using the same prompt pack on each

Frequently asked questions

What is a context window calculator?
A tool that estimates whether your prompt (plus reserved output) fits a model’s maximum token budget for a single request. TokenCalculator’s version is at /tools/context-window.
What is a context window in AI / LLMs?
The maximum tokens a model can consider in one request. Input and planned output usually share that budget. See the context windows guide.
Can I trust page count or file size?
No. Tokenization depends on content type and language. Two PDFs with the same page count can produce very different token totals.
How many pages or words fit in 128K tokens?
There is no fixed page or word conversion. Dense code, tables, and non-English text use more tokens per page than light prose. Tokenize the real text, then compare to the model window with reserved output.
Do I need the exact tokenizer for every model?
For shipping gates, prefer the closest exact or documented tokenizer path TokenCalculator exposes for that family. Approximate modes are for exploration. See the exact vs approximate tokens guide.
Why did my document “fit” in a spreadsheet but fail in the API?
Spreadsheets usually omit system text, tool schemas, history, and reserved completion tokens. They also miss provider-specific tokenization quirks.
Why did a chars÷4 estimate say it fits when the API rejected the call?
Character heuristics ignore tokenizer quirks, special tokens, templates, and reserved max output. They also miss system text and tool schemas. Re-run with a real tokenizer path and a full prompt pack.
Does the model’s answer count against the context window?
Yes. Completion tokens compete for the same request budget. Reserve them before you declare fit. See the reserve output tokens guide.
Should I always pick the largest window model?
Not automatically. Larger windows can raise latency, cost (including long-context tiers), and attention quality issues. Prefer the smallest window that fits with headroom and acceptable quality.
How does this relate to cost?
Fit answers whether the call can succeed. Cost answers what it will bill. Use the cost calculator after fit is green, and check long-context pricing when prompts are large.
What if only part of my document is relevant?
Prefer retrieval or section selection over full paste. That is the core idea in the context window budgeting for RAG guide.

Try it in TokenCalculator

Paste your real document text (or a representative slice), pick a model, reserve output tokens, and read fit vs overflow.

Open context window calculator · Open tokenizer · Estimate API spend · All guides

Related tools

Context window calculator · RAG cost · Cost calculator · Long-context pricing

Related guides

Context windows and overflow · Context budgeting for RAG · What happens when you exceed the context window · Why you must reserve output tokens · Effective vs advertised window

Sources and references

Official documentation used for definitions, counting methods, or rate cards. Always confirm critical budgets on the provider page.