Breaking Down Inference Costs by Token Type for Model Selection
This article explains how to estimate LLM inference costs by splitting tokens into uncached input, cached input, and output. It covers when cache hits occur, how to avoid billing the same tokens twice, and a daily budget example for a fixed knowledge base Q&A workload, using illustrative prices for two hypothetical models, Astra and Sol.
1. Confirm the Pricing Basis
The prices in this article are illustrative assumptions. Astra costs $8 per million input tokens, $0.40 per million cached input tokens, and $40 per million output tokens. Sol’s prices are derived from the assumption that Astra is 20% cheaper than Sol, which gives $10, $0.50, and $50 respectively. These are not official list prices. Before building a real budget, open the provider’s pricing page, check the current unit prices, and confirm whether cache write fees apply. The calculations below only demonstrate the method. Replacing them with real unit prices will change the results.
2. How Each Token Type Is Billed
Inference costs are usually calculated separately for three token types.
Input tokens are all the context sent to the model in each request. This includes the system prompt, retrieved reference material, and the user’s question. Input tokens that miss the cache are billed at the standard input price.
Cached input tokens are the part of the input whose prefix exactly matches a previous request and is still within the cache’s validity period. Their unit price is much lower than the standard input price. On Astra, the difference is $8 versus $0.40, a 20-fold gap.
Output tokens are everything the model generates. They have the highest unit price. For agent tasks, code generation, and long-form writing, output is often the main source of cost.
Several conditions determine whether a cache hit occurs. The prefix must match exactly, because any change invalidates the cache from that point onward. Cache entries have a time to live, and they must be written again after they expire. The prefix must also meet the minimum length set by the provider. Teams can track their cache hit rate daily. The hit rate is the number of cached tokens divided by the total number of input tokens. Measured figures are more reliable than estimates.
3. Do Not Bill Cached and Uncached Tokens Twice
Each token can be billed at only one price, and only once. If a fixed 50,000-token document is served from the cache, it is billed at the cached price only. It cannot also be counted in input costs at the standard input price.
This is an easy mistake to make. Suppose a team first bills the entire document at the input price, then bills the same document again at the cached price. In Scenario A below, the daily cost would be inflated by nearly 9 times. The correct approach is to split input costs into two parts:
- Uncached input cost = uncached tokens per request × number of calls × input unit price
- Cached input cost = cached tokens per request × number of calls × cached unit price
- Output cost = output tokens per request × number of calls × output unit price
If the fixed prefix length is P and the cache hit rate is h, the prefix cost per million requests can be written as P × (h × cached unit price + (1 − h) × input unit price). The higher the hit rate, the closer the prefix cost gets to the cached price.
4. Budget Breakdown
Scenario A: Fixed Knowledge Base Q&A
Each request includes a 50,000-token fixed knowledge retrieval result, which is a cacheable prefix, and a 1,000-token user question. The model outputs 500 tokens per request. The system handles 10,000 calls per day. This example assumes the cache always hits and excludes cache write fees.
- Uncached input: 1,000 × 10,000 = 10 million tokens. At $8 per million tokens, the cost is $80.
- Cached input: 50,000 × 10,000 = 500 million tokens. At $0.40 per million tokens, the cost is $200.
- Output: 500 × 10,000 = 5 million tokens. At $40 per million tokens, the cost is $200.
- Total daily cost: $480.
Without caching, the 50,000-token prefix would be billed at the standard input price. Input costs would rise to $4,080, and the daily cost would reach $4,280. Caching saves about $3,800.
