LLM Token Pricing Explained: How Billing Works and How to Cut Costs
When developers adopt LLM capabilities, they tend to focus on model quality and overlook a factor that directly determines whether a project stays sustainable: the token billing mechanism. For the same request volume, the final bill can differ severalfold depending on the pricing model, the input size, and the caching strategy. Understanding how billing works underneath is a prerequisite for making sound technical choices and controlling long-term costs. This article starts from the underlying mechanics, explains the core components of token-based billing, and lays out a practical method for estimating and optimizing costs.
LLM Token Pricing Explained: How Billing Works and How to Cut Costs
When developers adopt LLM capabilities, they tend to focus on model quality and overlook a factor that directly determines whether a project stays sustainable: the token billing mechanism. For the same request volume, the final bill can differ severalfold depending on the pricing model, the input size, and the caching strategy. Understanding how billing works underneath is a prerequisite for making sound technical choices and controlling long-term costs. This article starts from the underlying mechanics, explains the core components of token-based billing, and lays out a practical method for estimating and optimizing costs.
How Token-Based Billing Works
Unlike traditional APIs that charge per call, LLMs are billed per token. A token is the smallest unit of text the model splits content into before running inference. Billing is usually broken into two independent parts:
- Input tokens (prompt): everything you send to the model, including system prompts, context, and conversation history.
- Output tokens (completion): the content the model generates.
The key detail is that input and output usually have different unit prices. Because output is generated autoregressively, one token at a time, the compute cost is higher, which is why most providers price output tokens noticeably above input tokens — commonly by a factor of 2 to 4. This means the cost structure differs sharply between “read a lot, write a little” workloads (long-document summarization, batch classification) and “read a little, write a lot” workloads (code generation, long-form writing).
Common Pricing Model Differences
On top of the base rates, providers layer different pricing strategies. Understanding them is the precondition for estimating costs accurately.
1. Tiered pricing (by input length)
Some providers set price tiers based on the input token volume of a single request: the longer the input, the higher the tier and the higher the unit price. A provider’s tiering might look like this (illustrative figures only):
Input length tier Input price (¥/M tokens) Output price (¥/M tokens)≤ 32K 2.5 1032K - 128K 4 16128K - 252K 7 28
The rationale behind this design is that long contexts put heavier pressure on GPU memory and compute. The direct consequence is that unit prices jump when a workload’s input approaches a tier boundary. In cost-sensitive scenarios, compressing input length and keeping context size under control can therefore deliver non-linear savings.
2. Flat unit pricing
Other providers use a single flat rate regardless of input length. Cost estimation becomes simpler under this model, and optimization shifts toward reducing total token consumption.
3. Context caching (prompt caching)
A major cost-reduction lever in recent years. When multiple requests share the same prefix content — a fixed system prompt, a lengthy reference document, few-shot examples — the caching mechanism lets you reuse the result of that repeated input and skip recomputing it. Costs usually fall into two categories:
- Cache write: writing content into the cache for the first time may be billed at the input rate, or carry a slight premium in some cases.
- Cache hit: subsequent requests that reuse cached content get a substantial discount, potentially a few percent of the original input price.
For high-frequency workloads with long, fixed prefixes and strong reuse (customer support Q&A over a fixed knowledge base, code assistants with a unified spec), a higher cache hit rate can reduce costs considerably.
A Reusable Cost Estimation Method
With so many pricing strategies in play, the easiest trap to fall into is estimating costs off the top of your head. The right approach is to write down an explicit billing formula and calculate each token category separately. Assume the following real workload data:
Input tokens = 509.8K (includes the portion reused from cache)Output tokens = 8.125KCache hit ratio = ~90%
Estimating for this typical summarization workload (“read a lot, write a little, with cache hits”): assume the input falls into the highest tier, at ¥7 per million tokens for input and ¥28 per million tokens for output, with cached portions getting a discount of more than 10%:
def estimate_cost(input_tokens, output_tokens,in_price_per_m, out_price_per_m,cache_hit_ratio=0.0, cache_discount=0.1):# Cache-hit tokens are billed at a discountcached = input_tokens * cache_hit_ratiouncached = input_tokens * (1 - cache_hit_ratio)input_cost = (uncached * in_price_per_m+ cached * in_price_per_m * cache_discount) / 1_000_000output_cost = output_tokens * out_price_per_m / 1_000_000return input_cost + output_cost# Illustration: without caching vs. with cachingno_cache = estimate_cost(509800, 8125, 7, 28, 0.0)with_cache = estimate_cost(509800, 8125, 7, 28, 0.9, 0.1)print(f"No cache: ¥{no_cache:.2f} With cache: ¥{with_cache:.2f}")
The value of this approach is that it makes every variable explicit: whether cache writes are billed separately, whether the input falls into a higher tier, and whether output is more expensive. Replace the sample prices with your provider’s actual rates and you get a realistic estimate of your bill, rather than being misled by a single deceptively low unit price.
Core Cost Optimization Strategies
Once you understand the billing logic, the optimization directions become clear. Here are a few general, high-leverage practices:
Compress input tokens: trim system prompts, remove redundant context, and use summaries in place of long source text. Under tiered pricing, pulling input back from a high tier to a lower one often cuts the unit price by a multiple.
Raise the cache hit rate: place static content (system prompts, reference documents, examples) at the front of the request so the reusable portion consistently hits the cache. Avoid inserting fields that change over time (such as timestamps) at the beginning, since that breaks prefix consistency and invalidates the cache.
Separate input-heavy from output-heavy tasks: for “read a lot, write a little” tasks, prioritize caching strategies; for “write a lot, read a little” tasks, question whether the output tokens are necessary and avoid overly verbose responses.
Build observable usage monitoring: use general-purpose logging, monitoring, and alerting capabilities to track input, output, and cached token consumption by business dimension and pinpoint cost hotspots. Data-driven optimization is optimization you can justify.
Route across model tiers: not every request needs the strongest model. Sending simple tasks to a lightweight model and reserving more capable models for complex ones balances quality against cost.
Summary
Token billing looks simple, but it is actually the product of multiple overlapping mechanisms: separate input/output pricing, tiering by input length, and context caching. What truly determines your bill is not the unit price itself, but how well your workload characteristics match these mechanisms. Instead of arguing over which provider is cheapest, it is better to master a reusable estimation method, plug your real usage into the formula, and keep optimizing through input compression, higher cache hit rates, and usage observability. Once you can precisely answer how much a request consumed, where the cost went, and how to spend less, model selection and cost control stop being guesswork and become an engineering problem you can calculate and optimize.
