Context Window Calculator

Budget prompt, reserved, and completion tokens against a model window.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Enter the model's context window and what you plan to use: prompt tokens (or paste the prompt to have them counted), tokens reserved for the system prompt and tools, and the completion budget. You get tokens remaining, utilization and a fits yes/no.

How to use

1
Step 1
Enter the context window size.
2
Step 2
Enter prompt tokens, or paste the prompt text and leave tokens at 0.
3
Step 3
Add reserved tokens and the completion budget, then press Calculate.

How it works

Everything in a request shares one window: remaining = window − prompt − reserved − completion. If the result is negative, the request does not fit and the tool says by how many tokens. Pasted prompt text is counted with the o200k_base tokenizer and overrides the prompt tokens number.

remaining = window − prompt − reserved − completion

Worked example

A 128k model

Input
Window 128,000; prompt 1,200; reserved 1,000; completion 2,048
Output
123,752 tokens remaining; utilization 3.3%; fits: yes
Walkthrough
1,200 + 1,000 + 2,048 = 4,248 tokens allocated. With a 130,000-token prompt the result is -5,048 and Fits reads no (over by 5048).

Limitations

  • It does not know any model's real window; you type it in.
  • Pasted text is counted with o200k_base, which is approximate for non-OpenAI models.
  • Hidden overhead, such as chat formatting tokens and tool schemas, is not added; put it in reserved tokens.

Questions

How do I know if my prompt fits in the context window?
Enter the window, prompt, reserved and completion tokens. Fits says yes or no.
What should I reserve?
Tokens for the system prompt, tool definitions and any retrieved context that you do not count in the prompt.
Does the completion count against the window?
Yes. Input and output share the context window.
Can it count my prompt for me?
Yes, paste the text in the optional prompt field.

Features

  • Remaining and utilization
  • Counts pasted text
  • Over-by message

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Machine Learning for Everybody

    freeCodeCamp.org

    Accessible ML survey for AI calculator and metric tools.

    Watch on YouTube
  • Big-O Notation in 100 Seconds

    Fireship

    Complexity intuition when estimating training/inference cost.

    Watch on YouTube