LLM API Token Billing: How Developers Can Calculate and Control Costs
This article explains how token-based LLM API pricing works, covering input vs. output rates, peak/off-peak pricing, prompt-cache discounts, and model-tier gaps. It outlines practical engineering tactics—prompt compression, output limits, cache-friendly prefixes, off-peak batching, and model routing—so teams can keep quality while making usage economically viable.
LLM API Token Billing: How Developers Can Calculate and Control Costs
1. From “free chat” to usage-based pricing
Consumer chat products often look free or subscription-based, so users rarely see the compute behind each reply. For developers, every API call is metered and billed.
The unit is the token. Text is split into tokens; what the model reads is input (prompt) tokens, and what it generates is output tokens. For Chinese (and other languages), token count tracks character or word count only roughly; the exact mapping depends on each model’s tokenizer.
The economics are straightforward: inference is compute-heavy—GPUs, memory, and bandwidth are real costs. Charging by usage is currently the fairest, most sustainable model.
2. Three dimensions that split the price list
Public LLM price sheets are not a single number. They typically vary along three axes.
2.1 Separate prices for input and output
This is easy to miss. Input and output tokens are priced separately, and output is usually several times more expensive. One public example: peak rates of about 2 RMB per million input tokens vs. 8 RMB per million output tokens—a 4× gap.
Generation is autoregressive: each new token requires a full forward pass and cannot be amortized with the same parallelism as prefilling the prompt. Long-output apps (articles, code generation) therefore feel cost pressure first.
2.2 Peak vs. off-peak windows
Some providers float rates by time of day: higher at peak, lower off-peak, sometimes by several times. That reflects demand on the inference fleet—busy by day, idle at night—and uses price to shift load.
Latency-tolerant batch work (offline labeling, log summarization, bulk moderation) is cheapest if you schedule it in off-peak windows.
2.3 Large discounts from cache reuse
If a request shares a prefix with earlier requests (same system prompt, fixed document context), the provider can reuse prior compute. Cached input may be billed at a few percent of the normal rate—for example 2 RMB per million normally vs. 0.04 RMB on a cache hit (~50× cheaper).
Architecture implication: keep stable content at the front of the prompt and variable content at the end so cache hits stay high.
3. Price gaps across model tiers
Across capability tiers, the spread is larger still. Generating a million tokens on a flagship model can cost tens or hundreds of times more than on a lightweight model.
Not every task needs the strongest model. A common pattern is tiered routing:
def route_model(task):if task.type in ["format conversion", "simple classification", "keyword extraction"]:return "lightweight model" # low unit cost, fastelif task.type in ["code generation", "complex reasoning", "long-form writing"]:return "flagship model" # quality firstelse:return "mid-tier model"
In practice, routing high-volume, easy requests to cheap models can cut the bill by about an order of magnitude versus always using the flagship model, with little quality loss.
4. A developer cost checklist
- Compress prompts. Input tokens are billed; long context, duplicate examples, and unused instructions waste money. Audit prompts and drop low-value text.
- Cap output length. Output is more expensive. Constrain length in instructions, or outline first then generate in sections, to avoid one huge redundant dump.
- Maximize cache hits. Pin system prompts, domain knowledge, and few-shot examples in the prefix; put dynamic content last.
- Shift batch jobs off-peak when real-time latency is not required.
- Route by difficulty so you do not use a flagship model for trivial tasks.
- Observe cost at the gateway. Log input/output tokens, cache hits, and time-of-day; break cost down by product so optimizations are measurable.
5. The teams that win are the ones who can close the books
When chat looks free but APIs are itemized, the winners are not only model vendors—they are teams that treat token economics as an engineering constraint.
Input/output spreads, time-of-day rates, cache discounts, and model tiers should show up in architecture, not only in finance reviews. Cost control is not a minor saving trick; it is what determines whether an AI product can scale and whether the business actually works.
