Token Pricing Logic: How to Understand AI Compute Costs in One Minute

    This article breaks down how LLM token pricing actually works, from the hardware and software factors behind each inference request to the gap between input and output rates. You will learn the core cost formula, why output tokens cost more, six variables that drive real bills, a vendor-neutral cost estimation function, and a practical checklist for capacity planning and optimization.

    1. Why Token Pricing Can Be Explained in a Minute

    When teams evaluate the cost of an LLM application, the first instinct is usually to find a price sheet and multiply it by expected call volume. That works for a prototype, but once the application reaches production, the bill often diverges sharply from expectations. The reason is straightforward: a token is not a commodity priced per unit. It is a composite outcome of compute, GPU memory, bandwidth, and engineering amortization. Understanding pricing logic really means understanding what happens across the hardware and software stack during a single inference request.

    A token is the basic unit a model uses to process text, typically corresponding to a subword fragment. An English word may split into one or two tokens, while a Chinese character often maps to one or a few tokens. As a result, the same “word count” converts into different token counts depending on the language and the tokenization strategy. This is the first source of error in cost estimation.

    The second source is the asymmetry between input and output. The input stage (prefill) can be highly parallel, sending an entire prompt into the model at once. The output stage (decode) must generate autoregressively, token by token, and every step reads all model weights plus a growing context cache. The former is constrained by compute; the latter is constrained by GPU memory bandwidth. Differences in hardware characteristics directly explain why output is usually priced higher than input.

    2. The Basic Formula Behind Token Prices

    A conceptual formula captures the overall structure:

    1. Price per token ≈ (compute cost per unit × compute consumed per request + GPU memory and bandwidth overhead) / billable tokens
    2. + R&D and operations amortization / expected total call volume
    3. + reasonable profit

    The formula contains four key variables:

    1. Compute cost per unit: centered on the hourly rental or depreciation cost of accelerator cards, plus infrastructure overhead for the data center, power, networking, and storage.
    2. Compute consumed per request: determined by model parameter count, context length, concurrent batch size, and whether a cache is hit.
    3. R&D and operations amortization: upfront investment in training, evaluation, data governance, safety alignment, and inference engine optimization, spread across the expected total call volume over the lifecycle.
    4. Reasonable profit: covering risk and reinvestment to support ongoing model iteration.

    With this structure in mind, a common question becomes clear: why can prices across vendors and model tiers differ by one or two orders of magnitude? Because both the numerator (compute cost) and the denominator (call volume) change at the same time. A small-parameter model has low compute consumption per unit, and with large call volume its marginal cost is amortized quickly. A large-parameter model consumes more per unit, and if call volume is insufficient, the amortization portion significantly raises the unit price.

    3. Why Input and Output Differ by a Multiple

    The original observation that output is often two to five times the price of input has a clear engineering explanation.

    First, the computation patterns differ. Input processing is batched parallel matrix multiplication with high hardware utilization. Output decoding is serial, token by token, with low arithmetic intensity at each step while weights and the KV cache must be moved repeatedly, so the bottleneck falls on GPU memory bandwidth.

    Second, cache usage grows linearly over time. The longer the context and the longer the generation, the larger the cache and the higher the cost per step. For long-text generation, cost growth often outpaces the linear expectation based on token counts.

    Third, failure and retry costs are asymmetric. Once the output stage is interrupted, generated content usually cannot be reused and must be recomputed, whereas prefill results from the input stage can be cached and reused under some architectures.

    The practical design principle is therefore: move deterministic work to the input side and compress uncertain work on the output side. For example, complete long-document summarization, reranking of retrieval results, and structured extraction on the input side so the model only outputs a short conclusion. Constraining the output format, limiting maximum generation length, and using streaming responses to improve experience can all effectively reduce pressure on the output side.

    4. Six Variables That Affect the Real Bill

    • Context length: watch for cache reuse potential. In multi-turn conversations, placing the system prompt and stable history in the prefix noticeably increases the prefix cache hit rate.
    • Batching and concurrency: improving batch efficiency raises throughput per unit, but may introduce queuing latency, so you must trade off cost against experience.
    • Model tier selection: not every task needs the largest parameter model. Classification, extraction, and format conversion tasks can usually be handled by a small model, reserving the large model for complex reasoning.
    • Retry and fallback strategy: uncontrolled retries are a common cause of bill inflation, so set limits on retry counts and a timeout budget.
    • Output length constraints: an explicit maximum generation length and structured output constraints are the key switches for cost controllability.
    • Cache and intermediate result reuse: write reusable intermediate artifacts to object storage or a cache service to avoid recomputation.

    5. An Illustrative Cost Estimation Implementation

    The following vendor-neutral estimation logic makes it easy to translate the variables above into code:

    1. def estimate_cost(input_tokens, output_tokens,
    2. price_in_per_m, price_out_per_m,
    3. cache_hit_ratio=0.0, retry_factor=1.0):
    4. billable_in = input_tokens * (1 - cache_hit_ratio)
    5. cost = (billable_in * price_in_per_m
    6. + output_tokens * price_out_per_m) / 1_000_000
    7. return cost * retry_factor
    8. # Example: long prompt + short output, assuming a 50% prefix cache hit rate
    9. print(estimate_cost(8000, 300, 0.5, 1.5, cache_hit_ratio=0.5))

    The value of this code is not precision but making the two most easily overlooked variables, cache hit ratio and retry factor, explicit in the model. In production, log token usage, hit status, and latency for every call, then build a cost dashboard with monitoring and alerts to form a loop of continuous optimization.

    6. Capacity Planning and Optimization Checklist

    During budgeting, estimate resource needs as peak concurrency × average context × average output length, and reserve some headroom for traffic spikes. For optimization, follow this order:

    1. First cut ineffective calls: merge duplicate requests and filter out low-value tasks.
    2. Then optimize prompt structure: place stable prefixes first to improve cache hits.
    3. Next apply model tiering: small models handle high-frequency simple tasks, large models handle low-frequency complex tasks.
    4. Finally adjust the deployment shape: scale elastically on a container platform and use queues to smooth peaks and fill troughs.

    7. Conclusion

    Token pricing is not mysterious. It simply re-expresses compute cost, engineering amortization, and business return in a measurable unit. Mastering three main threads, cost structure, input-output asymmetry, and caching and retries, enables more robust decisions across model selection, architecture, and budgeting. In Baidu AI Cloud and general industry practice, incorporating cost observability into the daily engineering workflow often delivers more practical value than reconciling the bill after the fact.