# LLM API Pricing Explained: How Token Billing Works and How to Cut Costs
This article breaks down how LLM API pricing actually works: the three billing dimensions most providers use (input, output, and cache-hit tokens), why comparing per-token unit prices leads to wrong conclusions, and why cost per completed task is the metric that matters. It also covers when subscription plans beat pay-as-you-go, and shares practical engineering techniques — prompt trimming, cache-friendly request design, output length control, context pruning, and tiered model routing — for reducing API spend while preserving quality.
Why the “Unit Price” Is Misleading
When comparing the value of LLM APIs, the most common mistake is looking at a single number: dollars per million tokens. In practice, mainstream providers break billing into three dimensions: input tokens (prompt), output tokens (completion), and cache-hit tokens. These three prices can differ enormously, and the price ladder varies from model to model.
Fixating on one number leads to skewed conclusions. A model that looks cheap may balloon in cost on long-context workloads if the input side gets no cache discount, while a pricier model can turn out more economical in applications with a high cache hit rate. What actually determines cost is how your workload’s characteristics map onto these three billing items. So the rational starting point is to understand the pricing logic behind each of them.
The Essential Differences Between the Three Billing Categories
Input billing (prompt / input)
Input tokens correspond to the context the model must read before inference: the system prompt, conversation history, the user’s current question, and any retrieved content injected into the request. This is a sequence the model has to process in full, so its rate is typically on the same order as output, or slightly lower.
Input volume is often underestimated. In RAG pipelines, long-document summarization, and multi-turn agents, input tokens can be several times — sometimes tens of times — larger than output tokens. A short-looking user question may sit on top of thousands of tokens of reference material, and that overhead is the main source of input cost.
Output billing (completion / output)
Output tokens are what the model actually generates, and their unit price is usually significantly higher than input. The reason lies in inference mechanics: generation is autoregressive, and every new token requires recomputing the attention distribution over the full sequence so far, so compute accumulates as the sequence grows. That is why output rates are often several times the input rate.
This difference has direct implications for application design. If your scenario produces long outputs — long-form generation, code completion, structured data extraction — the weight of the output rate is amplified, and controlling output length and constraining the output format is usually more effective than optimizing input.
Cache-hit billing
Cache hits are an increasingly important part of modern pricing. The principle: when multiple requests share the same prefix (a fixed system prompt, the same batch of reference documents), the model can reuse the intermediate state computed earlier (the KV cache) instead of recomputing that portion of the input for every request. Tokens served from cache typically receive a discount well below the standard input rate.
The core precondition is a stable prefix. As long as the beginning of the request is byte-for-byte identical, the earlier portion can still hit the cache even if only a small amount of new content is appended afterward. This is extremely valuable for batch jobs built around a fixed template.
From Unit Price to Cost per Task
Once you understand the three billing categories, it becomes clear why the claim that one model is “more expensive” is often not rigorous. The right yardstick for value is not token unit price but the total cost of completing one real task.
The same business task consumes resources in completely different ways across models:
- Model A has low input and output rates but no cache optimization, so it recomputes the entire long context on every request.
- Model B has higher input and output rates but a very high cache hit rate and needs fewer total tokens per task.
In this situation, even though A’s per-token prices are lower, B’s cost per task may be lower. Any meaningful evaluation must plug in your real token distribution: average input length, average output length, the share of reusable prefix, request concurrency and frequency.
A practical approach is to build your own “task cost probe”: sample a batch of representative real requests, run them across different models and billing modes, record the total token breakdown and total spend, and compute the average cost per task. This is much closer to real expenditure than any static unit-price comparison.
# Illustration: estimate cost per task from real request samplesdef estimate_task_cost(sample_requests, pricing):"""pricing: {"input": price per 1k, "output": price per 1k,"cache_hit": discounted price per 1k}Each request contains the fields input_tokens / output_tokens / cached_tokens"""total = 0.0for req in sample_requests:cached = req.get("cached_tokens", 0)plain_input = req["input_tokens"] - cached # the uncached portion is billed as regular inputcost = (plain_input / 1000 * pricing["input"]+ cached / 1000 * pricing["cache_hit"]+ req["output_tokens"] / 1000 * pricing["output"])total += costreturn total / len(sample_requests) # average cost per task
The value of this model is that it turns “unit price” back into “business cost,” putting different billing schemes on the same footing for comparison.
Pay-As-You-Go vs. Subscription Plans
Beyond token rates, another layer that affects real cost is the billing model itself. The industry generally offers two options: pay-as-you-go and subscriptions.
Subscription plans commonly take the form of “a fixed monthly fee plus a usage allowance”: after paying the flat fee you receive a pool of usage to consume, and once it is exhausted you may be charged a higher rate or moved to a degraded tier. The key metric here is not the unit price but the conversion ratio between the plan price and the allowance it grants, along with whether that allowance covers your real monthly consumption.
Deciding whether a subscription is worthwhile comes down to three questions:
- What is your average real monthly consumption? Run the task cost probe described above for a month to get the total token breakdown, then convert that into an allowance requirement.
- Does the allowance match your consumption? If it is far larger than your needs, you are paying for idle capacity; if it is far smaller, the overage ends up raising your overall cost.
- What are the overage and rollover rules? Whether the allowance accumulates across months, what the overage rate is, and whether elastic scaling is supported — these details often determine long-term cost more than the headline price does.
A sensible strategy: teams with stable, predictable load can use a subscription to lock in the price differential; projects with volatile load or still in the trial-and-error stage should start with pay-as-you-go to observe the real consumption distribution before deciding whether to migrate to a plan. Avoid prepaying for a long-term plan based on headline pricing alone when you have no real consumption data.
Practical Cost Optimization Techniques
Whichever billing model you choose, the following engineering measures cut spend materially:
1. Trim and structure your prompts
A verbose system prompt is billed as input tokens on every single request. Compressing prompts down to the necessary information and removing redundant phrasing accumulates meaningful savings under high concurrency.
2. Maximize cache hits
Put stable, unchanging content (system instructions, fixed templates, reference material) at the very front of the request and variable user input at the end. Keeping the prefix byte-for-byte identical is the key to a high cache hit rate.
# Stable prefix first, dynamic content last, to improve cache hit ratestable_prefix = "[Fixed system instructions and reference material, kept completely identical]"def build_prompt(user_input):return stable_prefix + user_input # prefix stays unchanged; only the tail is appended
3. Control output length
Since output tokens cost more, use explicit constraints — specifying fields, limiting length, requiring structured output — to prevent the model from generating redundant content.
4. Context management and pruning
In multi-turn conversations, summarize or apply a sliding window to message history so the full history is not repeatedly billed as input. Filter retrieval results by relevance and inject only the necessary snippets.
5. Tiered routing by task complexity
Send simple tasks to smaller, lower-priced models and reserve high-capability models for complex tasks. Classifying requests by difficulty lowers average cost without sacrificing quality.
Summary
Evaluating LLM API cost cannot stop at surface-level comparisons of “price per token.” What really drives spend is the interaction of the three billing categories — input, output, and cache hits — and how your workload maps onto them. Use cost per task as your yardstick, assess pay-as-you-go against subscriptions using your real token consumption distribution, then keep optimizing through engineering measures such as prompt trimming, cache reuse, context management, and tiered model routing. Only then can you find the balance between capability, quality, and cost that genuinely fits your business. Pricing is just the surface; understanding the billing mechanics and letting data do the talking is the real path to controlling LLM API spend.
