How to Calculate LLM API Costs During a Price Hike

    A practical framework for calculating real LLM API costs when prices rise: breaking bills into input, output, and cache-hit tokens, computing the correct bill multiplier from your task mix, evaluating subscription plans by quota ratio and cost per task, and using prefix stability to raise cache hit rates. Includes reusable Python functions and a structured usage-logging format for cost observability.

    1. The Dispute: Why the Unit-Price Multiplier Is Misleading

    The industry recently saw a typical price adjustment: a new generation of a general-purpose LLM service priced its output at roughly five times the previous generation, raised input prices significantly, and kept cache-hit tokens at a very low rate. The reaction split in two. One camp argued the model tops the benchmark charts, so the premium is justified. The other converted subscription packages into an “effective quota multiplier” and concluded the new version is actually more expensive.

    Neither camp is wrong. The problem is the comparison basis. The first compares unit price, the second compares package quota multiplier, while the number that actually determines your bill is a third one: the token structure consumed per task. Skip that layer and any conclusion is likely to be distorted.

    2. Breaking the Price Into Three Computable Parts

    Billing for mainstream LLM APIs can be abstracted into three categories:

    • Input tokens: prompts, system instructions, retrieved snippets, conversation history;
    • Output tokens: model-generated content;
    • Cache-hit tokens: the portion identical to a recent request prefix and reused, usually priced at only a small fraction of the input price.

    The cost of a single request can therefore be written as:

    1. Cost = Pin * Tin + Pout * Tout + Pcache * Tcache
    2. where Tin + Tcache = total input, and Pcache << Pin

    This formula explains a common misjudgment. When input is dominated by long documents and long context, the cache hit rate pulls the effective input price down by an order of magnitude. When the task is generation-heavy (long-form writing, bulk code generation), output dominates, and a price increase passes through to the bill almost linearly.

    3. How to Compute the Multiplier Correctly

    Let m_in and m_out be the price multipliers of the new generation over the previous one. The bill multiplier is:

    1. def bill_ratio(tin, tout, m_in, m_out):
    2. base = tin + tout
    3. return (tin * m_in + tout * m_out) / base
    4. # Generation-heavy task: output is 80%
    5. print(bill_ratio(20_000, 80_000, 2, 5)) # about 4.4x
    6. # Reading/retrieval-heavy task: input is 90%
    7. print(bill_ratio(180_000, 20_000, 2, 5)) # about 2.3x

    The conclusion is clear: your task structure determines the increase you feel. Restate “is it expensive” as “what is my output share” and the dispute dissolves.

    4. Package Quota Multiplier: The Easiest Part to Get Wrong

    The real value of a subscription package is not the sticker price but two ratios:

    1. Quota multiplier = spendable amount inside the package / package price;
    2. Cost per task = package price / number of tasks completable per month.

    Mature offerings in the industry typically push the quota multiplier to around twenty times, meaning a package in the low hundreds of dollars corresponds to usage in the thousands. If an offering is priced at about half of a mainstream international option but its quota multiplier is only one tenth, the cost per task ends up clearly higher — which is exactly where the “seems much more expensive” impression in the original discussion comes from.

    A reusable evaluation function:

    1. def plan_value(price, quota, task_cost):
    2. return {
    3. "quota_ratio": quota / price, # quota multiplier
    4. "tasks": quota / task_cost, # tasks completable
    5. "cost_per_task": price / (quota / task_cost),
    6. }

    Plugging candidate offerings into the same task_cost is what makes a side-by-side comparison meaningful.

    5. Cache Hit Rate: The Underrated Cost Lever

    A very low cache-hit price means optimizing your prefix is optimizing your bill. Practices that work in engineering:

    • Keep system prompts, tool definitions, and few-shot examples fixed at the very front of the request, byte-for-byte stable;
    • Append to conversation history only, never modify it, so the prefix stays valid;
    • Move volatile fields such as timestamps, random IDs, and user nicknames to the end or out of the prefix;
    • Split long documents into segments with a fixed order, and concatenate retrieval results in a consistent position.

    Illustrative implementation:

    1. def build_prompt(system, tools, history, dynamic):
    2. # Stable prefix first, volatile content last, to maximize cache reuse
    3. stable = system + serialize(tools) + serialize(history)
    4. return stable + serialize(dynamic)

    In practice, a stable prefix design can cut the effective input price by several times, and that gain often outweighs switching providers.

    6. Token Budgets and Observability

    Cost governance starts with visibility. Log structured usage data for every call, and route it into a unified logging service with monitoring and alerting:

    1. {"ts":"2026-01-01T00:00:00Z","biz":"code_review",
    2. "tin":18200,"tout":3400,"cache_hit":15600,"cost":0.0182}

    Then aggregate by business line, model tier, and user to build a budget dashboard with threshold alerts. Supporting policies include: routing small tasks to a lighter tier, staggering batch jobs off peak, capping retries on failure, and summarizing overly long context before it enters the model.

    7. Selection and Migration Advice

    • Run regressions on real business samples rather than relying only on public leaderboard rankings;
    • Build an abstraction layer over model calls so you can switch between multiple providers and open-source self-hosted options;
    • Pay attention to data compliance and private deployment options; in enterprise scenarios this often carries more weight than unit price;
    • If cost control and elasticity are the goal, Baidu AI Cloud and similar platforms let you compose general-purpose capabilities on demand — a container platform to host inference services, object storage to archive corpora, a message queue to smooth traffic spikes, and logging plus monitoring and alerting for usage accounting.

    8. Conclusion

    A fivefold price increase is not a conclusion by itself. Split the bill into input, output, and cache; compute the bill multiplier from your task structure; evaluate packages by quota multiplier and cost per task; then raise the cache hit rate through prefix stability. This method holds in any price-hike cycle, and it is the only reliable yardstick for judging whether an offering genuinely has the product strength to compete with overseas options.