How to Compare LLM API Pricing: A Reproducible Cost Calculation Method

    Comparing LLM API prices across providers is harder than it looks: versions, currencies, billing units, and cache pricing all differ. This article presents a reproducible method for cost comparison—standardizing the comparison baseline, weighting input/output prices by real usage ratios, estimating monthly costs with Python examples, and avoiding common pitfalls such as promotional pricing and hidden costs. It also covers data collection practices for verifiability and a step-by-step selection workflow.

    1. Where Price Differences Come From

    Quotes for the same model across different channels are typically shaped by several factors:

    • Channel positioning: Direct access from the model provider, cloud platform resellers, and third-party aggregation gateways each have different cost structures and margins.
    • Region and currency: Data center costs, taxes, and settlement currencies vary by region and affect the final price.
    • Version and configuration: Within the same model family, flagship, lightweight, and coding-specialized variants often differ significantly in unit price.
    • Billing details: Whether input and output tokens are priced separately, whether cache hits have their own pricing tier, and whether tiered pricing exists all affect actual spending.

    Therefore, you should not assume that “direct access is always the most expensive” or that “third parties are always cheaper.” Such judgments need to be validated against data collected under a unified baseline.

    2. Standardize the Comparison Baseline First

    A price comparison is only meaningful if the objects being compared are actually comparable. Before comparing, confirm the following four items:

    2.1 Version Alignment

    Different channels may list different version numbers. If a channel only offers a previous-generation version, comparing its unit price directly against a newer version is meaningless. For versions that cannot be aligned, mark them as “not available” rather than substituting a similar model.

    2.2 Currency and Exchange Rates

    Channels in different regions often price in different currencies. Choose one conversion currency and record the exchange rate along with its date. When exchange rates fluctuate significantly, it is advisable to also report the original-currency prices.

    2.3 Billing Units

    Most platforms bill per million tokens. Confirm that units are consistent—for example, some pages quote prices per thousand tokens, which can introduce a tenfold error during conversion.

    2.4 Caching and Additional Fees

    Some platforms offer lower unit prices for cached input tokens; others have no such tier. List cache pricing separately when comparing, rather than looking only at the base input price.

    3. Weight Prices by Actual Usage Ratios

    The ratio of input to output tokens varies greatly across scenarios. Q&A workloads tend to be input-heavy, while generative workloads are output-heavy. For coding assistants or agent-style applications, multi-turn tool calls produce large amounts of context, so input share is usually high—but output tokens are generally priced higher, so both must be calculated together.

    The weighted unit price is calculated as follows:

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

    The input and output shares should come from your team’s own call logs, not from a borrowed rule of thumb. Below is an illustrative calculation function:

    1. def blended_price(price_in: float, price_out: float,
    2. ratio_in: float, ratio_out: float) -> float:
    3. """Compute the weighted price per million tokens based on input/output shares."""
    4. assert abs(ratio_in + ratio_out - 1.0) < 1e-9, "Shares must sum to 1"
    5. return price_in * ratio_in + price_out * ratio_out
    6. # The numbers below are fictional examples used only to illustrate the
    7. # calculation process; they do not represent any real pricing
    8. price = blended_price(price_in=2.0, price_out=8.0, ratio_in=0.3, ratio_out=0.7)
    9. print(f"Weighted price: {price:.2f} per million tokens") # Output: 6.20

    In this example, with an input price of 2, an output price of 8, and a 70% output share, the weighted price is 6.2. Every 10-percentage-point increase in output share raises the weighted price by about 0.6. This shows that output share is the key variable driving cost.

    Estimating Monthly Cost

    With the weighted unit price, you can estimate monthly spending:

    1. def monthly_cost(total_tokens_million: float, blended: float,
    2. cache_hit_rate: float = 0.0,
    3. cache_discount: float = 0.0) -> float:
    4. """
    5. total_tokens_million: total monthly tokens (in millions)
    6. blended: weighted unit price (per million tokens)
    7. cache_hit_rate: input cache hit rate
    8. cache_discount: discount ratio on cache hits relative to base price
    9. """
    10. effective = blended * (1 - cache_hit_rate * cache_discount)
    11. return total_tokens_million * effective
    12. # Example: 50M tokens per month, 40% cache hit rate, 80% discount on cached portion
    13. print(monthly_cost(50, 6.2, cache_hit_rate=0.4, cache_discount=0.8))

    Note that cache discounts typically apply only to input tokens, so the function above is an approximation. For precise accounting, input and output costs should be calculated separately.

    4. Data Collection and Verifiability

    The credibility of a price comparison depends on whether data sources are clear and traceable. The following practices are recommended:

    • Record collection time: Prices change frequently; the same dataset may become outdated on a different date.
    • Record source pages: Save the pricing page URL or a screenshot so others can verify the data.
    • Distinguish page types: Some official sites use dynamic rendering, so static scraping may not capture the full price table. In such cases, note whether the data comes from an alternative page.
    • Mark missing items: If a channel doesn’t offer a version or a page omits a field, mark it explicitly instead of filling in estimates.
    • Fix version numbers: Only compare model versions of the same generation and positioning in the report.

    These practices may seem tedious, but they prevent the problem of data that “looks precise but cannot be reproduced.”

    5. Common Pitfalls

    Looking only at unit price, not usage structure. A channel with a low input price may end up costing more if its output price is high and your workload is output-heavy.

    Ignoring cache hit rates. In scenarios with long contexts and repeated system prompts, cache hit rates have a major impact on cost. A well-designed caching strategy can sometimes be more effective than switching channels.

    Treating promotional prices as long-term prices. Limited-time discounts and first-purchase offers should not be used for long-term budget planning.

    Ignoring hidden costs. Failed retries, truncation of overlong contexts, and repeated calls made to meet quality requirements all push up actual spending.

    Ignoring non-price metrics. Rate limits, concurrency quotas, response latency, service availability, and compliance requirements all affect the selection decision. A cheap channel that throttles frequently may not be suitable for production.

    1. Define the scenario: Clarify the application type, peak concurrency, and quality requirements.
    2. Collect logs: Measure the actual input/output ratio, cache hit rate, and monthly usage.
    3. List candidate channels: Confirm version alignment and unify currency and billing units.
    4. Calculate weighted costs: Derive the weighted unit price and monthly estimate for each channel.
    5. Run a small-scale validation: Evaluate output quality, latency, and stability on real business samples—price is only one dimension.
    6. Review periodically: Model prices change frequently; re-verify the data monthly or quarterly.

    7. Cost Attribution and Management

    When a team uses multiple models or channels simultaneously, cost management becomes complex. You can use the billing and monitoring services of cloud platforms to attribute costs by project, module, or model, and set up usage alerts. This makes it easier to spot abnormal consumption early and to compare costs across different options over the long term.

    In summary, price comparison in model selection should be built on a unified baseline, real usage data, and traceable sources. With the method above, a team can repeatedly evaluate different models using the same process and continuously optimize its cost structure as prices and business needs evolve.