LLM API Cost Calculation: Comparing Prices for the Same Model Across Providers

    Learn how to compare LLM API pricing across providers using workload-based token ratios, consistent currencies and billing units, and adjustments for caching and fees. A Python example demonstrates weighted cost calculations, while a practical checklist covers model versions, rate limits, reliability, and data compliance.

    1. Why Prices for the Same Model Can Vary Widely

    LLM API pricing depends on several factors, including model version, deployment region, billing units, caching support, concurrency limits, and service levels. Providers using the same model name may offer different versions or regional deployments, so comparing listed prices alone can lead to misleading conclusions.

    Common sources of price differences include:

    • Service provider: Direct services from model developers, cloud platform resellers, and third-party API aggregators have different pricing strategies and cost structures.
    • Model version: A model family may include flagship, lightweight, and coding-focused versions. Comparing unit prices is not meaningful if the versions differ.
    • Deployment region: Pricing, taxes, and currency conversion practices may vary across regions.
    • Billing structure: Some providers charge separately for input and output tokens, apply separate rates to cached input, or offer tiered pricing.

    Establish a consistent basis for comparison before evaluating the numbers.

    2. Understand the Billing Structure

    Most LLM APIs use token-based billing, typically quoted per million tokens. Pricing generally includes:

    1. Input pricing: Tokens sent to the model, including prompts, context, and tool results.
    2. Output pricing: Tokens generated by the model. For most models, output tokens cost substantially more than input tokens.
    3. Cached input pricing: The rate charged when repeated context qualifies for a cache hit, usually lower than the standard input rate.

    The cost of a single request can be expressed as:

    1. Request cost =
    2. Uncached input tokens × Input rate
    3. + Output tokens × Output rate
    4. + Cached input tokens × Cached input rate

    The token counts and rates must use matching units. When rates are quoted per million tokens, divide each token count by 1,000,000 before multiplying. Cached input must be separated from uncached input to avoid counting it twice.

    Looking only at input or output pricing can distort the comparison. A provider with a low input rate but a high output rate may be more expensive for output-heavy workloads.

    3. Calculate Weights from Your Workload

    To combine input and output rates into a comparable metric, first determine the share of tokens consumed by each. Use actual request logs rather than estimates based on intuition.

    Follow these steps:

    • Aggregate input and output token counts from the past week or month.
    • Group usage by task type. Code generation, document summarization, and retrieval-based question answering can have very different token ratios.
    • For tasks involving multiple rounds of tool calls, include the input and output tokens from every round. Tool results often become input to the next round and are easy to overlook.

    Code generation and agent workloads can have a relatively high output share. Suppose your logs show that input accounts for approximately 30% of total tokens and output accounts for 70%. The weighted rate is:

    1. Weighted rate = Input rate × 0.3 + Output rate × 0.7

    If cache hits account for a substantial share of input, split the input component into uncached and cached input, then apply the corresponding rates.

    4. Normalize Currency and Billing Units

    Cross-provider comparisons require consistent currencies, exchange rates, and billing units.

    • Choose a base currency and record the exchange rate and its date in the report.
    • Convert all rates to a price per million tokens. If a provider quotes prices per thousand tokens, multiply those rates by 1,000.
    • Use the public pricing pages available at the time of the report. Save snapshots or screenshots for later verification.
    • If a version has no published price or is not offered by a provider, state that explicitly. Do not substitute the price of another version.

    5. Worked Example

    The following Python script calculates weighted rates and ranks providers. All prices are fictional and illustrate the calculation method only; they do not represent actual offers.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class Channel:
    4. name: str
    5. input_price: float # CNY per million tokens
    6. output_price: float # CNY per million tokens
    7. def blended_price(ch: Channel, input_ratio: float = 0.3) -> float:
    8. """Calculate the weighted rate from input and output token shares."""
    9. if not 0 <= input_ratio <= 1:
    10. raise ValueError("input_ratio must be between 0 and 1")
    11. return ch.input_price * input_ratio + ch.output_price * (1 - input_ratio)
    12. channels = [
    13. Channel("Provider A", input_price=2.0, output_price=8.0),
    14. Channel("Provider B", input_price=1.0, output_price=4.0),
    15. Channel("Provider C", input_price=1.5, output_price=9.0),
    16. ]
    17. for ch in sorted(channels, key=blended_price):
    18. print(f"{ch.name}: {blended_price(ch):.2f} CNY per million tokens")

    Output:

    1. Provider B: 3.10 CNY per million tokens
    2. Provider A: 6.20 CNY per million tokens
    3. Provider C: 7.35 CNY per million tokens

    Provider C’s input rate falls between those of the other two providers, but its output rate is the highest. It therefore ranks last after weighting the rates by token consumption. Ranking providers by input price alone would produce a different—and misleading—result for this workload.

    6. What to Check Before Drawing Conclusions

    A price comparison should also account for the following:

    1. Matching versions: Compare the same version or functionally equivalent versions. If a provider does not offer a comparable version, mark it as “no comparable data” rather than forcing a numerical comparison.
    2. Taxes and service fees: Some listed rates exclude taxes or carry additional platform fees.
    3. Rate limits and concurrency: Lower-priced providers may impose stricter limits, reducing effective throughput for high-concurrency workloads.
    4. Reliability and service levels: Evaluate availability commitments, incident response, and historical reliability.
    5. Data compliance: For sensitive data, confirm storage regions, retention periods, and permitted data uses.
    6. Caching and context length: Cache hit rates can significantly affect costs in long-context workloads. Recalculate estimates using real traffic.
    1. Use request logs to measure input and output token shares, grouped by task type.
    2. List candidate models and their exact versions, then confirm whether each provider actually offers those versions.
    3. Normalize currencies and billing units, and record pricing sources and collection dates.
    4. Calculate weighted unit costs, adjusting for caching, taxes, and other applicable fees.
    5. Run a limited-traffic trial to verify that latency, success rates, and output quality meet your requirements.
    6. Make a decision based on cost, reliability, and compliance needs, and review pricing changes regularly.

    Price is only one selection factor. A lower unit rate does not necessarily produce a lower total cost: weaker output quality can lead to more retries and greater overall spending. Evaluate unit cost alongside task completion rates and actual token consumption per task to reach a more reliable conclusion.