LLM API Cost Estimation and Model Selection: A Practical Guide
Choosing the cheapest LLM API per token rarely leads to the lowest bill. This guide shows how to calculate a blended unit price from cache-read, input-miss, and output pricing, weight it against your own traffic profile, adjust for discounts and tiered usage, and turn the whole process into a repeatable engineering workflow with usage collection, caching, and routing.
1. Why the Lowest Unit Price Is Not the Lowest Cost
The most common mistake teams make when deploying LLM applications is making decisions based on a single price tier. Vendors usually break pricing into three parts: the read price for cache hits, the input price for cache misses, and the output price for generated content. The gaps between them can be several times, or even an order of magnitude. If your traffic pattern does not match the assumptions behind the price list, the option that looks cheapest on paper may cost more on the actual bill.
So the core of cost evaluation is not comparing single-point prices, but building a weighted metric tied to your own traffic structure. This article calls it the “blended unit price,” using the industry-standard unit of CNY per million tokens.
2. Defining the Blended Unit Price and Where the Weights Come From
The basic form is:
blended price = w_read × read price + w_miss × input price + w_out × output pricewhere w_read + w_miss + w_out = 1
In long-context scenarios with obvious repeated prefixes—code assistants, document Q&A, batch calls with a fixed system prompt—cache hit rates are usually high, so a conservative set of reference weights can be used:
blended price = 0.8 × read + 0.1 × input + 0.1 × output
The meaning of the weights needs emphasis: they are not universal constants but a compressed expression of a “traffic profile.” 0.8/0.1/0.1 suits batch workloads with heavy cache reuse and short outputs. For conversational applications with long outputs and low prefix reuse, the weights should shift toward something closer to 0.2/0.3/0.5. Teams should measure the actual share of the three token types from real logs and write the weights back, rather than copying someone else’s parameters.
3. From Price Table to Leaderboard: A Reusable Process
Step 1: Unify units and definitions. Normalize all prices to CNY per million tokens, and note whether they are tiered and whether they vary by context-length band.
Step 2: Handle the time dimension. Dual-tier pricing for “off-peak / peak” hours is common in the industry; calculate each separately, then use the distribution of your actual call times as a secondary weight to get a time-weighted blended unit price.
Step 3: Handle missing values. If the read, input, or output price for a tier is not published or cannot be verified, mark it as “not ranked” instead of filling in zero or a guess, which would pollute the ordering.
Step 4: Sort and segment. Using the reference weights 0.8/0.1/0.1, typical results fall into three clear bands:
- Tier 1 (blended price roughly 0.3–1.4): lightweight and high-speed models, suited to high concurrency, short outputs, and strong caching;
- Tier 2 (roughly 1.9–5.5): balanced mid-tier models, suited to general Q&A and medium-complexity generation;
- Tier 3 (roughly 6.7–27.3 and above): high-capability models, suited to complex reasoning and long-chain tasks, requiring strict rate limiting and caching.
The specific numbers shift as vendors adjust prices; the method does not: weight first, then rank, then match to business tiers.
4. Effective Price: A Second Pass for Discounts, Rebates, and Tiers
The second line of the leaderboard is the “effective price.” Enterprise procurement usually comes with discounts, tiered rebates, vouchers, and committed usage, so the effective blended unit price may be only a small fraction of the list price. The standard approach is to introduce a discount factor:
effective blended price = blended price × discount factordiscount factor = amount actually paid / amount payable at list price
Three cautions: the discount factor should be recalculated on a rolling basis per billing cycle, not estimated once; tiered pricing means the factor changes with usage and should be expressed as a piecewise function; different tiers (such as the high-speed tier) may not share the same discount scheme and need separate modeling. Maintaining both leaderboards—list price and effective price—side by side is what lets you answer both “does the capability fit” and “is the budget sustainable.”
5. Turning Cost Estimation into an Engineering Loop
Estimation should not stop at a spreadsheet; make it an executable process:
def blended_price(p_read, p_miss, p_out, w=(0.8, 0.1, 0.1)):return w[0]*p_read + w[1]*p_miss + w[2]*p_outdef rank(models, weights=(0.8, 0.1, 0.1), discount=1.0):rows = []for m in models:if None in (m["read"], m["miss"], m["out"]):continue # price unverified, excluded from rankingrows.append((m["name"], blended_price(m["read"], m["miss"], m["out"], weights)*discount))return sorted(rows, key=lambda x: x[1])
Three engineering capabilities are needed alongside it. First, usage collection: use logging services and monitoring alerts to break down token structure by model, scenario, and time period. Second, caching strategy: stable prefixes, fixed system prompts, and reused context can significantly raise the hit rate, amplifying the gains from the heavy weight on the read price. Third, routing and fallback: serve high-frequency short requests with the low-cost tier and complex requests with the high-capability tier, with retry budget control for failed requests.
6. Common Pitfalls and Practical Recommendations
Pitfall one: using the output price to represent overall cost while ignoring the share of cache reads. Pitfall two: treating reference weights as an industry standard. Pitfall three: ignoring the nonlinearity caused by peak hours and tiered bands. Pitfall four: forcing unverified prices into the ranking.
The recommendation is to maintain a four-dimensional table of “model—weights—discount—measured unit price,” review it quarterly, and recompute the weights after every change in traffic structure. If an organization already uses Baidu AI Cloud’s model services along with general capabilities such as object storage, logging, and monitoring alerts, the process above can be embedded directly into the existing observability stack to make cost visible and selection automatic, turning cost optimization from a one-off analysis into a continuously running mechanism.
