A Reproducible Method for Calculating LLM Subscription and API Costs

    Official per-token prices rarely reflect actual spend. This article introduces a reproducible method for comparing LLM subscription and API costs, built around a core metric: effective unit price, defined as total cost over a billing cycle divided by the count of new valid tokens. It details how to convert subscription quotas into an equivalent per-token price, breaks down the four major API billing items—uncached input, cache read, cache write, and output—and provides a Python script that simulates a full compression cycle to account for context growth and cache invalidation. The method reveals how metrics like average unit price and marginal cost per turn can produce different conclusions, and why a lower context threshold does not always mean higher efficiency. The article concludes with practical caveats about effective quota utilization, model-tier separation, and the need to verify against actual bills.

    Why Sticker Prices Do Not Match Actual Costs

    Comparing only the official per-million-token prices can lead to one-sided conclusions. Actual costs are influenced by at least three factors: pricing model (pay-as-you-go vs. subscription), cache hit rates, and how context grows and is compressed during a session.

    The core metric used throughout this article is:

    • Effective unit price = total cost per billing cycle ÷ total new valid tokens per cycle
    • New valid tokens refer to the input and output added to the conversation in each new turn, excluding historical context that is repeatedly processed.

    This definition places different access methods on a common scale for comparison. However, it only applies when comparing the same task profile. If input-to-output ratios, cache hit conditions, or compression frequencies differ, the results are not directly comparable.

    Is a Subscription Worthwhile? Calculate Tokens per Dollar First

    Subscription fees are fixed; the real question is how much of the quota you can actually consume. The conversion works as follows.

    Step 1. Normalize the quota to a monthly basis. If the provider states a weekly quota:

    Monthly quota (tokens) = Weekly quota (tokens) × 52 ÷ 12

    Step 2. Deduct the portion that cannot be used effectively. Many low-cost subscription tiers allocate only a fraction of the quota to high-quality models, while the rest goes to cheaper models or is simply wasted. Introduce an “effective utilization ratio”:

    Effective quota (tokens) = Monthly quota × Effective utilization ratio

    Step 3. Convert to an equivalent unit price:

    Equivalent unit price (USD / million tokens) = Monthly fee (USD) ÷ Effective quota (million tokens)

    As a hypothetical illustration: a subscription costs $200 per month, provides 48 million tokens per week, and has an effective utilization ratio of 50%. The monthly quota is approximately 208 million tokens, the effective quota is roughly 104 million tokens, and the equivalent unit price is around $1.92 per million tokens. These numbers are for demonstration only and do not represent any real platform.

    Two caveats apply. First, be conservative with quota estimates. Some high-end subscription tiers lack publicly documented usage caps, and estimates vary widely across sources; always use the lower estimate in calculations. Second, compare the same task profile. If the input-output ratio under a subscription differs from that of an API plan, re-weight the token mix accordingly before comparing.

    API Billing: Break Down Input, Cache Read, Cache Write, and Output

    When comparing API pricing, consider the following billing items separately:

    Billing item Description Notes for calculation
    Uncached input New input tokens not served from cache Billed at the standard input rate
    Cache read Historical input served from a prefix cache Price varies widely by platform; check the current rate card
    Cache write Cost of writing context into the cache Some platforms charge separately; default write policies can raise the effective input price
    Output Tokens generated by the model Usually more expensive than input; the ratio depends on the model and platform

    Cache write costs depend on the platform’s charging policy and your usage strategy. If every request writes to cache by default, the effective input price will be higher than a read-only cache scenario. Whether and how much the price rises should be computed from the platform’s write fee and write ratio, not from a fixed assumption.

    Session Simulation: Putting Cache and Compression into a Single Cycle

    A common simplification is to apply a fixed cache hit rate as a weighted average. This ignores an important dynamic: the historical context grows every turn, and compression invalidates the cache. A more robust approach is to simulate a full cycle.

    The cycle proceeds as follows:

    1. After compression, the summary becomes the new prefix and is written to cache at full price.
    2. In each turn, the existing context is billed at the cache read rate, new input at the standard input rate, and newly generated output at the output rate.
    3. The context grows each turn by the sum of new input and output, until it reaches the compression threshold.
    4. A compression request reads the entire context (cache is invalidated, so it is billed at the standard input rate) and generates a summary.

    The script below implements this logic. Rates are per million tokens; the returned cost and token counts can be divided directly.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class Rates:
    4. input: float # Uncached input, per million tokens
    5. cache_read: float # Cache read, per million tokens
    6. output: float # Output, per million tokens
    7. def session_cost(max_ctx, incr_in, incr_out, summary_len, r):
    8. """Simulates one compression cycle; returns (total_cost, new_valid_tokens)."""
    9. step = incr_in + incr_out
    10. if not (0 < summary_len < max_ctx) or step <= 0:
    11. raise ValueError("Invalid parameters: require 0 < summary_len < max_ctx and step > 0")
    12. cost = summary_len * r.input # First turn after compression: summary written at full price
    13. ctx = summary_len
    14. tokens = 0
    15. while ctx < max_ctx: # Context grows by `step` each turn; loop terminates
    16. cost += ctx * r.cache_read # Historical prefix hits the cache
    17. cost += incr_in * r.input # New input at standard rate
    18. cost += incr_out * r.output # Output at output rate
    19. ctx += step
    20. tokens += step
    21. cost += ctx * r.input # Compression: cache invalidated, full context read at standard rate
    22. cost += summary_len * r.output # Summary generation during compression
    23. return cost, tokens

    To get the effective unit price, divide cost by tokens. Since the rates are per million tokens, the result is also per million tokens.

    In addition to the average unit price, consider the marginal cost per turn: (ctx × cache_read_rate + new_input × input_rate + new_output × output_rate) ÷ step. This value rises as the context grows and more closely reflects the perceived cost of an additional turn in everyday use.

    Example Parameters and Results

    The table below shows a set of hypothetical parameters and rates, provided solely to reproduce the calculations.

    Parameter Scenario A Scenario B
    Compression threshold max_ctx 100,000 50,000
    New input per turn incr_in 2,000 2,000
    New output per turn incr_out 1,000 1,000
    Summary length summary_len 8,000 8,000
    Input rate (per million tokens) 10 10
    Cache read rate (per million tokens) 1 1
    Output rate (per million tokens) 40 40

    The simulated results are as follows.

    Result Scenario A Scenario B
    Turns per cycle 31 14
    New valid tokens 93,000 42,000
    Total cost per cycle 4,913,000 2,125,000
    Average unit price (per million tokens) 52.83 50.60
    Marginal cost at first turn 22.67 22.67
    Marginal cost at last turn 52.67 35.67

    Under these parameters, lowering the compression threshold from 100,000 to 50,000 reduces the average unit price by about 4%. The reason is that each turn reads the entire historical prefix; the higher the threshold, the longer the history read per turn, driving up cumulative cache read costs. This runs counter to the intuition that longer context is always more efficient. The fixed cost of compression itself (full-price summary write and generation) is the same in both scenarios, so more frequent compression spreads that overhead over a larger fraction of tokens. The relative strength of these two effects depends on the specific parameters; run the script with your own rates and scenarios to verify.

    Conclusions and Limitations

    1. Whether a subscription is worthwhile depends on whether the effective quota is fully utilized. If the quota is sparingly used, pay-as-you-go may be cheaper.
    2. High-quality and low-cost models should be analyzed separately, as cache strategies and output ratios differ significantly.
    3. Examine the marginal cost per turn, not just the average. Marginal cost reflects the real cost of each additional turn in daily use.
    4. Formalizing session simulation into a script lets you reproduce comparisons across vendors’ rate cards, avoiding reliance on a single promotional claim.

    Risk warning: Prices change with promotions, tiers, cache policies, and billing conventions. Before making any decision, verify against the official billing documentation and cross-check with actual invoices. The rates and quotas in this article are hypothetical and should not be used directly for budgeting.