LLM Cost Estimation: From Per-Token Pricing to Subscription Plan Evaluation

    Unit prices alone don’t tell the full cost of an LLM call. This article breaks down the billing components—input tokens, output tokens, and cached tokens—gives a formula for estimating per-task cost, explains how to evaluate subscription plans, lists common estimation mistakes, and offers practical steps for monitoring and optimizing model spend.

    Why Per-Token Price Is Not the Whole Story

    LLM services are usually billed by token. Input tokens refer to the prompt, context, and conversation history sent to the model. Output tokens refer to the response generated by the model. The two types often have different prices, and output tokens are usually more expensive because generating content requires token-by-token inference and more computation.

    Some services also offer cache-hit pricing. When multiple requests share the same prefix, the server can reuse intermediate results already computed for that prefix. The corresponding input cost is lower than uncached input. For applications with long system prompts or large documents, the cache hit rate directly affects total cost.

    For these reasons, comparing listed prices per million tokens does not reflect real spending. The same task can consume very different numbers of tokens across models. More reasoning steps and longer responses increase cost. Before evaluating cost, you need to understand how many tokens a task actually consumes, then multiply those tokens by the relevant prices.

    Three Cost Components

    A single API call can be broken into three cost components:

    1. Input cost: proportional to context length. Longer context means higher baseline cost per call.
    2. Output cost: related to response length and reasoning depth. Detailed analysis or long code can quickly increase output tokens.
    3. Cache cost: depends on prefix reuse. If fixed system prompts and knowledge-base fragments are reused consistently, cache-hit tokens grow and total cost drops.

    The weight of each component varies by use case. Question-answering applications are usually input-heavy. Code generation and long-form writing are usually output-heavy. Identifying which category your business falls into helps determine where optimization should focus.

    From Unit Price to Per-Task Cost

    A single task can be estimated as:

    1. per-task cost =
    2. uncached input tokens × input price
    3. + cache-hit tokens × cache price
    4. + output tokens × output price

    Here, uncached input tokens equal total input tokens minus cache-hit tokens. Prices are typically expressed per million tokens, so divide the final result by one million.

    The following code illustrates the calculation:

    1. def estimate_task_cost(
    2. input_tokens: int,
    3. cache_hit_tokens: int,
    4. output_tokens: int,
    5. price_in: float,
    6. price_cache: float,
    7. price_out: float,
    8. unit: int = 1_000_000,
    9. ) -> float:
    10. """
    11. Estimate the cost of a single task.
    12. Prices are per `unit` tokens. The return value uses the same
    13. currency unit as the input prices.
    14. """
    15. if cache_hit_tokens > input_tokens:
    16. raise ValueError("Cache-hit tokens cannot exceed total input tokens")
    17. miss_tokens = input_tokens - cache_hit_tokens
    18. cost = (
    19. miss_tokens * price_in
    20. + cache_hit_tokens * price_cache
    21. + output_tokens * price_out
    22. ) / unit
    23. return cost
    24. if __name__ == "__main__":
    25. # The prices below are hypothetical and do not represent any real service.
    26. cost = estimate_task_cost(
    27. input_tokens=200_000,
    28. cache_hit_tokens=150_000,
    29. output_tokens=20_000,
    30. price_in=10.0, # currency units / million tokens
    31. price_cache=1.0, # currency units / million tokens
    32. price_out=50.0, # currency units / million tokens
    33. )
    34. print(f"Estimated per-task cost: {cost:.2f}")

    With the example values above, the estimated per-task cost is 1.65 in the same currency units used for the prices. Output cost accounts for about 60% of that total, so output length is the most important variable to optimize under those assumptions. The 150,000 cache-hit tokens produce only about 0.15 in cost, which clearly shows the value of cache-friendly prompt design.

    Comparing Pay-As-You-Go and Subscription Plans

    The value of a subscription plan depends on how many tasks it can cover. A practical conversion process has three steps:

    1. Normalize units. Plan quota may be expressed as monetary credit, token count, request count, or time. Convert everything into the same unit first.
    2. Estimate available tasks. The approximate number of tasks covered by a plan is the plan quota divided by your estimated per-task cost.
    3. Check hidden constraints. Concurrency limits, rate limits, available model range, and quota expiration all affect real usable capacity. Even a large quota is not useful if batch workloads cannot finish under the concurrency limits.

    Usage ranges shown on marketing pages are usually based on an assumed average task size. Real workloads can vary widely: simple questions and complex reasoning tasks may consume several times more tokens. Treat those ranges as references, not commitments.

    The most reliable approach is to run a representative workload sample, record the input, cache-hit, and output token counts for every call, and replace the assumed values with the measured data.

    Common Mistakes in Cost Evaluation

    • Only looking at unit price, ignoring output length. If output pricing is high and the model generates long responses, a lower input price does not necessarily mean lower total cost.
    • Neglecting cache design. Mixing dynamic content with fixed content in the prompt can prevent cache reuse.
    • Using one test as the average. Estimate the distribution, and pay attention to median and high-percentile cases, because long-tail tasks often determine the budget ceiling.
    • Ignoring retries and tool calls. Failed retries and function-call round trips generate extra tokens and must be counted.
    • Treating benchmark scores as cost-effectiveness. A better metric is quality-adjusted cost, which is per-task cost divided by a quality score measured on the same task set.

    Practical Recommendations

    1. Collect representative samples. Select samples by task type, covering simple, routine, and complex scenarios, and record the token distribution for each call.
    2. Compare candidates on the same task set. Evaluate output quality and per-task cost together, rather than comparing only one dimension.
    3. Optimize prompt structure. Put stable system instructions and background material at the front of the prompt, and keep dynamic content at the end, to improve cache hit rate.
    4. Limit output length. Set a maximum output length based on business needs, and require the model to return content in a fixed format to reduce unnecessary text.
    5. Forecast monthly cost with buffer. Estimate monthly spend from historical usage and expected growth, and reserve room for traffic spikes and retries.
    6. Set up cost monitoring. Track daily token consumption and cost, and set threshold alerts. Investigate anomalies early, such as a prompt becoming unexpectedly long.

    Cost evaluation is an ongoing process. Model versions, pricing rules, and business scenarios all change. Re-estimate quarterly with fresh workload samples so the budget stays aligned with actual usage.