Context Fit Checker
Reserves space for the answer first, then tells you how much of the context window is left for your prompt — or exactly how many tokens over you are.
usage object on any completion response — prompt_tokens and completion_tokens are what you are billed on, they cost nothing to read, and they settle the question for the model you are actually calling.Your request uses 0.1% of the window, and 4,096 tokens are still reserved for the reply.
- Prompt tokens (estimated)
- 81
- Message overhead (1 × 4)
- 4
- Other tokens in the request
- 0
- Total input
- 85
- Reserved for the answer
- 4,096
- Input budget (window − reserve)
- 123,904
- Context window
- 128,000
- Share of the window used by input
- 0.1%
- Share of the window still free
- 96.7%
What actually causes the 400
Nearly every “maximum context length exceeded” error is one of three arithmetic mistakes. The first is treating the context window as an input budget. It is not: input and output share it, and a request whose prompt fits perfectly will still fail the moment the model tries to write a reply longer than the space left. Reserving the output first, as this page does, is the correct order of operations.
The second is forgetting everything in the request that is not your prompt text. Chat templates wrap each message in role markers. Tool and function schemas are serialised into the request in full, on every call, and a handful of tools is routinely larger than the user’s question. Images become token counts through a tiling formula. All of it counts, and none of it appears in the string you pasted.
The third is a growing conversation. History is re-sent on every turn, so a chat that fits at turn five may not at turn thirty even though no individual message got longer. If you are close to a limit, the fix that scales is not a bigger window but a trimming policy: drop or summarise the oldest turns, keep the system prompt and the most recent exchanges, and check the fit before you send rather than after the API refuses.