How AI Token Billing Works: Reproduce a Multi-Turn Cost Estimate
Work through input, output and retained history, then calibrate the estimate with your model’s usage and prices.
Count the request you actually send
Input can include system instructions, retained messages, tool schemas, retrieved passages and the latest question. A short message in a UI can still generate a request with a long history. Tokenization, message formatting and attachment handling vary by model. Use the AI Token Calculator for rough estimates with public samples. Plan your budget with the model’s counting endpoint and actual usage data.
Reproduce the cost of retaining history
Let the first request contain A input tokens and each successive turn add G. Across N requests, total input is N × A + G × N × (N − 1) ÷ 2. With A = 600, G = 400 and N = 4, the four requests contain 600, 1,000, 1,400 and 1,800 tokens, for 4,800 total. Keeping only the most recent turn of history could cap requests 2–4 at 1,000 each, for 3,600 total. That saves 1,200 input tokens in this example. Include the cost of generating any summary and check that truncation preserves the information needed to finish real tasks.
Translate usage into a bill
At 400 output tokens per turn, each conversation produces 1,600 output tokens. With illustrative prices of $0.25 per million input tokens and $1 per million output tokens, 1,000 such conversations cost 4.8 × $0.25 + 1.6 × $1 = $2.80. Use your model’s rates and account separately for cache reads or writes, tool fees and reasoning usage where applicable.
Calibrate with real calls
- Run a small sample of representative requests with the same model. Record first- and last-turn usage and error counts.
- Try a sliding window or shorter tool descriptions on the same requests. Compare input tokens and task quality.
- Compare per-minute requests, per-minute tokens and daily volume with your dashboard. Use a small load test for limits the dashboard omits.
References: Gemini token counting and OpenAI prompt caching.