LLM API Cost Estimation: A Usage-Based Framework for Choosing a Model

    This article explains why comparing list prices per token can lead to the wrong API choice. It walks through five steps for building a consistent cost estimate, covering thinking-mode output, time-of-day pricing, length tiers, caching rules, and excluded items. It also includes a reusable Python script and explains how to read the results for a final decision.

    1. Why Comparing List Prices Leads to Mistakes

    When choosing an LLM API, many teams open the pricing pages of several providers, compare the price per million input and output tokens, and pick the lowest number. This approach looks intuitive, but it often leads to the wrong conclusion for three reasons.

    First, billing structures differ. Providers do not bill in the same way. Some charge different prices during peak and off-peak hours. Some charge by tier, based on the input length of each request. Some offer caching, where the price for cached input and uncached input can differ by an order of magnitude. Comparing a single list price is like comparing values measured in different units.

    Second, thinking mode changes output cost. Most current models support a “thinking” or “reasoning” mode. When it is enabled, the model generates internal reasoning tokens before its final answer. These reasoning tokens are usually billed as output, so the actual output can be several times longer than the final answer. If thinking mode is not set the same way across providers, the cost comparison will be seriously distorted.

    Third, your usage pattern determines the real cost. Long document summarization, multi-turn conversations, and batch data processing have very different input-to-output ratios. One million tokens affects models with different billing structures in very different ways, depending on whether those tokens are input or output.

    A sound approach is to fix the measurement basis first, apply your real usage second, and isolate the effect of price last. Only then should you draw a conclusion.

    2. Five Steps to Build a Consistent Cost Basis

    1. Define what you are comparing

    Before selecting a model, confirm that each candidate endpoint has a distinct product positioning, such as lightweight and fast, balanced, or flagship reasoning. These endpoints are not necessarily direct competitors within the same model series. A conclusion applies only to “these endpoints under the specified billing conditions.” It cannot be generalized into a ranking of overall model capability. State this clearly when reporting to your team, so the results are not mistaken for a capability benchmark.

    2. Fix thinking mode and the output definition

    Run all estimates with thinking mode enabled, and define output explicitly: output tokens equal thinking tokens plus final answer tokens, billed together. Also watch for special rules on some platforms. For example, some services bill at non-thinking rates if thinking is enabled but no thinking tokens are actually produced. This “bill by actual usage” rule must be handled separately in your estimation script. Otherwise, the estimate will systematically overstate costs.

    3. Handle time-of-day pricing

    Some platforms charge different input prices during peak hours (for example, weekday daytime) and off-peak hours. The difference can reach 2x. When estimating, answer this business question: when does your traffic occur?

    • If usage is concentrated in working hours (for example, customer support or office assistance), estimate with peak prices.
    • If execution can be delayed (for example, overnight batch jobs or data cleaning), estimate with off-peak prices. You can reduce costs further by using a batch API, if the provider offers one.

    For the same model, the cost conclusion can reverse completely depending on the time-of-day assumption.

    4. Handle length tiers and caching rules

    • Length tiers: Some platforms switch to a higher price tier when the input of a single request exceeds a threshold, such as 128K tokens. If your scenario includes very long context calls, calculate each tier separately. Do not apply the low-price tier to all requests.
    • Cache writes and hits: Some platforms bill context caching as a write price plus a hit price. The write price may be the same as or different from the normal input price. When estimating, make sure write costs are not counted twice. For multi-turn conversations and repeated prefixes, such as a fixed system prompt, the cache hit rate has a major effect on cost. For one-off independent requests, the benefit of caching is close to zero.

    5. List exclusions to keep results reproducible

    A rigorous estimate should state which variables it excludes:

    • free credits and promotional discounts
    • optional tools such as web search or OCR, which are usually billed separately
    • one request per task
    • retries and manual review costs
    • cache hits, unless caching is analyzed separately

    Writing these exclusions down makes the conclusions reproducible and open to challenge by others.

    3. A Reusable Cost Estimation Skeleton

    The following Python skeleton shows how to implement these rules in an executable estimation script:

    1. # Cost estimation framework sketch (prices are placeholders; refer to each provider's official pricing page)
    2. PRICING = {
    3. "model_a_offpeak": {"input": 1.0, "output": 4.0}, # CNY per million tokens
    4. "model_a_peak": {"input": 2.0, "output": 4.0},
    5. "model_b_short": {"input": 0.8, "output": 4.0}, # input <= 128K tier
    6. "model_b_long": {"input": 2.5, "output": 4.0}, # input > 128K tier
    7. }
    8. def cost(model, input_tokens, output_tokens):
    9. p = PRICING[model]
    10. return input_tokens / 1e6 * p["input"] + output_tokens / 1e6 * p["output"]
    11. # Scenario examples: long document summary (thinking mode; output includes reasoning tokens)
    12. scenarios = {
    13. "Long document summary": dict(input_tokens=150_000, output_tokens=12_000),
    14. "Multi-turn customer support": dict(input_tokens=30_000, output_tokens=20_000),
    15. }
    16. for name, u in scenarios.items():
    17. tier = "model_b_long" if u["input_tokens"] > 128_000 else "model_b_short"
    18. print(name,
    19. "A (off-peak):", round(cost("model_a_offpeak", **u), 2),
    20. "A (peak):", round(cost("model_a_peak", **u), 2),
    21. "B:", round(cost(tier, **u), 2))

    The core value of this skeleton is that it explicitly encodes the three factors most often overlooked: input length tiers, time-of-day prices, and output that includes thinking tokens. To reuse it, replace the prices or usage figures with your own values.

    4. Reading the Results for a Decision

    Do not simply declare the cheapest option the winner. Interpret the results with this framework instead.

    1. Split by scenario instead of using a global average. The results may diverge. For example, Model A might be 40% cheaper for batch processing, while Model B is 25% cheaper for high-frequency conversations. In that case, weight the results by your traffic mix, or adopt a “route by scenario” architecture in which different task types call different endpoints.

    2. Sensitivity analysis matters more than a single point estimate. Perturb the key assumptions, including the thinking token share, the cache hit rate, and the peak traffic share, by ±30%. Then check whether the conclusion holds. If a model’s advantage disappears under these changes, the advantage is fragile and should not be the basis for a decision.

    3. Cost is only one dimension. Completion rate, answer quality, latency, rate limits, and regional availability also affect total cost of ownership. An inexpensive endpoint that requires many retries and manual fallback may cost more overall. Beyond the cost estimate, run a small-scale pilot to verify quality metrics.

    4. Set up continuous monitoring. After launch, use a logging service to record token usage and cost for each call, and summarize them weekly. Providers change prices and release new model versions often, so a static estimate usually stays valid for only a few months.

    5. Summary

    The correct path for LLM API selection is: fix the basis (thinking mode, output definition, caching and time-of-day rules), apply real usage, estimate by scenario, run sensitivity analysis, and then combine the results with quality and latency to make the decision.

    A price table only provides intuition. Real cost conclusions come from breaking down billing structures and understanding how your traffic is distributed. Turning this method into an internal estimation template lets your team make decisions quickly with each model iteration or price change. It also helps you avoid paying hidden costs from optimizing a single metric.