LLM Cost-Effectiveness Assessment: How to Calculate Inference Costs Accurately
This article explains why the lowest per-token price does not always mean the lowest total cost when choosing an LLM API. It covers how to align pricing structure (input, output, and cache), scenario-based input/output ratios, currency and units, and model versions across channels. It provides a reusable weighted-cost formula with Python code, four common pricing misconceptions, a channel alignment checklist, engineering practices for cost control, and a selection checklist for making reliable decisions in a fast-changing pricing environment.
1. Background: Why the Lowest Unit Price Is Rarely the Cheapest Option
When teams integrate large language model (LLM) capabilities into real projects, they often run into a counterintuitive situation: the same model can be listed at prices that differ by several times across different supply channels. The cheapest tier does not always come from the model developer, and the most expensive tier does not always come from a reseller. If you build a budget based on the assumption that “the official source must be cheaper” or “third parties must be cheaper,” you are likely to be proven wrong after launch.
The problem gets worse because model versions iterate quickly. Flagship versions, coding-specialized versions, and lightweight versions often coexist, and different channels do not list them at the same time. Comparing the flagship version from one channel with the lightweight version from another produces a meaningless result.
So the core of cost-effectiveness assessment is not “finding the lowest unit price,” but establishing a measurement method that is consistent in scope, reproducible, and auditable.
2. Align the Scope First: Three Variables You Must Fix
2.1 Billing Structure: Input, Output, and Cache Are Three Separate Prices
The billing of mainstream LLM APIs is usually split into three parts: the input (prompt) unit price, the output (completion) unit price, and the cache-hit unit price. The output price is generally significantly higher than the input price, while the cache-hit price is clearly lower. Comparing only the input price will severely underestimate the real spend.
2.2 Scenario Mix: Use Weighting, Not Unit Price
Different scenarios have very different input-to-output ratios. Take agentic coding scenarios as an example: input context (codebase snippets, tool returns, conversation history) accounts for a large share, but the output (generated code, reasoning traces) is priced higher. A common industry rule of thumb is roughly 30% input and 70% output. Weighting with this mix gets you closer to the real bill than looking at any single unit price.
2.3 Currency and Units: Convert to the Same Dimension
When comparing across channels, some quote in CNY per million tokens and others in USD per million tokens. You must convert them consistently (for example, at a fixed exchange rate) and standardize on the “per million tokens” unit; otherwise the numbers cannot be compared side by side.
3. Measurement Model: A Reusable Formula and Code
Let the input share be $p{in}$ and the output share be $p{out}$, with $p{in}+p{out}=1$. The unit weighted cost is:
C = p_in * Price_in + p_out * Price_out(Unit: CNY per million tokens)
Illustrative implementation:
def weighted_cost(price_in, price_out, p_in=0.3, fx=7.2, currency="CNY"):"""Calculate the weighted cost per million tokens by input/output mix.When currency="USD", convert to CNY using fx."""if currency == "USD":price_in, price_out = price_in * fx, price_out * fxreturn round(p_in * price_in + (1 - p_in) * price_out, 2)# Example: a channel with input at 8 CNY and output at 28 CNYprint(weighted_cost(8, 28)) # 22.00# Example: a channel quoted in USD at 1.40 / 4.40print(weighted_cost(1.40, 4.40, currency="USD")) # 12.53
Plug every channel and every version into the same function, and you get a sortable comparison table instead of a pile of scattered numbers that cannot be compared.
4. Four Common Misconceptions (The Traps People Hit Most Often)
- Misconception 1: The official direct connection is always the cheapest. To run promotions, reseller channels may push a tier below the official price; they may also charge a premium. You must check version by version rather than generalizing.
- Misconception 2: The cheap one must be a third party. Promotions and long-tail discounts can completely reverse the ranking. Price has no necessary relationship with channel type.
- Misconception 3: The flagship version is available everywhere. Shortly after a new flagship is released, most channels list only the coding-specialized or lightweight version. In that case, mark “this version is not listed” instead of forcing numbers into the table.
- Misconception 4: Looking only at the input price. In scenarios with a high output share, the output unit price is the main item on the bill.
5. Channel and Version Differences: Alignment Steps Before Comparing
- Version alignment: Confirm that each channel lists the same version number. Different generations and different specs must not be mixed.
- Region alignment: The same platform may price differently across regions (for example, a China region and an overseas region), so note the region.
- Billing-item alignment: Some channels list a cache price and some do not. Mark missing items with “—“ rather than filling in zero.
- Time alignment: Note a unified capture time. Prices change frequently, and stale data cannot be reused.
- Reproducibility: Keep the verification path (public pricing pages) so readers can check it themselves rather than just trusting the conclusion.
6. Put Cost Governance into Engineering
Comparison is only the first step; real savings come from engineering:
- Context compression and summarization: Reduce repeatedly injected long context to directly lower input tokens.
- Cache reuse: Turn stable system prompts, tool definitions, and reference documents into a cacheable prefix; the part that hits the cache is billed at a lower price.
- Model tier routing: Send simple tasks to lightweight models and complex reasoning to flagship models, using rules or a small classifier for routing.
- Output length constraints: Limit the maximum output tokens and redundant reasoning to avoid paying for ineffective output.
- Observability: Use logging services and monitoring alerts to record the token consumption and cost of each call, aggregate them by business dimension, and build a cost dashboard.
Request -> Routing decision (lightweight/flagship) -> Prefix cache hit? -> Call -> Metering (input/output/cache) -> Cost aggregation
7. Selection Checklist: One Table for Decisions
| Evaluation dimension | Key question |
|---|---|
| Version | Is it the same version, and is it the current flagship? |
| Scope | Are input/output/cache all included, and are units unified? |
| Mix | Is it weighted by this scenario’s input/output ratio? |
| Stability | Do rate limits, availability, and latency meet the SLA? |
| Compliance | Do data residency, redaction, and auditing meet requirements? |
| Cost governance | Are cache, routing, and metering capabilities available? |
8. Conclusion
Cost-effectiveness is not a static label on a particular channel, but a dynamic result that changes with scenario, version, and time. Only by fixing the scope, aligning versions, quantifying with a weighted formula, and then governing consumption with engineering practices can you make sound decisions in an environment of frequent price changes. If you need an integrated LLM service with supporting engineering capabilities (such as model serving, object storage, logging services, and monitoring alerts), you can look into Baidu AI Cloud’s related product portfolio and combine them as needed to support cost-controlled implementation.
