LLM API Cost Estimation Methodology and Scenario-Based Practice

    This article presents a reproducible methodology for estimating large language model API costs across different workloads. It defines a unified set of pricing assumptions, abstracts three common billing models, models token usage for customer support, batch content generation, and long-document analysis, and explains how time-of-day pricing, input-length tiers, and caching rules can reverse rankings based on unit price. It also outlines a routing and fallback architecture, common estimation mistakes, and a checklist for more accurate cost governance.

    1. Why the “Cheapest” Option Is Often Calculated Wrong

    When integrating LLM capabilities into business systems, teams typically face three workloads: customer-facing support replies, batch content generation, and long-document analysis and summarization. On the surface, all three look like “call an API once, pass in text, get a result back.” In practice, their billing profiles differ significantly. Without a shared baseline, the question “which API is cheaper?” has almost no meaningful answer.

    There are three common estimation mistakes. The first is comparing only unit prices while ignoring the asymmetry between input and output pricing. Long-document workloads are dominated by input tokens, while short Q&A workloads have a higher output share; a lower unit price does not necessarily mean a lower bill. The second is ignoring time-of-day and tiering rules. Some services price calls differently based on when they occur or on the length of a single input, so comparing across time windows or length bands can lead to the opposite conclusion. The third is treating token counts as measured values. In most budget estimates, token counts are assumed values chosen to isolate the pricing factor.

    This article takes a different approach: fix a set of assumed usage figures, treat price as the only variable, reach comparable budget conclusions first, and then discuss quality and engineering constraints. Note that all numbers here are budget projections based on publicly available billing rules. No real API calls were measured, and the token counts are calculation assumptions. They do not represent the quality, completion rate, or actual consumption of any model.

    2. Seven Assumptions for a Unified Estimation Baseline

    To make different APIs comparable, the baseline must be fixed first. It is recommended to state the following assumptions explicitly in any internal estimation document:

    1. All pricing is based on thinking mode, where output tokens are the combined billable output of the reasoning process and the final answer;
    2. Assume no cache hits and use standard synchronous calls;
    3. Do not use batch discounts, free quotas, or promotional offers;
    4. Do not enable extra tool capabilities such as web search or document parsing;
    5. Count only one request per task, excluding retries and human fallback costs;
    6. If the provider prices cache writes separately, treat the write price as equal to the corresponding input price, without stacking it twice;
    7. If the provider tiers prices by single-input length, the tier boundaries must be included in the calculation.

    The value of this baseline is reproducibility: if someone else recalculates it later, the conclusion should remain the same.

    3. Abstracting the Pricing Model

    Abstract three differently positioned APIs into three billing forms for programmatic estimation:

    • Form A: input and output unit prices vary by time of day (off-peak / peak);
    • Form B: input unit price is tiered by single-input length, while output unit price is fixed;
    • Form C: input and output unit prices are fixed, but cache write rules apply.

    A schematic implementation is shown below (it expresses calculation logic only and contains no specific product identifiers):

    1. def cost(tokens_in, tokens_out, price):
    2. return tokens_in * price["in"] / 1e6 + tokens_out * price["out"] / 1e6
    3. # Form A: time-sensitive
    4. def cost_time_sensitive(tin, tout, is_peak):
    5. p = PEAK if is_peak else IDLE
    6. return cost(tin, tout, p)
    7. # Form B: input-length tiers
    8. def cost_tiered(tin, tout):
    9. p = TIER_HIGH if tin > 128_000 else TIER_LOW
    10. return cost(tin, tout, p)

    From an engineering perspective, it is advisable to externalize the price table as configuration and let the estimation script only iterate over the scenario matrix, so that code changes are not needed every time prices change.

    4. Usage Modeling for Three Scenarios

    Scenario 1, customer support replies: about 1.5k input tokens per call (including the system prompt and conversation history), about 300 output tokens, and 200,000 requests per day. The input-to-output ratio is about 5:1, so the output unit price has a significant impact.

    Scenario 2, batch content generation: about 800 input tokens and about 1.2k output tokens per call, with 50,000 tasks per day. Output exceeds input, making the output unit price the main cost item.

    Scenario 3, long-document analysis: about 60k input tokens and about 2k output tokens per call, with 2,000 tasks per day. Input accounts for more than 95% of the cost, and this scenario easily triggers length tiers and context limits.

    Writing the three scenarios as a configuration matrix makes it possible to calculate all combinations at once:

    1. SCENARIOS = [
    2. {"name": "Customer Q&A", "tin": 1500, "tout": 300, "calls": 200_000},
    3. {"name": "Content generation", "tin": 800, "tout": 1200, "calls": 50_000},
    4. {"name": "Long document", "tin": 60_000, "tout": 2000, "calls": 2000},
    5. ]

    5. Abstract Conclusions from the Estimation

    Under the baseline above, the conclusions show a clear structural pattern, summarized in three points:

    First, time-sensitive APIs have a clear cost advantage during off-peak hours, because the price gap between peak and off-peak can be several times. Once tasks concentrate in the morning and afternoon peak windows on workdays, this advantage is significantly weakened.

    Second, during peak hours, for short Q&A and content generation workloads, the input-tiered API is cheaper within the low-price tier. But once a single input crosses the length threshold into the high-price tier, its input cost rises by a multiple, and the long-document scenario reverses.

    Third, the API with fixed but overall higher unit prices has a higher total cost across these three usage profiles. The reason to choose it is usually not budget, but stability of results, long-context consistency, or compliance requirements.

    This leads to an actionable selection principle: profile the workload first, then discuss unit price; confirm the time-of-day and input-length distributions before deciding on primary and backup APIs.

    6. Applying the Conclusions to Architecture

    A “routing + fallback” structure is recommended instead of binding to a single API:

    1. Request -> Classifier (scenario / length / time) -> Price and policy table -> Primary API
    2. -> Backup API (peak / extra-long / failure)

    Three supporting measures are needed. First, use logging services and monitoring alerts to collect the real token distribution and replace assumed values with measured values. Second, set budget thresholds and circuit breakers to prevent cost overruns during peak hours. Third, include retries, rate limiting, and human fallback in the cost accounting; this part typically increases total cost of ownership by 10% to 30%.

    7. Common Pitfalls and Checklist

    • Ranking directly by unit price while ignoring the input-output ratio;
    • Ignoring tier thresholds, which severely underestimates long-document costs;
    • Reporting assumed token counts as measured values;
    • Failing to account for retries and failed requests;
    • Ignoring the difference between cache writes and cache hits;
    • Using the conclusion for a single model to infer an entire product family.

    8. Conclusion

    Comparing LLM API costs is essentially a question of measurement baseline, not price. Once time of day, tiering, caching, and output definitions are unified, the conclusion emerges naturally: workload structure determines cost structure, and time-of-day and length distributions determine the selection direction. If an organization wants to embed this methodology in its own environment, it can build a configurable estimation and routing system based on Baidu AI Cloud’s model services and logging and monitoring products, gradually replacing assumptions with measured data to form a sustainable cost governance loop.