LLM API Cost Comparison: A Practical Framework for Estimating Usage and Pricing

    Learn how to estimate and compare LLM API costs using consistent token usage, billing, and caching assumptions. This framework covers three common pricing structures, a worked RAG example, and a reusable Python calculation for request-level and monthly budgets.

    Why LLM API Cost Comparisons Need a Consistent Baseline

    Cost is one of the most frequently discussed factors in choosing a large language model, alongside output quality. Yet many teams compare providers by simply adding up the rates on their official pricing pages and declaring one option cheaper.

    Comparing prices per million tokens alone tells you relatively little, for three reasons:

    1. Tokenization differs. Models can tokenize the same Chinese text or code at different granularities. The resulting token counts may differ by more than 10%.
    2. Billing structures differ. Some models distinguish between reasoning and non-reasoning modes. Others use time-dependent pricing, request-length tiers, or discounts for cached inputs.
    3. Usage patterns differ. Input-to-output ratios vary widely by workload. Retrieval-augmented generation (RAG) often involves long inputs and short outputs, while code generation can be more output-heavy. The same pricing table can produce different rankings for these two workloads.

    A rigorous cost comparison therefore isolates pricing differences under fixed usage assumptions. It is not a model quality benchmark.

    This article presents a reusable estimation framework and walks through a representative workload.

    1. Establish Four Consistent Assumptions

    Define Where Your Usage Estimates Come From

    Token estimates should be grounded in a real business workload—for example, average context and output lengths derived from historical logs—rather than arbitrary numbers.

    Make it clear that these figures are calculation assumptions, not measured consumption. They also do not imply that every model will complete the same task with equal quality.

    Quality and cost are separate dimensions. A cost comparison should not be presented as a capability ranking.

    Standardize the Billing Mode

    If the models support reasoning modes, decide which mode the comparison will use.

    One common approach is to calculate costs in reasoning mode, defining billable output as the combined total of reasoning tokens and final-answer tokens.

    A detail matters here: some models specify that requests producing no reasoning tokens are billed at non-reasoning rates. If your application can disable reasoning or limit its length, actual costs may be lower than the estimate.

    State the assumption explicitly and explain whether it makes the estimate conservative or optimistic.

    Specify Caching and Discount Assumptions

    Input costs often depend on cache hits. Requests that reuse the same prefix may be billed at substantially lower rates than ordinary input.

    For a clean baseline that isolates pricing differences, assume no cache hits. Also exclude:

    • Batch API discounts.
    • New-user credits and promotional offers.
    • Additional charges for tools such as web search or document parsing.
    • Duplicate charges from retries and the cost of manual handling.

    If a provider charges for cache writes, clarify how those charges relate to ordinary input charges. Otherwise, you may count the same portion of the input twice.

    Identify the Exact Models and Versions

    Prices and capabilities can vary substantially across model variants and versions.

    The results apply only to the specific API models being compared, not to an entire model family. Include this limitation in your conclusions.

    2. Worked Example: Three Common Pricing Structures

    Assume a RAG question-answering application uses approximately:

    • 20,000 input tokens per request
    • 4,000 billable output tokens per request, including reasoning and the final answer

    For illustration, consider three hypothetical models, A, B, and C, with the following published rates. Prices are in CNY per million tokens, retained as the currency of this example.

    Model and pricing condition Input Output
    A, off-peak hours 1 4
    A, peak hours 2 8
    B, input length ≤128K tokens per request 0.8 8
    C, default caching conditions 13 68

    The calculations below use the listed rates without applying any cache-hit discounts.

    1. A, off-peak: 20000/1e6*1 + 4000/1e6*4 = 0.02 + 0.016 = CNY 0.036
    2. A, peak: 20000/1e6*2 + 4000/1e6*8 = 0.04 + 0.032 = CNY 0.072
    3. B: 20000/1e6*0.8 + 4000/1e6*8 = 0.016 + 0.032 = CNY 0.048
    4. C: 20000/1e6*13 + 4000/1e6*68 = 0.26 + 0.272 = CNY 0.532

    These figures highlight four practical considerations.

    Input and Output Have Different Cost Weights

    In this example, output rates are several times higher than input rates. More generally, output rates can exceed input rates by a factor of ten or more.

    As a result, reducing output length can save more than reducing input length. However, input accounts for a larger share of consumption in long-context RAG workloads, so optimization priorities should follow the actual usage mix.

    Time-Based Pricing Creates Scheduling Opportunities

    Model A costs twice as much during peak hours as it does during off-peak hours.

    For tasks that can run offline, such as batch summarization or log analysis, queueing requests for off-peak execution can reduce costs without changing the underlying task.

    Length-Based Tiers Can Create Pricing Cliffs

    A model with B’s pricing structure uses 128K input tokens per request as a tier boundary. Input rates on opposite sides of such a boundary may differ by a factor of three.

    When requests approach the threshold, trimming context or summarizing conversation history to keep inputs within the lower tier can deliver substantial savings.

    Premium Reasoning and Lightweight Models Can Differ by an Order of Magnitude

    Large price differences do not automatically make a premium reasoning model poor value.

    Instead, they point to task-based routing as a central cost optimization strategy: send simple tasks to lightweight models and reserve premium models for complex reasoning.

    A common architecture performs this routing at the gateway layer, using task type, context length, and the need for deep reasoning to select a model.

    3. Turn the Framework into a Reusable Script

    Put the calculation into a simple function so you can rerun it whenever prices change:

    1. def cost(input_tokens, output_tokens, price_in, price_out):
    2. """Prices are in CNY per million tokens."""
    3. return input_tokens / 1e6 * price_in + output_tokens / 1e6 * price_out
    4. scenarios = [
    5. ("Short Q&A", 4_000, 800),
    6. ("RAG Q&A", 20_000, 4_000),
    7. ("Long-document summarization", 60_000, 8_000),
    8. ]
    9. for name, tin, tout in scenarios:
    10. for model, (pi, po) in price_table.items():
    11. print(name, model, round(cost(tin, tout, pi, po), 4))

    Here, price_table represents the input and output rates for the models and billing conditions included in your comparison.

    Multiply the per-request cost by monthly request volume to obtain a baseline budget estimate. Then add a 10–20% contingency for retries and exceptional cases to bring the budget closer to likely operating costs.

    4. Use the Framework as an Ongoing Decision Tool

    The value of cost estimation is not a one-time answer to “Which provider is cheapest?” It is a decision framework that can be updated as workloads and pricing policies change.

    The essentials are:

    • Use consistent, workload-based token assumptions.
    • Standardize billing modes.
    • Exclude caching discounts and promotions from the baseline.
    • Limit conclusions to the exact models and versions compared.
    • Use the results to inform task-based routing and time-based scheduling.

    Pricing tables will change, but the method remains useful. When official rates change or your input-to-output mix shifts, rerun the calculation to update the cost basis for model selection.