How LLM Token Pricing Works: Cost Structure and Billing Logic Explained
LLM services bill by token, but the "one price for input, another for output" model hides a cost structure built from GPU compute, inference efficiency, R&D amortization, and profit margins. This article breaks down how token pricing works: what a token actually is, how per-million-token prices are constructed, why output tokens cost more, how to estimate request costs with a working model, and practical optimization strategies for budgeting and architecture design.
Large language model services charge by token. On the surface, this looks simple—input tokens at one price, output tokens at another—but underneath sits a cost model shaped by compute costs, inference efficiency, R&D amortization, and commercial margins. Understanding this logic helps developers make better decisions in architecture design, budget planning, and cost optimization. This article covers the billing unit, pricing formulas, input/output price differences, estimation methods, and optimization practices.
1. Understand Tokens First: The Billing Unit Is Not the Character Count
A token is the basic unit of text processing for a model, produced by a tokenizer that splits text into word fragments, subwords, or symbols. Token counts vary with language, punctuation, code structure, and number formatting. The same business text can tokenize differently in Chinese, English, or mixed code contexts; long contexts, system prompts, tool call results, and conversation history all continue to consume tokens.
So the first step in token pricing is not looking at unit prices, but estimating how many tokens a business request translates into. A request typically consists of input tokens and output tokens: input includes system prompts, user queries, context, and retrieval results; output is what the model generates. Because they consume resources differently during inference, most commercial services price them separately. When budgeting, teams should track average input length, average output length, P95 tail lengths, and extra consumption from retries, cache misses, and repeated context.
2. Breaking Down the Pricing Formula: From GPU-Hour Cost to Per-Million-Token Price
The per-million-token price can be abstracted as:
Per-million-token price = GPU-hour cost × GPU hours consumed per million tokens + R&D amortization per million tokens + operations and compliance amortization per million tokens + target profit per million tokens
Here, GPU-hour cost covers not just GPU resources but also power, cooling, networking, storage, scheduling, and cluster utilization. GPU hours consumed per million tokens depend on model size, sequence length, batching efficiency, inference optimization, and cache hit rates. R&D amortization covers long-term investments in training, data governance, alignment, evaluation, tooling, and security compliance. Profit is the result of commercial pricing, adjusted for product positioning, competition, and economies of scale.
Note that cost-based pricing and market-based pricing are not the same thing. High-concurrency workloads with efficient batching and high cache hit rates can have lower per-token costs; long contexts, complex reasoning, and strict latency requirements push costs up. When discussing token prices, don’t rely on a single number—consider request structure, latency requirements, and resource utilization together.
3. Why Output Tokens Usually Cost More
In many commercial services, output prices run several times higher than input prices—commonly 2–5x, depending on the model and inference strategy. The reason isn’t simply that “generation is harder than understanding”; it comes down to how resources are used during inference.
Input processing is inherently parallel. The model performs a forward pass over the entire input, with dense matrix operations and high batching efficiency, making GPU utilization relatively easy to scale. Output generation is autoregressive and token-by-token: each token depends on all previous results, decoded step by step. Every step incurs memory bandwidth, cache management, and scheduling overhead; batching capacity is limited, and long outputs hold resources continuously. As context grows, state such as the KV cache adds further memory pressure. Output tokens therefore tend to correspond to higher per-unit resource consumption.
Low-latency requirements raise costs further. To shorten time-to-first-token and generation latency, providers must reserve capacity and optimize scheduling, sometimes sacrificing batching efficiency. Long outputs, complex reasoning, multi-turn conversations, and tool call chains all amplify output-side costs. Long input contexts also increase compute and memory overhead, but unit costs can usually still be reduced through batching and caching.
4. A Generic Pricing Example: Focus on the Structure, Not Specific Products
You can reason about the billing structure with variables. Suppose a model’s input price is a and output price is r×a, where r is the output-to-input price ratio. The cost of a single request is roughly:
Request cost ≈ (input tokens ÷ 1,000,000) × a + (output tokens ÷ 1,000,000) × r × a
For example, if a workload averages 2,000 input tokens and 500 output tokens per request with an output ratio of 3, the output portion—despite fewer tokens—may still account for a significant share of cost due to its higher unit price. If output length grows to 2,000 tokens, the cost structure changes noticeably. These ratios and token counts are illustrative only and do not represent any actual product’s prices.
Teams should build a “request profile”: average input, average output, tail lengths, retry rate, cache hit rate, concurrency peaks, and latency targets. Only by plugging these variables into a cost model can you assess how price changes truly affect your overall budget.
5. Cost Estimation Pseudocode and Budgeting Approach
The following pseudocode illustrates how to combine GPU-hour cost, R&D amortization, and a profit factor into an estimation model. Real parameters should come from cloud billing, load testing, and business monitoring—do not substitute fixed values.
function estimate_request_cost(tokens_in, tokens_out,gpu_hour_cost,in_gpu_hours_per_million,out_gpu_hours_per_million,rd_per_million_in,rd_per_million_out,margin_rate):in_unit = gpu_hour_cost * in_gpu_hours_per_million + rd_per_million_inout_unit = gpu_hour_cost * out_gpu_hours_per_million + rd_per_million_outsubtotal = tokens_in / 1000000 * in_unit+ tokens_out / 1000000 * out_unitreturn subtotal * (1 + margin_rate)
When calculating GPU-hour costs in a general cloud environment such as Baidu AI Cloud, base your figures on actual bills, resource utilization, and scheduling policies—nominal unit prices are not a substitute for real costs. For budgeting, segment by workload type: lightweight Q&A, long-document processing, code generation, and complex reasoning each have different token structures and latency requirements and should be estimated separately. For high-concurrency scenarios, prioritize batching, caching, tiered model routing, and output length control. For latency-sensitive scenarios, evaluate the trade-off between capacity reservation and unit cost.
6. Common Pitfalls and Optimization Directions
Common pitfalls include: looking only at input prices and ignoring output prices; relying on average lengths while ignoring P95 tails; overlooking repeated tokens from system prompts, conversation history, and retrieval results; ignoring extra consumption from retries, failure fallbacks, and tool call chains; and missing how cache hits reduce input costs. Optimization directions include: trimming prompts, capping output length, using structured output to reduce redundancy, caching high-frequency requests, routing tasks by difficulty to different model sizes, improving resource utilization with batching and streaming output, and building token-level cost monitoring.
In summary, token pricing can be described as GPU-hour costs plus inference efficiency differences, R&D and operations amortization, and commercial profit, resulting in a billing model with separate input and output prices. Output tokens are usually more expensive because token-by-token decoding suffers lower resource utilization and tighter latency constraints. Developers and teams that build a request profile, a cost model, and a monitoring loop can accurately assess API costs and balance performance, latency, and budget.
