Cheaper LLM APIs: How to Calculate Your Bill and Where to Save
With LLM API prices dropping, many previously cost-prohibitive scenarios are back on the table. Using an example pricing set (input at 3 per million tokens, output at 6, cache hits at 0.3), this article explains how token-based billing works, why prefix caching saves money, how to calculate a realistic bill from input, output, and cache-hit composition, and how to estimate monthly costs from real usage logs.
1. First, Understand the Scope of the Price Cut
Recently, a platform published an example inference pricing set: input (cache miss) at 3 per million tokens, output at 6 per million tokens, and cache hits at 0.3 per million tokens. This article uses this set of prices for its calculations. It is only an example and does not represent the pricing of all platforms or all models. Before making a selection, always refer to the official pricing page and billing documentation of the relevant platform, and confirm the effective date, applicable models, and billing methodology.
The immediate benefit of lower prices is that costs become predictable in advance. In the past, scenarios like real-time customer service, batch analysis of long documents, and code review were often shelved because the cost per call was too high. When the cost per call drops to the level of a few cents, these scenarios re-enter feasibility evaluation.
2. Understand the Billing Unit First
Most commercial APIs bill by token. A token is the smallest unit of text a model processes. In English, roughly one word corresponds to one token; in Chinese, roughly one character or a word fragment corresponds to one token. Different models tokenize differently, so the same passage may produce different token counts on different platforms. Estimates should be based on the actual usage returned by the API.
The cost formula for a single call is:
Cost = token count ÷ 1,000,000 × unit price
For example, 100,000 tokens billed at the input price of 3 would cost 0.1 × 3 = 0.3.
2.1 The Difference Between Input, Output, and Cache Hits
A single request typically generates three categories of billable tokens:
| Category | Example price (per million tokens) | Typical source | Can it be optimized? |
|---|---|---|---|
| Input (cache miss) | 3 | New user questions, new documents, changing context | Yes, by trimming prompts |
| Cache hit | 0.3 | System prompts, conversation history, or fixed documents that exactly match the beginning of a previous request | Yes, by keeping prefixes stable |
| Output | 6 | Model-generated responses | Yes, by limiting response length and format |
In this example pricing, the output unit price is twice the input unit price. This ratio applies only to the example in this article. Other platforms and models may have very different input/output ratios—some larger, some closer. Compare unit prices directly when selecting a model; do not assume a fixed ratio.
Output costs more because of how generation works. During the input phase, the entire prompt can be computed in parallel. During the output phase, tokens are generated one by one, and each new token requires reading the existing KV cache, which places heavier pressure on compute and memory bandwidth.
When tracking costs, record input, output, and cache-hit tokens separately. Otherwise, you cannot tell where the money is going.
2.2 Why Prefix Caching Saves Money
To understand cache pricing, you first need to understand how a Transformer processes input. As the model reads each token, it computes the corresponding key-value vectors (the KV cache) for use in subsequent attention calculations. If two requests begin with exactly the same content—for example, the same system prompt or the same conversation history—then the KV computation results for that prefix are also identical.
Prefix Caching (also called context caching) takes advantage of exactly this. The server stores the KV results it has already computed. When a new request’s prefix matches the cache, the existing results are reused directly, and computation is only performed on the new portion. The cache-hit portion is billed at the cache price, while the missed portion is billed at the regular input price.
This brings two benefits. First, it saves compute and lowers the bill. Second, time to first token (TTFT) is noticeably reduced, because the long prefix does not need to be recomputed.
However, cache savings have prerequisites, and you cannot simply estimate them as a flat discount:
- The beginning of the request must match character for character. If a timestamp, username, or random ID slips into the system prompt, the prefix no longer matches and the cache is invalidated.
- The server must support prefix caching. Different platforms have different rules on minimum cacheable length, cache retention duration, and billing methodology.
- On a cache miss, those tokens are billed at the regular input price with no discount. Content that previously hit the cache may also revert to miss status once its retention period expires.
The conclusion of this section: the cache price is the upper bound of the discount. The actual bill depends on the stability of your request prefixes and the server-side policy. When estimating, first measure the real hit rate from historical logs, then estimate based on that proportion, and leave headroom.
3. How to Calculate a Real Bill
The low unit prices after a price cut can easily create a false impression of cost. What truly determines the bill is how much of each category—input, output, and cache hits—makes up one unit of business traffic.
Take 1 million tokens as an example, with the following composition:
- Input (cache miss): 600,000 tokens
- Cache hits: 200,000 tokens
- Output: 200,000 tokens
Calculating item by item at the example prices:
- Input (miss): 0.6 × 3 = 1.8
- Cache hits: 0.2 × 0.3 = 0.06
- Output: 0.2 × 6 = 1.2
Total: 1.8 + 0.06 + 1.2 = 3.06.
If those 200,000 cache-hit tokens were not served from cache and were all billed as cache-miss input, input would total 800,000 tokens, costing 0.8 × 3 = 2.4. Adding the 1.2 for output gives a total of 3.6. The cache saves 0.54 on this bill, a reduction of about 15%.
This example illustrates two points. First, the blended unit price under mixed billing is about 3.06 per million tokens—higher than the pure input price, because output accounts for a significant share. Second, output accounts for only 20% of the tokens but about 39% of the cost (1.2 ÷ 3.06). Therefore, controlling output generally delivers a higher return than controlling input.
For practical estimation, follow this sequence:
- From your logs, calculate the average input, output, and cache-hit token counts for each request type.
- Multiply by the corresponding unit prices to get the cost per request.
- Multiply by the average daily request volume to get daily cost, then multiply by 30 days to get monthly cost.
- Add a 10% to 20% buffer on top of the result to account for traffic spikes and context growth.
4. Three Actionable Practices for Saving Money and Selecting Models
4.1 Prompt Trimming
Applicable scenarios: applications with long system prompts, continuously growing conversation history, or heavy repetition of formatting instructions.
Steps:
- Remove background information irrelevant to the task; keep only rules, roles, and output format requirements.
- Place fixed instructions at the very beginning of the prompt, ensuring this portion is identical in every request so it can hit the cache.
- Set a window for conversation history, keeping only the most recent turns and replacing earlier content with a brief summary.
- Limit output length by specifying a word or character cap in the prompt, or by providing a structured template to reduce unnecessary
