Large Language Model Token Pricing Explained: A Practical Guide to Cost per Task Optimization

    Billing an LLM call is not a matter of a single "output price." This guide breaks down the three billing units behind every call — uncached input, cache-hit input, and output — and explains why output tokens cost more. It then replaces the "per million tokens" comparison with cost per successful task, covering how to calculate blended pricing and unit economics, how subscription plan leverage compares with pay-as-you-go, and which knobs engineers actually control: cache-friendly prompt design, output constraints, model tier routing, and retry governance. You'll also find a minimal logging schema, cost estimation code, and a six-question checklist for choosing a model setup.

    1. First, Correct a Common Intuition: Model Cost Is Not a Single Price

    When teams see that “the output price is several times higher than the previous generation’s,” their first reaction is often “so my bill will go up by several times.” That inference is not sound from an engineering perspective. The actual cost of a single LLM call is made up of three distinct billing units:

    Billing unit Corresponding compute stage Relative price (general pattern)
    Input tokens (cache miss) Prefill: the entire context is processed in one parallel pass Baseline, 1x
    Cache-hit input tokens Hits a cached common prefix, so repeated computation is skipped Well below baseline, often around 1/10
    Output tokens Decode: tokens are generated one at a time, sequentially Typically 2–5x the input price

    Why is “output is the most expensive” an industry-wide pattern rather than one vendor’s pricing strategy? It follows directly from hardware and algorithmic characteristics. Prefill is a large-scale matrix multiplication, which is compute-bound and keeps accelerator utilization high. Decode, by contrast, generates only one token per step. Each step repeatedly moves all weights and the KV cache from GPU memory, which makes it memory-bandwidth bound, so the same card produces far less per unit of time. Since the hardware cost per unit of output is higher, pricing output above input is an inevitable outcome. Cache hits are cheaper because they skip prefill altogether and only involve reuse at the memory level.

    The conclusion is straightforward: to evaluate a model’s price, you have to look at three numbers at once — the output unit price, the cache discount ratio, and how your own business traffic is distributed across these three token types. Fixating on the output unit price alone is the most common cost misjudgment.

    2. Change the Unit of Comparison: From “Per Million Tokens” to “Cost per Task”

    Unit prices alone cannot answer whether your business can afford a given setup. The truly comparable metric is cost per task: the total spend required to complete one user-visible task. You calculate it by first converting the bill into a blended unit price, then multiplying that by the task’s average token consumption.

    2.1 Blended unit price

    1. blended_price = (C_in * P_in + C_cache * P_cache + C_out * P_out)
    2. / (C_in + C_cache + C_out)
    3. where:
    4. C_in uncached input tokens
    5. C_cache cache-hit input tokens
    6. P_in input price
    7. P_cache cache-hit price
    8. C_out output tokens
    9. P_out output price

    2.2 Cost per task

    1. cost_per_task = blended_price * avg_tokens_per_task * (1 + retry_rate)
    2. unit_economics = cost_per_task / success_rate

    Pay attention to that final division. A model with a cheap unit price but only an 80% success rate and 1.5 retries on average can easily have a higher cost per successful task than a model that costs twice as much per token but succeeds on the first try. You have to account for this layer in engineering, or your cost optimization will go off track.

    2.3 An illustrative example

    Suppose a mixed workload of code completion and Q&A measures out, on average per task, to 2,000 uncached input tokens, 600 output tokens, and 8,000 cache-hit tokens. Plugging in illustrative prices (20, 1, and 100 per million tokens for input, cache hits, and output respectively, in arbitrary cost units):

    1. C_in * P_in = 2000 * 20 / 1e6 = 0.04
    2. C_cache * P = 8000 * 1 / 1e6 = 0.008
    3. C_out * P_out = 600 * 100 / 1e6 = 0.06
    4. cost per task ≈ 0.108

    Two key facts stand out here. First, output accounts for only about 5% of total tokens yet consumes more than half the cost — controlling output length pays off more than compressing the input. Second, if the cache hit rate drops from 50% to 0, the cost per task rises to roughly 0.14, an increase of close to 30%, with not a single unit price changed. The quality of your cache design is the equivalent of an implicit price cut.

    3. Subscription Plans vs. Pay-as-You-Go: It All Comes Down to the “Leverage Ratio”

    Subscription plans are priced according to a logic entirely separate from API unit prices. What a plan effectively gives you is a quota lever: a fixed monthly fee in exchange for several to several dozen times the equivalent API usage. Define it as:

    1. leverage ratio R = equivalent API cost redeemable within the plan / monthly plan fee

    Public discussions have mentioned a few typical shapes: lower-tier plans have a leverage ratio roughly in the teens, while higher-tier plans can amplify it to dozens or even over a hundred times. Within the same vendor, the flagship model and the previous-generation model also differ in price by around 5x. These figures are illustrative values that only demonstrate the calculation method. They do not represent any vendor’s actual terms; the real numbers must be taken from the official pricing documentation in effect when you sign up.

    This leads to a counterintuitive but important judgment: the higher the plan tier, the larger the marginal leverage ratio tends to be, because the high fixed cost gets amortized over a much larger volume of usage. This explains why heavy users feel that “pay-as-you-go is absurdly expensive” — they are paying the tier with the lowest leverage ratio. Conversely, for teams whose usage fluctuates widely with sparse peaks, a high-leverage plan turns into pure sunk cost.

    To decide which one to choose, you only need to compare two numbers: whether your estimated monthly equivalent usage divided by the plan’s allowance reliably exceeds 1, and how large the variance in your business usage is. Reliably over-provisioned with low variance means choosing a high-leverage plan; sparse usage or pronounced peaks means pay-as-you-go is the better deal.

    4. Turn Cost into an Observable Metric

    Cost governance starts with instrumentation. At a minimum, collect the following fields and aggregate them by day:

    1. # Minimum viable field set for an LLM call log
    2. record = {
    3. "ts": "2026-08-31T10:00:00Z",
    4. "biz_line": "coding-assistant",
    5. "model_tier": "flagship", # flagship / standard / light
    6. "prompt_tokens": 12034, # total input
    7. "cached_tokens": 9800, # cache hits
    8. "completion_tokens": 742, # output
    9. "latency_ms": 2310,
    10. "success": True,
    11. "retry_count": 0,
    12. }

    That corresponds to a cost estimation table:

    1. def estimate_cost(records, price):
    2. """price: {"in": x, "cache": y, "out": z}, in cost units per 1M tokens"""
    3. unit = 1e-6
    4. cost = 0.0
    5. for r in records:
    6. cost += (r["prompt_tokens"] - r["cached_tokens"]) * price["in"] * unit
    7. cost += r["cached_tokens"] * price["cache"] * unit
    8. cost += r["completion_tokens"] * price["out"] * unit
    9. return cost
    10. def cost_per_success(records, price):
    11. succeeded = [r for r in records if r["success"]]
    12. if not succeeded:
    13. return float("inf")
    14. return estimate_cost(succeeded, price) / len(succeeded)

    Once you wire these metrics into monitoring and alerting, you can build a dashboard that links “token usage — success rate — cost per task.” On Baidu AI Cloud, this kind of governance typically comes down to a combination of general-purpose capabilities:

    • The model serving side offers multiple model tiers for tiered selection.
    • Call details and results are archived to object storage.
    • The logging service handles collection of usage details.
    • Monitoring and alerting handle thresholds and alerts for abnormal fluctuations.

    These are all industry-standard practices that do not depend on any proprietary interface.

    5. Four Cost-Reduction Levers You Can Put into Practice

    5.1 Cache-Friendly System Design (Usually the Biggest Payoff)

    The cache matches on token prefixes: change the prefix and everything after it is invalidated. So the most stable and longest content must go first, and dynamic content must come last:

    1. # Bad: dynamic content mixed into the system prompt, so the prefix changes
    2. # every time and the cache almost never hits
    3. bad = f"current time {now()}, user {uid}, profile {profile}\n" + LONG_STATIC_RULES
    4. # Good: stable prefix first, dynamic context appended at the tail
    5. prompt = LONG_STATIC_RULES + build_dynamic_context(uid, now()) + user_input

    System prompts, few-shot examples, coding standards, and the body of long documents are all candidates for the “stable prefix.” Simply reordering how you concatenate them can often lift the cache hit rate from single digits to over 80%, which is the equivalent of a deep discount on input costs.

    5.2 Output-Side Constraints

    As Section 2.3 shows, output is where most of the cost sits. Effective measures include:

    • Setting a reasonable max_tokens cap.
    • Requiring structured output to suppress redundant elaboration.
    • Splitting “explanatory prose” from “the result itself” into two tasks, with the former handled by a lightweight model.
    • Summarizing and compressing conversation history instead of carrying it in full.

    5.3 Model Tier Routing

    Use lightweight models for intent recognition, format validation, simple Q&A, and summarization. Reserve flagship models for complex reasoning and long chains of tool calls. A typical implementation runs one cheap classification call first, then decides where to route:

    1. def route(task):
    2. if task["estimated_difficulty"] == "low":
    3. return "light"
    4. if task["needs_reasoning"] and task["context_tokens"] > 32_000:
    5. return "flagship"
    6. return "standard"

    In practice, 60%–70% of requests can be handled by lightweight models, and the overall cost reduction is typically far larger than any price fluctuation in the flagship model.

    5.4 Call Behavior Governance

    This includes:

    • Suppressing wasteful retries: short-circuit requests that have definitively failed instead of retrying three times.
    • Concurrency and rate-limiting policies that keep peak traffic from spilling beyond your highest-leverage tier.
    • Periodic prompt regression testing on scenarios with low success rates.

    The retry rate is one of the biggest sources of hidden cost. Cutting it from 30% down to 5% is the equivalent of a 20% price cut.

    6. Selection Checklist

    When evaluating any model setup, answer these questions in order:

    1. Have you measured your per-task token distribution? The shares of uncached input, cache hits, and output determine how sensitive you are to unit prices.
    2. What is your cache hit rate, and is the prefix structure stable? This is the optimization point with the highest return on investment.
    3. What is your cost per successful task? Include retries and failed-attempt overhead, not the nominal unit price.
    4. Does the plan’s leverage ratio match your usage curve? Reliably over-provisioned means a high-leverage tier; sparse and volatile means pay-as-you-go.
    5. Have you implemented tiered routing? Flagship models should handle only the requests that genuinely need them.
    6. Are your cost metrics observable and alertable? No instrumentation means no governance.

    Ultimately, price increases and decreases in model unit prices are external variables. Token distribution, cache structure, routing policy, and retry rate are internal variables your team can fully control. Shifting your attention from “which vendor is cheaper” to “where is every cent of my spend actually going, token by token” is the right starting point for cost engineering.