Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path
Context Budget & Cost Planner
Add a system prompt, tool definitions, conversation history and retrieved context, then see your context window fill up and the cost per call — plus the bill at 1k and 1M requests — across model price tiers. An architecture planner, not a toy token counter.
Every turn of a conversation re-sends the whole context, so the bill depends on what sits in that context far more than on the user's question. This planner adds up the system prompt, tool definitions, retrieved documents and growing chat history, shows how the context window fills, and prices one conversation, a thousand conversations, a day and a month on one of three price tiers.
What it computes
Call the fixed part of every request B: system prompt + tool definitions + RAG context. Turn i of a t-turn conversation sends B, the i user messages so far and the i − 1 earlier replies:
input on turn i = B + i × u + (i − 1) × r
total input = t × B + u × t(t + 1)/2 + r × t(t − 1)/2
total output = t × r
peak context = B + t × (u + r)
cost/conversation = input/1M × P_in + output/1M × P_out
cost/day = cost/conversation × requests per day
cost/month = cost/day × 30
- u: user tokens per turn. r: output tokens per turn; each reply becomes history for the next turn.
- t: turns in one conversation. One "request" in the daily volume is one whole conversation.
- P_in, P_out: the selected tier's price per million tokens. The built-in tiers are $3/$15, $1/$5 and $0.25/$1.25.
The colored bar splits the peak context into system prompt, tools, RAG and history, where history is t × (u + r). Token counts are entered directly; the tool does not tokenize text.
A worked example
The defaults: a 900-token system prompt, 1,200 tokens of tool definitions, 3,000 tokens of RAG context, 150 user and 400 output tokens per turn, 8 turns, the $3/$15 tier and 10,000 conversations a day.
- Fixed context:
B = 900 + 1,200 + 3,000 = 5,100tokens, sent on all 8 turns, so 40,800 tokens. - User messages:
150 × 36 = 5,400. Replies re-sent as history:400 × 28 = 11,200. - Total input: 57,400 tokens. Output:
8 × 400 = 3,200. - Peak context:
5,100 + 8 × 550= 9,500 tokens, split 9.5% system, 12.6% tools, 31.6% RAG and 46.3% history. - Cost per conversation:
57,400/1M × $3 = $0.1722plus3,200/1M × $15 = $0.0480= $0.2202. - Scale: $220.20 per 1k conversations, $2,202.00 a day and $66,060 a month.
The same conversation on each tier:
| Tier | Per conversation | Per day | Per month |
|---|---|---|---|
| Frontier ($3 / $15) | $0.2202 | $2,202.00 | $66,060 |
| Mid ($1 / $5) | $0.0734 | $734.00 | $22,020 |
| Small ($0.25 / $1.25) | $0.0183 | $183.50 | $5,505 |
Note where the input goes: the fixed context accounts for 40,800 of the 57,400 input tokens, 71%, even though history is the largest slice of the peak window.
Assumptions and limits
- Uniform turns. Every user message and reply has the same length. Real conversations vary, and one long pasted document changes everything after it.
- Full history, every turn. Nothing is summarized, windowed or dropped, and RAG context is retrieved once and kept for the whole conversation.
- No caching. Every input token is billed at the full input price. Providers that cache a repeated prefix bill it at a discount, which mostly hits the fixed context.
- Three fixed tiers. The prices are illustrative points, not a specific vendor's list. The model's context window is not checked against the peak.
- A 30-day month at constant daily volume.
How to use the result
- Attack the slice that repeats most. The fixed context is billed once per turn, so in a long conversation it is usually the cheapest place to win: a shorter system prompt, leaner tool schemas, fewer RAG chunks or a cached prefix.
- Cap history when turns grow. History cost rises with the square of the turn count, so beyond a few turns a rolling window or a running summary pays for itself.
- Test one lever at a time. Halving RAG context to 1,500 tokens brings the default to $0.1842, 16% less. Comparing levers this way stops you from optimizing the wrong slice.
- Keep peak context well inside the window. Leave room for the reply and for the longest conversations, not the average one.
- Route by difficulty. Each tier down is 3 to 4 times cheaper here, so sending routine turns to a smaller model can beat any prompt trimming.
When to use it, and when not
Use it while a chat feature is still on paper: to set a token budget for each slice, choose a price tier, decide when history needs a window or a summary, and turn expected traffic into a monthly figure before launch.
It models one model call per turn. Agents that make several calls inside a turn, each re-sending the growing context, are better priced with an agent-loop estimator. Once you have traffic, sum the token counts your provider returns with each response; they include caching, real message lengths and conversations that end early.
Trade-offs and limits
| Ignored | Direction | Size with the defaults |
|---|---|---|
| Uneven conversation lengths | Understates | Half at 4 turns and half at 12 average $0.2334, 6% above 8 turns every time, because history cost is quadratic |
| Prefix caching | Overstates | Caching only the 5,100-token fixed context at an illustrative 10% of the input price puts 35,700 tokens in cache reads and costs $0.1238, 44% less |
| Fresh retrieval each turn | Understates | If every turn adds 3,000 new RAG tokens and keeps the old ones, the peak reaches 30,500 and the cost $0.4722, 2.1× |
| History windowing | Overstates, if you use it | Keeping only the last 2 exchanges costs $0.1955 at 8 turns, 11% less, and $0.3959 at 16 turns, 27% less |
The window saving grows with length because it removes the quadratic term: past the window, every turn costs the same. The price is memory, since anything older than the window is gone unless a summary carries it forward.
Common mistakes
- Entering API calls as requests. The daily volume counts whole conversations. 10,000 calls a day from 8-turn chats are 1,250 conversations, or $275.25 a day; entering 10,000 overstates the bill eightfold.
- Counting tokens, not dollars. Output is 3,200 of the 60,600 tokens in the default, about 5%, yet at five times the input price it is $0.0480, 22% of the cost.
- Putting changing content first. Caching reuses a prefix that is identical from the start. Keep the system prompt and tool definitions first and the retrieved chunks, which change per conversation, after them.
- Sizing the window for the average conversation. The peak grows by 550 tokens a turn here. The longest conversations you allow, not the typical one, must fit.
- Retrieving on every turn without dropping old chunks. Each new set of chunks becomes history for every later turn, the 2.1× case in the table above.
Check yourself
At 16 turns, what is the peak context, and what share of the billed input is the fixed context?
Peak: 5,100 + 16 × 550 = 13,900 tokens. Total input is 150,000, of which 16 × 5,100 = 81,600 is fixed, 54%. At 8 turns it was 71%: the longer the conversation, the more the history matters.
Which saves more: cutting tool definitions from 1,200 to 400 tokens, or replies from 400 to 200?
Tools: $0.2010, 9% less. Replies: $0.1794, 19% less. Each reply is billed once at the output price and then re-sent as input on every later turn, so it pays twice.
When does history overtake the fixed context, in the window and in the bill?
In the window, when t × 550 > 5,100: at 10 turns (5,500). In the bill it takes until 20 turns, where re-sent history is 107,500 input tokens against 102,000 fixed, because history starts small on each conversation and only the late turns carry much of it.
How it works
- Each turn re-sends system prompt + tools + RAG context + the full history as input.
- Cost = input tokens × input price + output tokens × output price, per 1M tokens.
- Peak context = fixed context + every user message and reply in the conversation.
- Token counts are entered directly; pick one of three price tiers; a month is 30 days.
Frequently asked questions
How is LLM API cost per conversation calculated?
Add up the input tokens of every turn and multiply by the input price per million, then add the output tokens times the output price per million. Input includes everything sent on each turn: the system prompt, tool definitions, retrieved context and the conversation so far. With the defaults, 57,400 input tokens at $3 per million is $0.1722 and 3,200 output tokens at $15 per million is $0.0480, so one 8-turn conversation costs $0.2202.
Why do long conversations cost more per turn?
Because every turn re-sends the fixed context plus the whole history so far. Turn 8 of the default conversation sends 5,100 fixed tokens, eight user messages and seven earlier replies, 9,100 input tokens in all, while turn 1 sends 5,250. The history terms grow with the square of the number of turns, so doubling the default from 8 to 16 turns raises the cost per conversation about 2.5 times, from $0.2202 to $0.5460.
What counts toward the context window?
The system prompt, every tool or function definition, any retrieved documents and the full message history all share one window, along with the reply the model is generating. The planner reports the peak context, which is the fixed context plus every user message and reply in the conversation, and splits it into four colored segments. With the defaults the peak is 9,500 tokens, and history is the largest segment at 46%, ahead of RAG context at 32%.
What is the difference between peak context and total input tokens?
Peak context is the size of the conversation at its largest, which is what has to fit inside the model's context window. Total input tokens is the sum of what was sent on every turn, which is what you are billed for, because the provider processes the whole prompt again on each call. In the default example the peak is 9,500 tokens but the total billed input is 57,400, about six times larger, because the fixed context alone is sent eight times.
Does the planner count tokens from my text?
No. Each slider takes a token count directly, so measure or estimate your own. A common rule of thumb for English prose is about four characters per token, so a 3,600-character system prompt is roughly 900 tokens, while code, JSON and non-English text often take more tokens per character. For billing-grade numbers, run your real prompt, tool schemas and a sample conversation through your provider's tokenizer or token-counting endpoint.
Which price tier should I choose?
The three tiers are fixed price points built into the tool: $3 and $15, $1 and $5, and $0.25 and $1.25 per million input and output tokens. Pick the one nearest your model's list price. Because every tier prices output at five times input, cost scales exactly with the tier: the default conversation costs $0.2202 on the first, $0.0734 on the second and $0.0183 on the third, so each step down divides the bill by 3 and then by 4.