How to Calculate the Real Cost per Task for Large Language Models

    A practical guide to calculating the actual cost per task of large language models. It breaks the cost formula into four variables, explains why smaller or cheaper-token models can consume more tokens, and provides a code-based measurement method along with an engineering checklist for reducing costs. Readers will learn to evaluate models by effective cost per task rather than token price alone.

    1. The Problem: Matching Capabilities, Unequal Bills

    A common pattern has emerged in the industry: two large language models with nearly identical capability scores can differ by more than 3x in token price, yet when the cost is measured by “completing one real task,” the gap shrinks to around 20%. Many teams look only at the price per million tokens during selection, then find the bill after launch does not match expectations. The problem is usually not the unit price, but how many tokens it takes to complete the same thing.

    This can be reduced to a general principle: the actual cost of using a model = unit token price × total tokens consumed to complete the task. A capability score only determines “whether it can do it,” while token efficiency determines “how much it costs.” Both are required.

    2. Breaking Down the Cost Formula: Four Variables Decide the Final Bill

    Let the cost per task be C, input tokens be In, output (including reasoning) tokens be Out, input unit price be Pi, and output unit price be Po (both are prices per million tokens). Then:

    1. C = (In / 1e6) * Pi + (Out / 1e6) * Po

    The engineering meaning of the four variables:

    • Capability score: Determines task success rate and rework rate. A low score leads to retries, secondary validation, and manual fallback. These hidden costs often exceed the tokens themselves.
    • Parameter size (total and activated): Affects the capability ceiling and inference resource usage. Under a sparse architecture, the activated parameters are the real compute for a single forward pass, so “small total parameters” does not mean “cheap inference.”
    • Inference token volume: Includes the reasoning process and the final output. Reasoning models tend to produce longer output, and this part directly inflates the bill.
    • Price structure: Input and output are usually priced separately, and the output price is generally higher than the input price, so long-output scenarios have a larger impact on the total.

    An illustrative example (numbers are only to demonstrate the calculation): Model A has an output price of 4.4 and 41K output tokens per task; Model B has an output price of 15 and 25K output tokens per task. Looking only at the output side, A is about 0.18 and B is about 0.375, so the token price advantage is clear. But once the input side and fixed overhead are added, the per-task cost of the two converges to the same order of magnitude. A unit price advantage gets eaten up by token efficiency, and this is the easiest pitfall in cost evaluation.

    3. Why a “Smaller Model” Can Cost More Tokens

    Post-training optimizations (such as preference alignment, reasoning-chain reinforcement, and tool-calling training) can significantly improve the capability output per parameter, allowing a model with a smaller activated size to match a larger one. But these optimizations often come with side effects:

    1. Reasoning redundancy: The model tends to expand longer reasoning chains to trade for accuracy, pushing up output tokens.
    2. Verbose style: Explanatory expression increases and the proportion of structured output drops.
    3. Retry amplification: Unstable formatting causes parsing failures, triggering retries and doubling the cost.

    So when evaluating a model, the “token budget per task” should be treated as a first-class metric, not something measured after the fact.

    4. A Practical Cost Measurement Method

    Teams are advised to build a selection measurement sheet with fields including: capability score, input/output unit price, average input tokens, average output tokens, task success rate, and average retry count. When calculating, use “effective cost” rather than “list price cost”:

    1. def task_cost(pi, po, in_tok, out_tok, success=1.0, retry=1.0):
    2. base = (in_tok / 1e6) * pi + (out_tok / 1e6) * po
    3. return base * retry / max(success, 1e-6)
    4. # Illustration: lower unit price but longer output, so the effective cost advantage is compressed
    5. a = task_cost(1.4, 4.4, 8000, 41000, success=0.95, retry=1.05)
    6. b = task_cost(3.0, 15.0, 8000, 25000, success=0.97, retry=1.02)
    7. print(round(a, 3), round(b, 3))

    The key point: only by including success rate and retry count in the formula can you explain the phenomenon of “large list-price gap, small actual gap.”

    5. An Engineering Checklist for Reducing Costs

    • Slim the context: Deduplicate and summarize retrieved snippets to control input tokens. Input is often overlooked, but its share is considerable under high concurrency.
    • Constrain the output: Use structured templates, field whitelists, and maximum length limits to compress output; when necessary, separate “reasoning” from “delivery” and apply billing-style management only to the delivery part.
    • Cache and reuse: Apply result caching and semantic caching for repetitive requests, combined with a message queue for peak shaving.
    • Tiered routing: Send simple tasks to small models or rules, and escalate complex tasks, forming a cost gradient.
    • Observability: Use logging services and monitoring alerts to track tokens per task, success rate, and retry rate, forming a closed loop for continuous optimization.
    • Elastic resources: Scale container platforms on demand, and use object storage to hold long-text corpora, avoiding idle resources.

    6. Selection Conclusion

    The capability score determines “whether it is usable,” while token efficiency determines “whether it is affordable.” When two models have close scores, the real dividing line is cost per task and stability. It is recommended to run a small-scale canary with real business samples, measure the effective cost, and then make a large-scale decision, rather than being led by the price sheet. In related practices at Baidu AI Cloud, it is also recommended to build a measurement and observability system using general-purpose capabilities (monitoring alerts, logging services, and container platforms) so that costs can be quantified and reviewed.