Large Language Model API Cost Estimation and Model Selection: A Practical Guide

    This guide explains how to estimate large language model API costs and choose the right model tier for production workloads. It breaks down the standard billing structure of input tokens, cached input tokens, and output tokens, abstracts pricing into a reusable cost formula, and shows how to compare model tiers against a fixed sample workload. It also covers tiered routing, architectural strategies for handling frequent price changes, a practical cost-optimization checklist, and the general cloud capabilities needed to run such a system. Readers will learn how to build a predictable, optimizable cost model instead of relying on a single "price per million tokens" number.

    1. The Problem: Why “How Much Does One Million Tokens Cost?” Is an Incomplete Question

    When building AI applications, almost every team asks the same question: how much does it cost to call a large language model for one million tokens? The question itself, however, is missing key constraints. Mainstream LLM API billing is rarely based on a single dimension. It is typically split into at least three categories: regular input tokens, cache-hit input tokens, and output tokens. The unit prices of these three often differ by multiples. Within the same model, a several-fold gap between input and output pricing is normal, and the gap across different models can be even larger.

    The correct question, then, is: given a specific input length, output length, cache hit rate, and call volume, what is the total cost of the task? This article does not focus on any specific vendor’s products. It discusses only the general billing structure and estimation methods, helping readers build their own cost model.

    One boundary needs to be clear up front: this article compares only standard text generation token costs. It does not include add-ons such as web retrieval, multimodal processing for images and audio, region-specific processing, or discounts and surcharges for batch asynchronous jobs. These add-ons can account for a significant share of a real bill and need to be modeled separately.

    2. Abstracting the Billing Model: Turning a Price List into a Function

    Setting aside specific numbers, any cloud provider’s text model pricing can be abstracted into the following form:

    1. Cost per call = Input tokens × P_in
    2. + Cache-hit tokens × P_cache
    3. + Output tokens × P_out
    4. Monthly cost = Cost per call × Monthly call volume + Fixed costs (gateway/logging/monitoring, etc.)

    The three unit prices generally follow this rule: P_cache < P_in < P_out. Cached input is cheaper because that prefix computation is reused, so the server skips the repeated forward pass. Output is the most expensive because it is generated token by token in an autoregressive manner, cannot be parallelized, and occupies compute for the longest time.

    This leads to three conclusions that matter greatly for engineering practice:

    1. Output length is the most cost-sensitive factor. When the output unit price is several times the input price, a requirement to “write three hundred more words” affects the bill far more than cutting the system prompt in half.
    2. Prompt prefix stability directly determines the cache hit rate. Putting volatile content such as timestamps, random IDs, or user nicknames at the very front of the prompt will repeatedly invalidate the cache.
    3. The input-to-output ratio (I/O ratio) is a selection profile. Extraction, classification, and rewriting tasks have a high I/O ratio and are best served by tiers with cheap input and good cache support. Generation, creative writing, and code completion tasks have a low I/O ratio and require close attention to the output unit price.

    3. Scenario-Based Estimation: Comparing Tiers Against the Same Workload

    To make the comparison reproducible, fix a hypothetical workload (the numbers are illustrative only and do not represent any real pricing):

    • System prompt + retrieval context: 4,000 input tokens per call
    • Model output: 600 tokens per call
    • Cache hit rate: 50% (a common magnitude in multi-turn conversations and fixed-prefix scenarios)
    • Monthly call volume: 1 million calls

    Plugging these into the formula, the monthly cost can be written as:

    1. Monthly cost = 1e6 × [ (4000×0.5)×P_cache + (4000×0.5)×P_in + 600×P_out ]

    Substituting the prices of different tiers reveals a stable pattern: the cost gap between the flagship tier and the lightweight tier is often more than an order of magnitude, while the mid tier covers roughly 80% of quality requirements in most business scenarios. This means that “defaulting to the most powerful model” is usually not cost-effective in engineering. A reasonable approach is tiered routing.

    A practical tiered routing pseudocode:

    1. def route(prompt, expected_output_len):
    2. # 1) High-value, long-output, strong-reasoning: route to flagship
    3. if prompt.complexity > 0.8 or expected_output_len > 2000:
    4. return "flagship"
    5. # 2) Regular business: route to mid tier, balancing quality and cost
    6. if prompt.cacheable_prefix:
    7. return "mid_tier_with_cache"
    8. # 3) High concurrency, short output, high fault tolerance: route to lightweight
    9. return "lightweight"

    4. Coping with Frequent Price Increases and Decreases

    Price adjustments are the norm. It is not uncommon for a certain class of models to see a several-fold increase while a new version is released at the same time. The right response is not to chase the price list, but to build cost controllability into the architecture:

    • Abstract a model gateway layer. Business code depends only on a unified inference interface, and model identifiers live in a configuration center, so switching and canary rollouts require no changes to business logic.
    • Build a unit economics dashboard. The core metrics are not the total bill, but “cost per thousand successful requests” and “token cost per unit of revenue,” while also monitoring the consumption share of the three token types: input, output, and cache.
    • Set budget guardrails. Define token quotas and rate limits per tenant and per endpoint, with circuit breaking for anomalous calls, to prevent a single point of failure from blowing up the monthly budget.
    • Make the final decision with an evaluation set, not the price. Maintain a business regression suite of a few dozen to a few hundred cases, record the two-dimensional distribution of quality scores and cost scores, and choose the tier on the Pareto frontier.

    5. Cost Optimization Checklist

    • Slim down the context: after reranking retrieval results, keep only the Top-K and remove duplicate and low-relevance fragments.
    • Fix the prefix: place unchanging instructions, examples, and tool descriptions at the front and reuse them to improve cache hits.
    • Constrain the output: replace vague requirements like “be as detailed as possible” with structured output and explicit length limits.
    • Semantic caching: cache results for high-frequency similar questions to eliminate calls entirely.
    • Batching and asynchrony: use asynchronous or batch channels for offline tasks, which usually come with price discounts.
    • Small model first: perform intent recognition and feasibility checks first, escalating to a stronger tier only when necessary.

    6. General Capability Combination for Cloud Deployment

    If you deploy the above solution in a cloud environment, general-purpose capability categories are usually enough to support it: use a container platform to host the model gateway and routing service, use object storage to store evaluation sets and call samples, use a message queue to smooth peaks and handle retries for offline tasks, and use logging and monitoring/alerting systems for token-level metering and cost attribution. General cloud product categories from cloud providers such as Baidu AI Cloud can serve as the foundation for this kind of architecture; refer to the official documentation for specific specifications and billing.

    7. Conclusion

    The answer to “how much does one million tokens cost” depends on where you position the ratio of input, output, and cache. The truly professional approach is to first quantify your workload profile, then use a unified formula to compare tiers side by side, and finally lock the choice into the architecture with an evaluation set and budget guardrails. This way, no matter how prices fluctuate, cost remains a predictable, optimizable, and rollback-able engineering variable, rather than a surprise on the month-end bill.