Plan your token budget before you call
Every LLM call has to fit inside a fixed context window. This planner helps you divide that window sensibly: reserve tokens for the output, account for your system prompt, and see how much room is left for user context and retrieved documents — with a visual bar that turns red the moment you overflow.
Context windows across common models
Different models offer significantly different context windows, and the right budget strategy depends on which model you are using:
| Model | Approximate context window |
|---|---|
| GPT-4o | 128,000 tokens |
| GPT-4o mini | 128,000 tokens |
| Claude 3.5 Sonnet | 200,000 tokens |
| Claude 3.5 Haiku | 200,000 tokens |
| Gemini 1.5 Pro | 1,000,000 tokens |
| Llama 3 (8B) | 8,000 tokens |
Larger windows do not mean you stop needing to budget. Even with 200K tokens available, a poorly planned call that fills the window with low-value retrieved documents and generates a truncated output is wasteful. The planning discipline stays the same regardless of window size: reserve output first, then allocate input.
How the budget works
For most models the context window is shared by input and output. The planner subtracts in this order:
remaining_for_context = window − output_reserve − system_prompt
If that number goes negative, the request will not fit. Because the model’s reply lives in the same window, reserving too little output truncates the answer; reserving too much starves your context. The bar shows the four segments — system, context, output, and free — proportionally.
Where budgets are typically wasted
Oversized system prompts are the most common problem. A system prompt that runs 4,000 tokens — full of repeated rules, elaborated examples, and redundant hedges — is billed on every single call. Cutting it to 1,500 tokens frees 2,500 tokens for user context on every request.
Uncontrolled retrieved context in RAG applications is the second most common issue. Without a hard token budget for retrieved documents, a retrieval step that returns ten long passages can consume most of the window before the user’s actual question arrives.
Tips
- Reserve output first. Decide how long the answer needs to be, then spend what’s left on input.
- Keep the system prompt lean. It’s billed and counted on every call; move large stable references into retrieved context instead.
- Leave a 5–10% margin. Token estimates and chat-template overhead mean the real count is a bit higher than your math.
- Set a hard limit on retrieved context. If you use RAG, cap the total tokens retrieved before they reach the prompt so the budget stays predictable.