A context window is the total token space available in one call: instructions, retrieved chunks, conversation history and the output all share it. A large window gives the model access to more material, but every token consumes compute, memory or a billable input category, and quality depends on relevance and order, not on size alone. Budgeting the window means deciding each part’s share before you send the prompt.
Before you start
The context window size of your model, in tokens, and a typical prompt with instructions, chunks and history.
List the four parts of the prompt
Write down the four parts: system instructions, retrieved chunks, conversation history, and the output reserve. Count the tokens in each part for a typical request, using a tokenizer, not a guess.
Include the output reserve: the model needs room to write its answer, and a prompt that fills the window leaves nothing to generate with.
Set each part’s share
Give the instructions a fixed small share, give the chunks the largest share, cap the history, and reserve output space. A common shape is 10 percent instructions, 60 percent chunks, 10 percent history and 20 percent output, but set the shares from your own counts.
Cap the history hardest: in a multi-turn conversation every prior message re-enters the token count with each new turn, so history grows the bill fastest.
Test the full prompt at the budget
Build the longest realistic prompt and count its tokens against the window. If it fits with room to spare, the budget works. If it overflows, cut the chunks first, then the history, never the instructions.
Log the token count per part for a week of real requests, and adjust the shares where one part keeps overflowing.
Practice check: fictional Maple Corner RAG, 32,768-token window
The table below is fictional practice material, worked out by hand from the stated shares. It is the expected result for the practice prompt, not a run of any API.
| Part | Share | Tokens | Verdict |
|---|---|---|---|
| Instructions | 10% | 3,277 | Pass |
| Retrieved chunks | 60% | 19,661 | Pass |
| History, capped | 10% | 3,277 | Pass |
| Output reserve | 20% | 6,553 | Pass |
| Total | 100% | 32,768 | Fits exactly |
The four shares add to 32,768 tokens exactly: 3,277 + 19,661 + 3,277 + 6,553 = 32,768. The prompt fits the window with the output reserve intact.
Expected result. UNTESTED: the token counts in the practice table are worked out by hand from the stated shares, not measured by running a tokenizer. Count the tokens in your own four parts, set the shares, and test the longest realistic prompt against your window.
Limits
- Token counts depend on the tokenizer: the same text is a different token count for different models.
- A budget that fits the window is not a budget that works: relevance and order matter more than size.
