How to Estimate LLM Costs: From Token Pricing to Total Subscription Costs

    Most LLM services bill per million tokens, with separate rates for input and output, so comparing unit prices alone often leads to wrong conclusions. This article explains the billing units (input tokens, output tokens, cached tokens), the differences between pay-as-you-go and subscription plans, and provides a reusable Python cost model with sensitivity analysis. It also covers evaluation dimensions for model selection, common pitfalls in cost estimation, and practical steps for building an ongoing cost management practice.

    1. Why Comparing Unit Prices Alone Is Misleading

    LLM services are typically billed per million tokens, with input and output priced separately. Some services also offer lower rates for cached input tokens. Looking at any single unit price in isolation can lead to one-sided conclusions. A model with a low input price may charge much more for output, so if your workload is dominated by long-form generation, total cost may not actually be lower. Conversely, a model with a higher unit price may complete the same task using fewer tokens, making it cheaper in practice.

    Therefore, what you should compare when selecting a model is the total cost of completing a business task. That total includes the cost of input, output, caching, retries, and failed requests, as well as the engineering effort required for development and migration.

    2. Understanding the Basic Billing Units

    2.1 Input Tokens

    Input tokens include the system prompt, conversation history, retrieved document chunks, and the user’s current question. In many applications, input volume far exceeds output volume. In retrieval-augmented generation (RAG) scenarios, for example, each request may carry thousands of tokens of context, making input the dominant cost driver.

    2.2 Output Tokens

    Output tokens are the content the model generates. Consumption scales directly with output length, and most services price output higher than input. Where the business allows, constraining the response format and capping the maximum generation length can effectively control this portion of spending.

    2.3 Cache Hits

    When multiple requests share the same prefix—such as a fixed system prompt or the same long document—the server may reuse previously computed intermediate results and bill that portion of the input at a lower rate. The cache hit rate depends on how stable the request structure is. A common practice is to place fixed content at the front of the prompt and variable content at the end, which makes it easier to form reusable prefixes.

    3. Pay-as-You-Go vs. Subscription Plans

    With pay-as-you-go pricing, cost scales linearly with usage: the more you use, the more you pay. A subscription fixes the cost instead. Within the included quota, the marginal cost of each call is close to zero. Once the quota is exceeded, services typically switch to rate limiting, downgrade service quality, or charge extra.

    To determine whether a subscription is worthwhile, answer three questions in order:

    • What is the effective monthly usage—that is, real call volume after excluding tests and invalid requests?
    • Can the quota ceiling cover business peaks, not just averages?
    • What is the unit cost beyond the quota, and what share of total usage does that overage represent?

    Different services compute quotas differently—for example, by number of requests, token count, or time windows. Specific terms should be verified against the provider’s published rules. Without real usage data, any conclusion about whether a subscription is cheaper or more expensive lacks a basis.

    4. Building a Reusable Cost Model

    The core of a cost model is converting business metrics into expenses. The code below provides a generic monthly cost estimation function. All prices are example values, not actual quotes from any service—replace them with the target provider’s published prices when using it.

    1. def monthly_cost(
    2. requests_per_day: int,
    3. input_tokens: int,
    4. output_tokens: int,
    5. cache_hit_ratio: float,
    6. price_input: float, # price per million input tokens (example value, in CNY)
    7. price_cache: float, # price per million cached input tokens (example value, in CNY)
    8. price_output: float, # price per million output tokens (example value, in CNY)
    9. days: int = 30,
    10. ) -> float:
    11. """Estimate monthly API call cost, in CNY."""
    12. if not 0 <= cache_hit_ratio <= 1:
    13. raise ValueError("cache_hit_ratio must be between 0 and 1")
    14. total_requests = requests_per_day * days
    15. cached_tokens = input_tokens * cache_hit_ratio
    16. uncached_tokens = input_tokens - cached_tokens
    17. input_cost = (
    18. uncached_tokens * price_input + cached_tokens * price_cache
    19. ) * total_requests / 1_000_000
    20. output_cost = output_tokens * price_output * total_requests / 1_000_000
    21. return input_cost + output_cost

    Suppose a business makes 2,000 requests per day, with about 3,000 input tokens and 800 output tokens per request, a 60% cache hit rate, and example prices of 10 CNY per million input tokens, 1 CNY per million cached tokens, and 40 CNY per million output tokens. Plugging these into the function yields a monthly cost of roughly 2,748 CNY, of which output accounts for about 1,920 CNY and input about 828 CNY.

    1. base = monthly_cost(2000, 3000, 800, 0.6, 10.0, 1.0, 40.0)
    2. low_cache = monthly_cost(2000, 3000, 800, 0.2, 10.0, 1.0, 40.0)
    3. print(f"Cache hit ratio 60%: {base:.0f} CNY")
    4. print(f"Cache hit ratio 20%: {low_cache:.0f} CNY")

    The results show that when the cache hit rate drops from 60% to 20%, the monthly cost increases by roughly 648 CNY. This demonstrates that in input-heavy scenarios, optimizing the cache structure may deliver more direct savings than switching to a model with a lower unit price.

    5. Sensitivity Analysis: Finding the Variables That Really Matter

    Once the model is built, adjust each key variable in turn and observe how much the total cost changes. Common variables include:

    1. Cache hit rate, which depends on prompt structure stability;
    2. Output length, which depends on response format constraints and generation length caps;
    3. Number of calls per task—for example, multi-step reasoning or tool calling multiplies the request count;
    4. Retry rate, since failed requests are also billed;
    5. Context length, which depends on the conversation truncation strategy and the number of retrieved chunks.

    If a variable significantly changes the total cost within its reasonable range, it should be the priority optimization target. Conversely, variables with limited cost impact do not deserve much engineering effort.

    6. Evaluation Dimensions for Model Selection

    Beyond cost, model selection should also consider quality, stability, and migration difficulty. The table below lists common evaluation dimensions.

    Dimension Key Question How to Evaluate
    Cost per task What is the total spend to complete one business task? Use real logs to count input, output, and call volume
    Task success rate Is the first generation usable? Build a test set and measure the pass rate
    Cache friendliness Is the prompt structure stable? Observe prefix reuse and hit rates
    Quota and rate limits Can peak traffic be handled? Stress-test against peaks, not averages
    Latency Does response time meet experience requirements? Measure time to first token and total duration
    Migration cost How much code must change to switch providers? Assess API abstraction and adaptation effort

    Success rate and cost must be evaluated together. A solution with a low first-pass success rate will see its actual spending pushed up by retries, even if its unit price is cheap.

    7. Common Pitfalls

    Pitfall 1: Extrapolating long-term costs from small tests. Small-sample tests cannot reflect long-tail inputs or peak traffic. Model costs on at least several weeks of real logs.

    Pitfall 2: Ignoring the cost of failed requests. Timeouts, malformed outputs, and requests that need regeneration are all billed. Include them in the total.

    Pitfall 3: Looking only at the nominal unit price. Nominal prices do not capture the effects of caching, context length, or output length. Two plans with identical unit prices can differ several-fold in actual spending.

    Pitfall 4: Treating a subscription quota as unlimited. The value of a subscription depends on whether usage stays within the quota. The unit cost of overage can be far higher than the standard price and must be calculated separately.

    8. Practical Recommendations

    1. Extract a representative sample of real request logs, analyze the distribution of input and output tokens, and flag peak business hours.
    2. Use the model from Section 4 to estimate monthly costs, then run a sensitivity analysis to identify two or three key variables.
    3. Optimize prompt structure and output constraints first—these changes are cheap to make and deliver fast results.
    4. Validate in phases: start with a small canary rollout, then scale up gradually while monitoring both cost and quality metrics.
    5. Set up budget alerts and a monthly review process, and investigate promptly whenever actual costs deviate from the model’s predictions.

    Cost estimation is an ongoing effort. As the business evolves, prompts are iterated, and provider rules change, the model needs regular updates. Treating cost as a measurable, optimizable engineering metric is what enables reliable decisions in technology selection and resource allocation.