LLM Token-Based Pricing Explained: Input vs. Output Costs, Prompt Caching, and Practical Cost Optimization
Most LLM APIs bill per token, charge far more for output than input, discount reused prompt prefixes through caching, and sell subscriptions that may or may not beat pay-as-you-go. This article explains how this pricing model works: what tokenization means for billing, why autoregressive decoding makes output more expensive, when prompt caching pays off, and how to compare subscriptions against metered usage. It also shows why agent and tool-calling workloads amplify costs, how to estimate them with a reusable Python function, and how to apply practical strategies such as prompt trimming, cache-friendly prompt design, model routing, context governance, and output limits. The goal is to help you build a cost model you can apply to any model service instead of relying on price tables that quickly go out of date.
Introduction: Why the same “conversation” can produce bills that differ several-fold
Many developers are confused the first time they see an LLM API bill: Why does one round of conversation charge a different price for input than for output? Why do costs drop sharply once caching is enabled? And why can a subscription plan that looks cheap turn out to have a higher effective per-unit cost once you use up the allowance?
Behind these questions is a model used by most LLM inference services: pay-per-token billing combined with multi-dimensional, differentiated pricing. Understanding this model does not mean memorizing any one vendor’s price list. Prices change frequently, and a price list is not a sound basis for long-term knowledge. What matters is understanding the pricing principles and cost model behind them. This article distills those general rules so you can quantify costs on any model service.
1. The Underlying Logic of Token-Based Billing
1.1 Tokens Are the Smallest Billing Unit
LLMs do not measure usage in “characters” or “sentences”; they use tokens as the smallest unit. After a piece of text is split by a tokenizer, Chinese, English, code, and punctuation marks are all converted into different numbers of tokens. This means:
- Billing correlates strongly with language and content complexity rather than with a simple character count.
- Input (the prompt you send) and output (the completion the model generates) are metered separately.
- Most services quote a per-million-token price, which makes side-by-side comparison easier.
Understanding tokenization is the first step in estimating costs. A rough rule of thumb: an English word is usually close to 1 token, a Chinese character often maps to 1–2 tokens, and code may run higher because it is dense with symbols. Exact values always depend on the target model’s tokenizer, so never apply a raw character count.
1.2 Why Output Is Generally More Expensive Than Input
This is the point new users most often overlook. In the vast majority of inference services, the per-token price for output is significantly higher than for input. The technical reason lies in the computational characteristics of autoregressive decoding:
- Prefill (the input stage): The entire prompt can be processed in parallel. A single forward pass produces the first token, so computation is fully parallelized and the unit cost is lower.
- Decode (the output stage): Tokens must be generated one at a time in sequence. Each new token depends on recomputing the entire preceding context and cannot be parallelized. As the context grows, KV cache overhead keeps accumulating.
This asymmetry — input can be parallel, output must be sequential — means the output stage inherently consumes more compute, so it is priced higher. When the output price is several times the input price, that is a normal consequence of this mechanism, not a simple “price hike”.
Cost per call ≈ input tokens × input price+ output tokens × output price- discount on the cache-hit portion
2. How Cache-Hit Pricing Works
2.1 The Principle of Prompt Caching
In real workloads, many requests share the same prefix. Examples include a fixed system prompt, a long document, codebase context, or tool definitions. Recomputing that prefix for every request wastes compute and drives up cost.
Prompt caching persists the computed results of this frequently reused prefix. When the next request matches the same prefix, it reuses the already-computed intermediate state and skips the repeated computation. As a result:
- Input tokens on a cache hit are priced well below the rate for a cache miss.
- Input tokens on a cache miss are still billed at the standard input price.
- Output generally does not get a cache discount, because the generated result is different every time.
2.2 Where Caching Delivers the Most Value
Savings from cache discounts scale with two factors: the length of the reusable prefix and how often it is reused. Typical high-value scenarios include:
- A long system prompt paired with many concurrent short requests, such as AI customer service or content moderation.
- Long context carried across multiple turns of a conversation.
- Coding assistants that repeatedly inject repository documentation, dependency information, or coding standards.
Conversely, if the prefix differs completely on every request or call volume is very low, the cache will rarely hit and there will be little or no discount. When assessing caching, always consider the hit rate alongside the discount percentage.
3. Subscription Plans vs. Pay-as-You-Go
3.1 Two Billing Paradigms
LLM services typically offer two billing models, each aimed at a different user profile:
- Pay-as-you-go: You pay for the tokens you actually consume, with no fixed monthly minimum. It suits workloads with volatile or hard-to-predict usage.
- Subscription: You pay a fixed monthly fee for an allowance (for example, a certain volume of tokens or a number of calls). Usage within the allowance is treated as prepaid.
3.2 The Trap When Converting Costs
Many people see a “low monthly fee + large allowance” and assume it is a good deal. But the real cost should be measured as the effective price per token. The correct approach is:
- Check whether the allowance covers input, output, or combined usage, and whether cache hits count toward it.
- Divide the monthly fee by the effective number of tokens you will actually consume to get the effective unit price.
- Compare that with the pay-as-you-go price, taking into account whether your usage is stable and whether it could exceed the allowance and trigger additional charges.
A common mistake is assuming the advertised allowance is the amount you will use. In practice, real workloads (especially task-based and agent workloads) often never reach the limit. The fixed cost is then spread over too few tokens, and the effective unit cost can end up higher than pay-as-you-go. Whether a plan is worth it therefore depends entirely on your actual usage pattern, and there is no blanket answer.
4. How to Estimate the Real Cost of Your Workloads
4.1 Task-Based and Agent Workloads Are Cost Amplifiers
The cost of a traditional “one question, one answer” call is easy to estimate. But the task-based workloads that dominate today — AI agents, tool/function calling, and long-document processing — multiply token consumption for three reasons:
- Multiple iterations: A complex task often requires the model to reason repeatedly, call tools, and keep going based on the results. Every round resends the full context.
- Context accumulation: As the conversation progresses, previous messages keep piling up, so the input token count grows with each subsequent round.
- Tool-definition overhead: The list of callable tools and their function descriptions also consume input tokens, and the cost rises with the number of tools.
For this reason, the cost of “completing one task” can differ several-fold depending on the workload. When planning a budget, use the task rather than the single API call as the unit of measurement.
4.2 Modeling Costs in Code
Rather than estimating by gut feeling, write a reusable cost function that makes the variables explicit:
def estimate_cost(input_tokens, output_tokens,input_price, output_price,cache_hit_ratio=0.0, cache_discount=0.9):"""Estimate the cost of a single call (prices are per 1M tokens):- cache_hit_ratio: share of input tokens served from cache (0-1)- cache_discount: discount on the cached portion (0-1; 0.1 means pay only 10%)"""# Uncached tokens are billed at the regular pricemiss_tokens = input_tokens * (1 - cache_hit_ratio)miss_cost = miss_tokens * input_price# Cached tokens get the discounthit_tokens = input_tokens * cache_hit_ratiohit_cost = hit_tokens * input_price * (1 - cache_discount)out_cost = output_tokens * output_pricetotal_per_million = miss_cost + hit_cost + out_costreturn total_per_million / 1_000_000# Example: a task with 8k input tokens, 2k output tokens, and 60% of input hitting the cachecost = estimate_cost(input_tokens=8000,output_tokens=2000,input_price=20, # Input price per 1M tokens (example)output_price=100, # Output price per 1M tokens (example)cache_hit_ratio=0.6,cache_discount=0.9)print(f"Estimated cost per task: {cost:.6f}")# Multiply by daily task volume and days per month to get a monthly budget range
The prices above are illustrative placeholders only. For real calculations, always use the latest official pricing for the model service you use. The value of this approach is that it breaks cost down into independent variables: input, output, cache hit rate, and task volume. Anyone can then quickly work out a cost range for their own workload instead of being misled by headline plan numbers.
5. Practical Cost Optimization Strategies
Once you understand how pricing works, you know where to focus your optimization efforts:
- Trim your prompts: Remove redundant descriptions and merge duplicate instructions to cut input tokens directly. The leaner your system prompt, the greater your long-term savings.
- Maximize cache reuse: Put stable content such as guidelines, documentation, and tool definitions first as a cacheable common prefix, and put content that changes often later, to increase the cache hit rate.
- Route across model tiers: Send simple tasks to lightweight small models and reserve large models for complex reasoning. Combining small and large models with routing can significantly lower the average cost per call.
- Govern context: Trim or summarize conversation history so context does not grow without limit. When needed, use retrieval-augmented generation (RAG) to retrieve only what is required rather than stuffing an entire corpus into the prompt.
- Control output: Since output tokens cost more, cap generation length (for example, with a sensible maximum token limit) and avoid lengthy, unhelpful responses.
- Make observability a priority: Use logging, monitoring, and alerting to track token usage, cache hit rates, and cost per task. Then let data, not guesswork, drive your optimization.
Conclusion: Build a Cost Model, Not a Memorized Price List
LLM pricing will keep changing with the market and with technical progress, and any specific number can quickly become outdated. The truly valuable skill is to understand the structure of token-based billing, why input and output are priced asymmetrically, how cache hits reduce costs, and how subscription and pay-as-you-go pricing compare under real workloads.
Once “input tokens × output tokens × cache hit rate × task frequency” becomes second nature, you can quickly calculate costs, choose the right billing model, and spend your budget on calls that create value, no matter which model service you use or how prices change. That is the key step from being able to afford LLMs to getting real value from them.
