How to Evaluate the True Cost of LLM API Usage
This article explains how to move beyond the list price per million tokens and model the true cost of LLM API usage. It breaks billing into input, output, cache hit/miss, and add-on charges; distinguishes list, effective, and task prices; shows why prompt caching matters for long-context workloads; and provides a replay-based comparison method, scenario-based tiering, and application-level cost controls. Readers can use these steps to estimate, compare, and govern LLM API costs using their own contract prices and workload samples.
Discussions about LLM API pricing often stop at the sticker price per million tokens. For engineering teams, that is only one factor in the bill. The real cost depends on how requests are assembled, how much context is resent, how long outputs are, and whether failed retries and tool calls are counted within the same business task. Comparing only output unit prices can overestimate or underestimate whether a design is sustainable.
Break the Bill into Calculable Items
Common text inference billing separates at least three usage categories:
- Input tokens: system prompts, retrieved chunks, conversation history, user questions, and text from tool returns that is sent back to the model.
- Output tokens: generated body text, structured results, and sometimes the reasoning process if the provider counts it as output.
- Cache hits and misses: for repeated prefixes or reusable context, some services bill at a lower input price; first writes or prefix changes are billed at the miss price or may even incur separate cache write charges.
Do not assume that input is always cheaper than output and can be ignored. Long system prompts, large retrieved materials, and multi-turn history often make input the main cost, while code generation and long reports make output the main cost. These two scenarios must be modeled separately.
A schematic formula is:
Cost per call = cached input tokens × cached input unit price+ uncached input tokens × uncached input unit price+ output tokens × output unit price+ other add-ons
Add-on items include peak surcharges rather than batch discounts, long-context premiums, tool call counts, failed retries, and whether logging and safety review are billed separately. Providers also do not use exactly the same definition of “per million tokens”: whether special tokens are included, whether partial output on a refusal is billed, and how cache keys are segmented can all change the result. Before signing or selecting a provider, validate usage with the same set of replay requests instead of trusting theoretical values on the price sheet.
List Price, Effective Price, and Task Price Are Not the Same
Looking at price at three levels makes conclusions much more stable.
The first level is list price: the public unit prices for input and output. It is suitable for order-of-magnitude screening, not budgeting.
The second level is effective price: the weighted input unit price after discounts under the real cache hit rate. If cached input is far lower than uncached input, a seemingly expensive miss price may not dominate the bill. Conversely, if prefixes often change, cache discounts barely apply and the effective price will be close to the miss price.
The third level is task price: the sum of all calls needed to complete one business goal. A single “answer the user” task may include retrieval query rewriting, the main answer, citation validation, and failed retries. Optimizing only the main answer’s output unit price can still leave a high task price.
There have been promotional prices well below sustainable cost to gain call volume and ecosystem position. As model capability, context length, and supporting service quality improve, prices returning to a range that covers compute and R&D is not surprising. For buyers, a price increase itself is not the conclusion. The question is whether quality, latency, stability, and context capability changed along with the same task price. If only the list price rose while task success rate stayed the same, the budget should increase; if longer context reduces multi-hop calls, the task price may not rise in step.
Public list prices for text inference vary widely across providers and regions. A much lower output price only shows that the screening range is large; once hit rate, output length, or retry rate differs, a cheaper sticker price can produce a higher task price.
Why Cache Discounts Are Critical for Long-Context Workloads
Many people remember only the regular price and ignore prefix reuse. The economics of caching are direct: separate stable, repeated context from variable user content so that the stable part repeatedly hits a lower price tier.
The biggest beneficiaries are usually “long and stable prefixes + short and variable suffixes”:
- Retrieval augmentation: system instructions, output format, and permission rules stay unchanged, while only retrieved chunks and questions change each turn. If chunks repeat across turns (same knowledge base, same session topic), the hit rate is even higher.
- Customer service and workflow bots: persona, compliance language, and tool instructions consume many tokens, while each user utterance is short.
- Code review and repository Q&A: coding standards, architecture constraints, and directory descriptions can be cached; change diffs and specific questions go in the suffix.
Once the hit rate rises, input-side cost can be significantly lower than the theoretical value of “all at miss price.” As a rule, if the hit price is about one fifth of the miss price and 80% of input comes from a stable prefix, the weighted input price will be around 30% of the miss price. This is arithmetic, not a promise from any provider: let miss price be U, hit price be 0.2U, and hit proportion be h. The effective input unit price is approximately (1-h)×U + h×0.2U = U×(1-0.8h). At h=0.8 it is about 0.36U; at h=0.9 it is about 0.28U. Output receives no such discount, so for tasks with a high output share, caching alone cannot control the total bill.
Caching is not free lunch. A small prefix change can invalidate the whole segment: adding timestamps, random numbers, or user nicknames to the system prompt, or inserting retrieval results in the middle of the prompt rather than at the end, can break the “stable prefix.” In engineering, fix the prefix content at the byte level, move variable fields to the end, and use separate cache keys for different agents and different specification versions to avoid incorrect reuse.
Compare with the Same Sample Set, Not Gut Feeling
Fix a set of replayable samples covering at least four categories: short Q&A, long-context multi-turn, retrieval augmentation, and high-output. For each category, record total input tokens, cacheable prefix length, output length, call count, retry count, end-to-end latency, and human or automated quality score. Then change only one variable: model tier, whether caching is enabled, number of retrieved items, or history truncation policy.
A schematic record can be:
| Sample group | Calls | Cached input | Uncached input | Output | Quality pass rate | P95 latency |
|---|---|---|---|---|---|---|
| Short Q&A | 1 | 0.2k | 0.3k | 0.4k | 0.91 | 1.2s |
| Multi-turn retrieval | 3 | 18k | 4k | 1.5k | 0.86 | 3.4s |
| Long-form generation | 1 | 1k | 2k | 12k | 0.84 | 8s |
Use your team’s contract unit price to fill in amounts; do not borrow numbers from someone else’s article as a budget. Pass rate must be viewed together with cost: cheaper but lower pass rate means rework and human review will push the task price back up.
Quality dimensions should include at least factual consistency, format compliance, tool call success rate, and whether refusals are reasonable. For latency, distinguish time to first token from total time; interactive products are sensitive to first token, while batch processing cares more about throughput and failure rate. A large context window does not mean you should fill it: very long input increases miss cost and may dilute key information. First use retrieval and summarization to keep relevant material at the necessary length, then consider putting everything into a very long window.
Choose Tiers by Scenario, Not Always the Highest Tier
Tiers usually combine capability, speed, and price. In practice, route by task risk instead of sending every request through the same price band.
- Classification, routing, query rewriting, and simple extraction: low-latency, low-price tiers are often sufficient, and frequent calls amplify unit price differences.
- Multi-document synthesis, complex code changes, and high-risk decision support: higher-capability tiers cost more per call, but if they reduce retries and manual edits, task price may be lower.
- Asynchronous batch processing: use queues to shave peaks and allow longer deadlines in exchange for lower unit compute cost; interactive paths prioritize stable latency.
Routing itself has costs: a router model can misjudge and send hard problems to a low tier or easy problems to a high tier. Calibrate routing thresholds with a small labeled sample and default low-confidence requests to the higher tier.
Set a cap on maximum output length. Without length constraints, occasional verbose generations in customer service answers or review comments can raise output cost and slow downstream. For long-form tasks, use segmented generation plus validation so that one failure does not rerun the entire output.
Cost Governance Belongs in the Application, Not Only in Month-End Bills
Actionable control points include:
- Version prompts. Publish stable prefixes separately and prohibit dynamic fields in the prefix. Changing a prefix means deliberately giving up hit benefits for a period and should be counted as a release cost.
- Trim history. For multi-turn conversations, keep conclusions and open questions and discard intermediate chatter already absorbed by summaries; if tool raw text can be stored externally, do not feed it all back.
- Set a retrieval budget. Limit the number of recalled items and the length of each item, and deduplicate repeated chunks. Retrieval augmentation that “looks smarter” is sometimes just more expensive context.
- Constrain output. Use explicit length and structure requirements to reduce wasted tokens; when parsing fails, retry only the differing part instead of replaying the entire long prefix.
- Observe. Break down hit rate, input/output ratio, and task price by application, tenant, and prompt version. A sudden drop in hit rate often means the prefix was changed or the cache key is unstable, not natural traffic fluctuation.
- Add budget guardrails. Set thresholds for per-request tokens, per-user daily cost, and abnormal retries; when exceeded, degrade to shorter context or a lower tier and alert.
These measures do not depend on any one model vendor’s proprietary API; a general gateway, logs, and monitoring can implement them. Object storage is suitable for retaining replay samples, message queues for peak shaving and asynchronous recomputation, and container platforms for deploying routing and billing sidecars. The key is that billing fields can be aligned with request identifiers; otherwise you cannot infer from a rising total bill whether hit rate, output length, or retries are responsible.
How to Judge Whether It Is Expensive
Answer the following questions and the price judgment will be more complete.
- Is the comparison baseline list price, comparable capability in the same region, or an international option for the same task? The answers can differ; state the baseline.
- In this scenario’s input, is the stable prefix share high enough, and can the cache keys actually hit?
- What share of tokens per call is output? When output is expensive, cache discounts feel weaker.
- Do the context window and maximum output reduce split calls? If not used, do not pay a premium for a “larger window.”
- After the quality pass rate changes, are human review and retries included in the task price?
- Did a price increase from an early promotional period bring improvements in availability, context, or tool reliability? If not, renegotiate the tier or change the architecture instead of accepting it by default.
For most developers, a low-price tier with a high hit rate can still keep interactive application costs in an operable range; high-price tiers should be reserved for steps where errors are costly. After commercialization, vendors are unlikely to keep pricing below cost to gain share for a long time. Procurement assumptions should shift to “price reflects capability and resources,” and acceptance should use task price rather than slogans.
When selecting on a cloud platform such as Baidu AI Cloud, check the same generic billing items and your own replay results: whether input distinguishes cache hits, how output is metered, whether long context has segmented pricing, and whether failures are billed. Do not put specific unit prices from external articles directly into a budget; contract unit prices, metering definitions, and your own business samples are the only valid price conclusion.
