LLM Pricing Increases: How to Calculate Your Actual Usage Costs

    A higher price per token does not necessarily mean a higher cost per task. Learn how to account for input, output, cached tokens, retries, and success rates, compare subscriptions with pay-as-you-go pricing, and calculate task-level costs with Python.

    1. Why Token Prices Do Not Tell the Whole Story

    Model services typically charge by the token, with rates quoted per million tokens. When those rates rise, it is easy to assume that using the model will become more expensive. But the token rate is only one part of the calculation.

    Actual spending depends on the tokens consumed per task, the applicable rates, and the total number of tasks. If a higher-priced model uses fewer tokens per task, or most input tokens qualify for cached pricing, spending may not rise proportionally—and may not rise at all.

    The reverse is also true: unchanged rates do not guarantee stable costs. Longer contexts, multiple tool calls, and retries after failures can substantially increase token consumption.

    The useful comparison is therefore cost per task, not just price per token, and it should be based on measured usage.

    2. Understand the Three Billing Components

    2.1 Input Tokens

    Input includes system prompts, conversation history, retrieved document passages, and tool results. Longer contexts mean more input tokens.

    In many applications, input volume far exceeds output volume, so input pricing can have a larger effect on the total bill.

    2.2 Output Tokens

    Output tokens are the content generated by the model. In most pricing structures, output tokens cost more than input tokens.

    Some models also generate intermediate reasoning tokens. These are often billed as output tokens, so they need to be accounted for separately when estimating usage.

    2.3 Cached Input Tokens

    A cache hit occurs when a request prefix matches content from a recent request, allowing the service to reuse previously computed intermediate results and charge a lower rate.

    Effective caching generally depends on two conditions:

    1. A stable prefix. Place system prompts and fixed documents at the beginning of the request.
    2. Requests within the cache lifetime. The interval between requests must fall within the service’s cache retention window.

    Consult the provider’s official documentation for the exact retention period and billing rules.

    A useful request structure is:

    1. [Fixed system prompt] [Fixed reference documents] [Conversation summary] [Current user question]
    2. |------------- Stable, cacheable prefix --------| |---------- Variable content -----------|

    Placing unchanged content first and variable content last can improve the cache hit rate.

    3. Compare Subscriptions and Pay-as-You-Go Pricing on the Same Basis

    Subscriptions and pay-as-you-go services use different pricing units. A subscription may describe an allowance as a range of tasks, while pay-as-you-go pricing lists rates per million tokens. Their advertised prices are not directly comparable.

    To compare them:

    1. Select a representative task set covering your main day-to-day use cases.
    2. Run those tasks on the target model and record input, output, and cached input tokens for each task.
    3. Calculate each task’s cost under pay-as-you-go pricing.
    4. Divide the subscription price by the number of tasks you can complete within its allowance.
    5. Compare the resulting costs per task in the same table.

    Actual subscription allowance consumption can vary with task type, retry count, and concurrency. The upper and lower ends of an advertised usage range may differ by several times. Use measured results rather than the advertised range alone.

    4. Compare Models at the Task Level

    Even when token rates are identical, models can consume very different numbers of tokens to complete the same task. Key factors include:

    • Output verbosity: Whether responses contain unnecessary explanations or excessive detail.
    • Reasoning depth: Complex tasks can require more intermediate steps, increasing output token usage.
    • Tool calls: Each call can introduce additional input and output.
    • Retries: Formatting errors or inadequate results can trigger repeated requests.
    • Context length: Conversation history may be counted again in each subsequent turn.

    Comparing token prices alone misses these task-level differences. Evaluate models against a fixed task set and track success rate, average token consumption, and average cost.

    A model with cheaper tokens can still cost more per successful task if its success rate is lower:

    1. Cost per successful task = Total cost / Number of successful tasks

    5. Example: Calculate Task Costs with Python

    The following code converts recorded token usage into task costs. The pricing parameters are placeholders; replace them with the rates in the provider’s official documentation.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class Pricing:
    4. input_per_m: float # Price per million uncached input tokens
    5. output_per_m: float # Price per million output tokens
    6. cached_per_m: float # Price per million cached input tokens
    7. @dataclass
    8. class TaskUsage:
    9. input_tokens: int # Total input tokens, including cached tokens
    10. output_tokens: int # Total output tokens
    11. cached_tokens: int # Cached input tokens; a subset of input_tokens
    12. def task_cost(usage: TaskUsage, price: Pricing) -> float:
    13. uncached = usage.input_tokens - usage.cached_tokens
    14. total = (
    15. uncached * price.input_per_m
    16. + usage.cached_tokens * price.cached_per_m
    17. + usage.output_tokens * price.output_per_m
    18. )
    19. return total / 1_000_000
    20. def cost_per_success(usages: list[TaskUsage], successes: int, price: Pricing) -> float:
    21. if successes == 0:
    22. return float("inf")
    23. total = sum(task_cost(u, price) for u in usages)
    24. return total / successes

    The example below uses illustrative prices and token counts:

    1. price = Pricing(input_per_m=2.0, output_per_m=8.0, cached_per_m=0.2)
    2. runs = [
    3. TaskUsage(input_tokens=12000, output_tokens=900, cached_tokens=8000),
    4. TaskUsage(input_tokens=15000, output_tokens=1200, cached_tokens=9000),
    5. ]