Calculate what percentage of an LLM's context window your prompt and history consume.
An LLM's context window is the maximum number of tokens (prompt + completion) it can process in a single request. This calculator adds your system prompt and user message/history tokens, then compares the total against the selected model's context window size to show percent used and remaining headroom. Staying well under the limit leaves room for the model's response and avoids truncation errors.
percent_used = (system_prompt_tokens + user_message_tokens) / context_window_size * 100
The API will either reject the request with an error or the provider will silently truncate the oldest messages, depending on how your client handles it. It's best to stay under the limit with margin for the response.
Yes. The context window covers both the input (prompt) and the output (completion) combined, so you should reserve tokens for the expected response length.
Context window size depends on the model's architecture and how it was trained, particularly its positional encoding scheme and attention mechanism, which determine how much sequence length it can handle reliably.
Not necessarily — very long contexts increase both cost and latency, and some models show reduced accuracy ('lost in the middle') on very long inputs.