LLM API Pricing Comparison: A Consistent Cost-Accounting Method

    This article explains how to compare LLM API pricing on a consistent basis. It covers the main sources of price variance, normalization of billing units and currencies, weighted cost per million tokens, pricing metadata, verification of public prices, cost per successful task, and non-price channel factors. It also includes example code and a configurable routing approach for reducing vendor lock-in.

    1. Where Price Differences Come From

    The cost of calling a large language model is determined by both the unit price and the actual number of tokens consumed. Under the same model name, the actual price paid through different channels can differ by several times. The main reasons include the following.

    Supply-chain position. Model developers may sell directly, cloud platforms may purchase and resell, and aggregation or routing platforms may buy in bulk and redistribute. Each layer can add cost, and each layer can also reduce cost through volume discounts.

    Billing rules. Some channels price per million tokens, while others distinguish between input, output, cache hits, and cache writes. Some channels also adjust prices by time window or usage tier, so the same request may cost different amounts at different times.

    Currency and exchange rates. Channels priced in foreign currencies need to be converted at a consistent exchange rate. If the exchange-rate date differs, the comparison result will be biased.

    Price basis. Whether a quote includes tax, whether there is a minimum spending threshold, and how prepaid discounts are calculated all change the final amount paid.

    Version differences. The same product line often includes a flagship version, a version specialized for coding scenarios, a lightweight version, and others. Their capabilities and pricing are not equivalent, so comparing them directly side by side leads to incorrect conclusions.

    Therefore, statements such as “direct connection is always more expensive” or “third parties are always cheaper” are only empirical judgments. Model selection should be based on verifiable data.

    2. Establish a Consistent Comparison Basis

    2.1 Standardize the Billing Unit

    Different channels quote prices in very different ways, so convert them to the same unit before comparing. A common approach is to convert all prices into “CNY per million tokens.” When converting, keep the original currency and exchange rate so the calculation can be reviewed later.

    2.2 Weight by Consumption Mix

    Input tokens and output tokens usually have different unit prices, and output is generally more expensive. Therefore, you should not simply take an average. Instead, weight the price by the actual consumption ratio:

    Weighted unit price = input ratio × input unit price + output ratio × output unit price

    In coding-agent tasks, the model needs to read a large amount of context and generate a relatively large amount of code, so the output share is often higher. Some teams have observed a consumption mix of roughly 30% input and 70% output, but this is only a reference. The actual ratio should be calculated from your own call logs.

    If a channel provides cache billing, you also need to include cache hit rate as a variable, because the unit price for cache-hit portions is usually significantly lower than that for ordinary input.

    The example code below demonstrates the weighted calculation. The prices are illustrative numbers, not real quotes.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class PriceQuote:
    4. channel: str # Channel identifier, used only for distinction
    5. input_price: float # Price per million input tokens in the original currency
    6. output_price: float # Price per million output tokens in the original currency
    7. fx_rate: float = 1.0 # Exchange rate for converting the original currency to CNY
    8. def weighted_price(quote: PriceQuote, input_ratio: float = 0.3) -> float:
    9. """Calculate the CNY weighted unit price based on the input/output consumption ratio (CNY / million tokens)."""
    10. if not 0 <= input_ratio <= 1:
    11. raise ValueError("input_ratio must be between 0 and 1")
    12. output_ratio = 1 - input_ratio
    13. base = input_ratio * quote.input_price + output_ratio * quote.output_price
    14. return base * quote.fx_rate
    15. quotes = [
    16. PriceQuote("Channel A", input_price=2.0, output_price=8.0),
    17. PriceQuote("Channel B", input_price=1.5, output_price=12.0, fx_rate=7.2),
    18. ]
    19. for q in sorted(quotes, key=weighted_price):
    20. print(f"{q.channel}: {weighted_price(q):.2f} CNY per million tokens")

    2.3 Record Pricing Metadata

    Every price should be accompanied by metadata; otherwise, the result cannot be reviewed. At a minimum, record the following fields:

    Field Description
    Model version The exact version number, not just the series name
    Channel type Direct connection, cloud platform resale, aggregation routing, etc.
    Billing unit Per million tokens, per thousand tokens, or another unit
    Currency and exchange rate Original currency, conversion rate, and date
    Tax included Whether the quote includes taxes
    Tier and time-window rules Whether usage tiers or time-of-day price differences apply
    Price-check time and source Page URL and capture date, with a snapshot retained

    3. Steps for Verifying Public Pricing

    1. Use the public pricing page as the source of truth. Prefer the official pricing page of the model developer or platform, save a screenshot or page snapshot, and record the capture time.
    2. Verify the version number. A model with the same name may correspond to multiple versions. Confirm that you are comparing versions at the same capability level.
    3. Mark missing items accurately. When a public price cannot be found, mark it as “not public” or “not listed.” Do not fill the gap with prices from other versions or estimated values, or the result will be distorted.
    4. Complete the verification within the same time window. Prices may change due to promotions or adjustments, and scattered queries introduce time bias.
    5. Produce a reviewable data table. Every number should be traceable to a specific source.

    4. From Unit Price to Cost per Task

    A low per-token price does not mean a low total cost for completing a task. A lower-priced model may require more turns, longer context, or more retries to pass the same task. Therefore, a more decision-useful metric is cost per successful task:

    Cost per successful task = total spend / number of tasks passed

    Assume that on the same evaluation set, Model A spends CNY 120 and passes 60 tasks, while Model B spends CNY 180 and passes 95 tasks. Model A’s cost per successful task is CNY 2.00, and Model B’s is about CNY 1.89. The model with the higher unit price is actually more cost-effective.

    1. def cost_per_success(total_cost: float, success_count: int) -> float:
    2. """Calculate the average cost per successful task. Return infinity when there are no successful tasks to avoid misleading comparisons."""
    3. if success_count == 0:
    4. return float("inf")
    5. return total_cost / success_count

    Calculating this metric requires two prerequisites: the evaluation set must cover real business scenarios, and the task pass criteria must be objective and automatically determinable.

    5. Channel Factors Beyond Price

    Cost is only one dimension of model selection. The following factors also affect the final decision:

    • Stability and rate limits. Pay attention to concurrency quotas during peak periods, request rate limits, and the response behavior after limits are exceeded.
    • Data compliance. Confirm where request data is stored and how it is processed, and determine whether it meets industry regulatory requirements.
    • Invoicing and settlement. Corporate reimbursement requires specific types of invoices, and settlement cycles and prepayment methods also need to be confirmed in advance.
    • New version rollout cadence. Different channels may take several weeks apart to onboard new versions. If the business depends on new capabilities, evaluate this in advance.
    • Switching cost. Whether the API protocol is compatible and how much adaptation-layer work is required directly determine the cost of changing channels later.
    • Disaster recovery capability. Whether you can quickly switch to a backup channel when a single channel fails.

    6. Engineering Practice: Use Configurable Routing to Reduce Lock-In Risk

    Putting channel information into configuration rather than hard-coding it in business logic can significantly reduce switching costs. The following is an illustrative configuration; field names should be adjusted according to the actual gateway or adaptation layer:

    1. llm_channels:
    2. primary:
    3. provider: channel_a
    4. model: large-tier-v1
    5. enabled: true
    6. fallback:
    7. provider: channel_b
    8. model: large-tier-v1
    9. enabled: true
    10. routing:
    11. strategy: cost_first_with_fallback
    12. max_retries: 2
    13. timeout_seconds: 60
    14. budget:
    15. monthly_limit_cny: 5000
    16. alert_threshold: 0.8

    Combined with the following practices, this works better:

    • Put the price table under version control