A Complete Guide to LLM Token Pricing Logic

    This article breaks down how LLM token pricing works, from the underlying formula based on compute cost, R&D amortization, and margin to the three key variables that drive token consumption: model size, input-to-output ratio, and inference overhead. It also explains why providers charge per token rather than per unit of compute, and shares practical strategies such as tiered routing, context compression, output limits, caching, and observability to help you control AI application costs.

    1. Why “Token Pricing in One Minute” Deserves a Closer Look

    When building LLM applications, cost is often the most underestimated factor. Many teams focus only on output quality during the prototype stage, only to find the bill far exceeds expectations once traffic grows. To understand that bill, you need to understand the underlying logic of token pricing: the price is not an arbitrary number, but a result derived from compute cost, R&D amortization, and a reasonable profit margin.

    A quick note on terminology: a token is the basic unit an LLM uses to process text. Any Chinese text, English text, or code is split into a number of tokens before being fed into the model. Billing is based on tokens because they are the smallest unit that users can perceive, count, and accumulate.

    2. What Makes Up a Token’s Price: A Reusable Pricing Formula

    The unit price can be described with the following general formula:

    1. Token unit price = (compute cost per unit time × compute consumed) ÷ total tokens produced
    2. + R&D and operations allocation + reasonable profit

    Breaking it down:

    1. Compute cost: rental or depreciation of accelerator hardware such as GPUs, data center facilities and power, and network overhead. This is the main variable cost.
    2. R&D allocation: upfront investment in model training, data governance, evaluation and alignment, and inference optimization, amortized over the expected call volume.
    3. Operations and profit: capabilities such as monitoring and alerting, logging services, and elastic scaling, plus the reasonable return needed to sustain the business.

    A common pattern across the industry is that the output price is typically 2 to 5 times the input price. The reason is that during the input stage the model mainly performs parallel encoding, while during the output stage it must generate autoregressively token by token. Each step repeatedly reads the weights and the context cache, so compute utilization is significantly lower.

    3. Three Key Variables in Compute Consumption

    3.1 Model Size

    The number of parameters directly determines the scale of a single forward pass. The industry commonly uses a tiered view — small models (around 7B), medium models (around 70B), and large models (hundreds of billions of parameters or more) — to reason about this: each step up in scale can increase compute consumption by an order of magnitude. Using a large model for a simple task is therefore one of the main sources of wasted cost.

    3.2 Token Length and Input-to-Output Ratio

    In real applications, the ratio of input to output varies widely:

    Scenario Input Tokens Output Tokens Approximate Ratio
    Simple Q&A 100 200 1:2
    Long-form generation 500 4000 1:8
    Code generation 300 1500 1:5

    Key takeaway: output tokens usually account for 75% to 90% of total cost, making them the first priority for optimization.

    3.3 Training vs. Inference

    Training is a one-time, large investment that typically does not appear on a per-call bill. Inference is the real-time cost incurred on every call, and it is the source of token-based billing. This also explains why a model with comparable quality but cheaper inference holds a cost advantage.

    4. Why Charge per Token Instead of per Unit of Compute

    Dimension Billing by Compute Billing by Token
    Ease of understanding for users High; requires concepts like TFLOPS Low; roughly “pay by word count”
    Pricing transparency Low High
    Cost predictability Hard Easy
    Communication and marketing Poor Good

    There are three core reasons. First, it is user-friendly: a token is a unit users can directly perceive. Second, it is easy to calculate: token count multiplied by unit price gives the total. Third, it is easier to communicate: “one dollar generates thousands of articles” is far more intuitive than a pile of compute metrics.

    5. Practical Advice: Get Your Costs Under Control

    1. Tiered routing: send simple requests to small models and escalate to larger ones only for complex reasoning, avoiding a one-size-fits-all approach that puts everything on a large model.
    2. Compress context: trim prompts, deduplicate history, and summarize when necessary to directly reduce input tokens.
    3. Control output length: set a reasonable maximum output limit. Saving one token on the output side is roughly equivalent to saving two to five tokens on the input side.
    4. Cache and reuse: cache results for high-frequency identical requests to avoid repeated inference.
    5. Observability: use monitoring, alerting, and logging services to aggregate token consumption by business dimension and build a cost dashboard.

    In common practice on cloud platforms such as Baidu AI Cloud, model services are typically billed by token and come with general-purpose capabilities such as monitoring, logging, and elastic compute, helping teams get the “unit price × usage” math right. With the formula and variables above in hand, you can make more rational decisions during model selection, budgeting, and architecture design.