LLM API Cost Accounting and Plan Selection: A Practical Guide

    This guide explains how to calculate the true cost of large language model API calls and choose the right pricing plan. It covers unified token accounting, cache hit rate definitions, cost crossover analysis between pricing structures, time-based pricing, plan utilization thresholds, and per-task cost metrics, ending with an actionable cost observability workflow.

    1. Why the Lowest Unit Price Does Not Mean the Lowest Cost

    When evaluating LLM API costs, the most common mistake is comparing only the most prominent number on a pricing page, such as the unit price for cached input. A real request usually involves multiple billable components: cached input tokens, uncached input tokens, and output tokens. The final bill is determined jointly by the unit price and volume of each category.

    For scenarios like AI-assisted coding, knowledge Q&A, and long-document processing, request structures vary significantly. Some tasks repeatedly carry the same background material and have high cache reuse potential; others frequently change context or require long outputs. Even with the same total token count, costs can differ substantially.

    Cost accounting should therefore answer three questions:

    1. What components make up actual consumption, and what is each one’s share?
    2. What time periods and billing categories do discounts apply to, and are there usage restrictions?
    3. How many acceptable task results does the spending ultimately produce?

    Only by addressing all three can you move from “comparing unit prices” to “comparing real usage costs.”

    2. Unify Measurement Conventions Before Discussing Cache Hit Rates

    2.1 Distinguish Three Basic Consumption Types

    In the simplest billing model, token consumption can be divided into:

    • Cached input tokens, denoted H;
    • Uncached input tokens, denoted U;
    • Output tokens, denoted O.

    The corresponding unit prices are Ph, Pu, and Po, all in “currency per million tokens.”

    The base call cost is:

    C = (H × Ph + U × Pu + O × Po) ÷ 1,000,000

    This formula holds only if all billing items genuinely fall into these three categories. If the service also charges for cache writes, cache storage, additional processing, or other items, those must be added according to the actual rules rather than forced into the simplified model.

    2.2 Two “Cache Rates” Must Not Be Mixed

    In practice, “cache hit rate” often has two definitions.

    The first is the input token cache hit rate:

    r = H ÷ (H + U)

    It describes what fraction of all input tokens is billed as cached.

    The second is the share of cached tokens among all tokens:

    h = H ÷ (H + U + O)

    This includes output tokens in the denominator. It better describes the overall billing structure, but strictly speaking should not be called the input cache hit rate.

    For example, suppose in a batch of requests cached input accounts for 98% of all tokens, uncached input for 1.5%, and output for 0.5%. The input cache hit rate is not 98%, but:

    98% ÷ (98% + 1.5%) ≈ 98.49%

    The two numbers look close here, but the gap widens as the output share grows. When building cost reports, define each field clearly and avoid direct comparisons across different conventions.

    In addition, request-level hit rates cannot substitute for token-level hit rates. A short request hitting the cache and a very long request hitting the cache have completely different billing impacts.

    3. Build a Cost Model That Explains Price Reversals

    3.1 Express Cost via Input Hit Rate and Output Share

    Let total token volume be T, the output share of all tokens be q, and the input cache hit rate be r. Then:

    H = T × (1 − q) × r

    U = T × (1 − q) × (1 − r)

    O = T × q

    Substituting into the base formula:

    C = T ÷ 1,000,000 × { (1 − q) × [ r × Ph + (1 − r) × Pu ] + q × Po }

    This model shows that cost depends not only on the cached price, but also on the cache rate, the regular input price, and the output price.

    When the cache hit rate drops, more input shifts from the low-price category into the regular input category. If two pricing structures differ greatly in regular input price, the structure with the cheaper cached price may end up more expensive.

    3.2 Illustrating the Reversal with Hypothetical Data

    The following numbers are for demonstration only and do not correspond to any actual pricing.

    Assume two pricing structures:

    Billing category Structure A Structure B
    Cached input 0.10 CNY / million tokens 0.05 CNY / million tokens
    Uncached input 1.00 CNY / million tokens 3.00 CNY / million tokens
    Output 4.00 CNY / million tokens 4.00 CNY / million tokens

    With a total volume of 100 million tokens, where cached input, uncached input, and output account for 98%, 1.5%, and 0.5% of all tokens respectively:

    Structure A costs:

    98 × 0.10 + 1.5 × 1.00 + 0.5 × 4.00 = 13.30 CNY

    Structure B costs:

    98 × 0.05 + 1.5 × 3.00 + 0.5 × 4.00 = 11.40 CNY

    Now keep the output share at 0.5%, but let the cached input share drop to 95%, so uncached input rises to 4.5%.

    Structure A costs:

    95 × 0.10 + 4.5 × 1.00 + 0.5 × 4.00 = 16.00 CNY

    Structure B costs:

    95 × 0.05 + 4.5 × 3.00 + 0.5 × 4.00 = 20.25 CNY

    A lower cached unit price does not mean lower cost under every request structure.

    3.3 Find the Cost Crossover Point, Not Just Two Samples

    With a fixed output share, the cost of each pricing structure varies linearly with the input cache hit rate. Setting the two costs equal yields the crossover point.

    In practice, compare the observed hit rate distribution against the crossover:

    • If most traffic falls on one side, the choice is usually clear;
    • If traffic frequently crosses the point, compute separately by business type;
    • If the hit rate fluctuates widely, calculate optimistic, normal, and conservative budgets.

    This is more reliable than projecting annual costs from a single idealized hit rate.

    4. Time-Based Pricing Must Be Weighted by Actual Usage

    Some billing or plan rules distinguish peak and off-peak periods. You cannot assume all traffic enjoys off-peak prices just because they exist.

    The correct calculation is:

    Total period cost = sum of fees for actual billed volume in each time period

    With multiple pricing windows, separately track cached input, uncached input, and output for each window.

    Pay special attention to:

    Time zones and boundaries. The same time description may correspond to entirely different working hours in different time zones. How requests crossing a billing boundary are classified should follow the actual rules and invoices.

    Business usage does not equal clock time. A period that occupies only a small part of the day may still carry most of a team’s requests. Do not derive cost shares directly from hour shares.

    Whether tasks can be shifted. Batch summarization, offline evaluation, and non-urgent document processing can be scheduled off-peak; interactive development and online Q&A usually cannot be delayed arbitrarily just to save money.

    Experience constraints in low-price windows. Even at lower prices, verify that concurrency, queuing, and completion times still meet business needs.

    The core of time-based optimization is rearranging load without breaking task timeliness, not simply chasing the lowest-priced window.

    5. Plan Evaluation Should Move from “Nominal Quota” to “Actual Usable Value”

    5.1 First Confirm What the Quota Actually Represents

    Plans may limit usage by request count, time window, call intensity, or other means. Only when the unit of measurement, applicable scope, and conversion rules are explicit does it make sense to convert the quota into token value.

    If the quota conversion assumes a particular cache rate and output ratio, then “how many tokens you can use” is merely an estimate under specific assumptions, not an unconditional allowance.

    Before comparing plans, confirm at least:

    • The quota’s accounting period and reset time;
    • Whether peak and off-peak consumption rules differ;
    • Whether concurrency or rate limits exist;
    • Whether the required call methods are covered;
    • Whether unused quota rolls over;
    • What happens after exceeding the quota: service stops or extra charges apply.

    5.2 Align Monthly and Weekly Accounting Periods

    When quota is granted weekly but fees are charged monthly, do not simply treat every month as four weeks.

    For long-term budgeting you can use:

    Average weeks per month ≈ 52 ÷ 12 ≈ 4.33

    But this is only an average. The quota actually available in a specific billing period depends on how quota resets align with the subscription cycle. The two cycles are not inherently aligned, and averages alone cannot guarantee actual entitlement.

    5.3 Use Utilization to Judge Whether a Plan Is Worth Buying

    Let the plan price be P, the pay-as-you-go value of its full quota under your actual task structure be V, and the actual utilization be u.

    Assuming proportional approximation, the plan is worthwhile only if:

    u × V > P

    So the break-even utilization is:

    u > P ÷ V

    For example, suppose a purely hypothetical plan costs 120 CNY, and its full quota corresponds to 200 CNY of pay-as-you-go usage under your current task structure. Utilization must exceed 60% for the plan to show a price advantage.

    If utilization is only 40%, the actual pay-as-you-go equivalent obtained is about 80 CNY. Even if the nominal discount looks attractive, it may not beat direct pay-as-you-go usage.

    This calculation also assumes the quota can be effectively consumed. If quota concentrates in unsuitable time windows or conflicts with task requirements, the usable value should be further discounted.

    6. Ultimately, Compare the Cost per Valid Task

    Token prices are the foundation of financial accounting, but not the endpoint of business efficiency.

    A task may involve initial generation, automated checks, error fixing, and human confirmation. Counting only the first call usually underestimates the full cost.

    A more business-meaningful metric is:

    Average cost per valid task = total workflow cost ÷ number of tasks passing acceptance

    Total workflow cost can be layered by management goals:

    • Model call fees;
    • Auxiliary resource fees for retrieval, storage, and compute;
    • Automated testing and validation fees;
    • Retry and re-execution costs;
    • Human review costs where necessary.

    For example, two options may differ in per-call price, but the cheaper option may require more repair rounds, so the final cost per accepted result may not be lower. Conversely, you cannot assume more expensive calls are necessarily more effective; this must be verified with the same task set and acceptance criteria.

    Evaluation should therefore record success rate, retry counts, completion latency, and cost together, rather than optimizing a single metric.

    7. Build an Actionable Cost Observability and Optimization Process

    7.1 Collect Request-Level Metering Data

    Record at least: request time, business type, task identifier, cached input tokens, uncached input tokens, output tokens, pricing version, cost, latency, and acceptance result.

    Task identifiers link multiple calls within the same workflow; pricing versions handle price changes; business types help identify where cost differences originate.

    If the API does not return sufficient metering fields, fill gaps with invoice details or other verifiable data. For data that cannot be observed, mark it as unknown or estimated rather than defaulting to cache hits.

    Cost logs generally do not need full prompt content. Prefer anonymized identifiers, digests, or length statistics to reduce sensitive data exposure.

    7.2 Build Baselines by Task Category

    Observe at least interactive Q&A, long-document processing, AI-assisted coding, and batch tasks separately.

    For each category, track input cache hit rate, output share, average cost per task, and failure retries. Overall averages reflect only the macro budget and cannot replace per-business diagnosis.

    For instance, a drop in cache rate may come from a change in context organization, or simply from adding a new low-reuse task type. These require entirely different responses.

    7.3 Optimize Caching While Keeping Content Boundaries Stable

    Where the service supports the corresponding caching mechanism, keep stable instructions and shared context unchanged, and reasonably separate dynamic content from stable content to reduce pointless rewriting.

    However, whether a cache hits still depends on actual matching rules, TTL, and context structure. Repeatedly sending the same content does not guarantee a discount.

    Nor should you pad prompts with irrelevant content just to raise the cache rate. Even at a low unit price, extra input can still increase cost, processing time, and context interference.

    7.4 Constrain Abnormal Consumption with Budget Thresholds

    Budget alerts can be set around:

    • Daily cost significantly above the recent baseline;
    • Sustained decline in cache hit rate;
    • Abnormal growth in output length;
    • Excessive retries for the same task;
    • Remaining plan quota insufficient for projected demand.

    Alerts should be paired with executable measures, such as capping per-task consumption, terminating repeatedly failing workflows, deferring non-urgent batch jobs, or requiring approval for high-cost tasks.

    8. Conclusion: Reproducible and Observable Accounting Is What Actually Controls Cost

    LLM cost management should not stop at comparing price tables, nor should it rest on idealized cache hit rates.

    A more reliable path is: first unify token measurement conventions, then compute costs based on actual input/output structure; next incorporate time-based pricing, plan restrictions, and quota utilization; and finally measure real output by the number of tasks passing acceptance.

    When this data can be continuously recorded and recomputed, cost optimization stops relying on intuition and becomes a verifiable, explainable, and iterable engineering process.