LLM API Cost Accounting: Pay-as-You-Go, Batch Processing, or Subscription?

    This article explains how to estimate the real cost of LLM API usage. It covers the billing components of token-based pricing, compares pay-as-you-go, batch, and subscription credit plans, shows how to calculate effective discounts, provides a Python cost estimation example, and lists the monitoring practices and risks to check before choosing a provider.

    1. Why Unit Price Alone Is Not Enough

    When choosing an LLM API, many teams start by comparing the price per million tokens. That comparison is useful but incomplete. The unit price tells you what one token costs. The final bill also depends on three other factors: how many tokens each request consumes, which tokens qualify for discounts, and whether those discounts last.

    The same model can differ across platforms in four common ways:

    1. Same list price, different discounts: Several platforms charge the same base price, but some offer time-limited discounts and others offer batch discounts.
    2. Same billing unit, different metering rules: Some platforms count reasoning tokens as output. Others bill cache storage separately.
    3. Different currencies and exchange rates: For platforms priced in US dollars, the cost in CNY changes with the exchange rate.
    4. Subscription versus pay-as-you-go: Subscription plans usually deduct credits or quotas. The actual price paid must be converted before it can be compared with pay-as-you-go pricing.

    Cost accounting should therefore use the actual spend per task as its unit, not the unit price. The rest of this article follows that approach.

    2. Understanding the Billable Items

    Most LLM API bills consist of the following token types.

    • Uncached input tokens: New content sent to the model in a request, including the system prompt, conversation history, and the user’s question.
    • Cache-hit tokens: The part of a request that matches a previous request prefix and is reused by the server. These usually cost much less than regular input tokens.
    • Output tokens: The content generated by the model. They usually cost significantly more than input tokens, so they deserve the most attention in the bill.
    • Cache storage fees: Some platforms charge separately for how long a cache is stored. Others store it free of charge for a limited period.

    One detail is easy to overlook. The reasoning process of reasoning models is often counted as output tokens. The answer a user sees may be only a few hundred words, while the model may generate several times that amount internally. If you estimate costs based only on the length of the final answer, the budget will be noticeably too low.

    During planning, you can estimate output volume with a simple rule of thumb:

    Actual output tokens ≈ Final answer tokens × (1 + reasoning ratio)

    The reasoning ratio depends on task difficulty and model settings, and no universal value exists. Start by sampling real requests for one week. Calculate the average from your usage logs, then replace the estimate with that value.

    3. Three Common Billing Models

    3.1 Pay-as-You-Go

    The pay-as-you-go formula is the most straightforward:

    Monthly cost = Input tokens × Input price + Cached tokens × Cache price + Output tokens × Output price

    Its main advantage is flexibility. It has no minimum spend, which makes it suitable for workloads with volatile usage or for products still in validation. The main risk is time-limited discounts. If a discount page does not state an expiration date, the team cannot assume the discount will last. A sound approach includes the following:

    • Keep two columns in the budget sheet, one for the discounted price and one for the list price.
    • Set a threshold that triggers an alert automatically when a discount expires.
    • Wrap model calls in a unified gateway or configuration layer, so that switching providers only requires a configuration change.

    3.2 Offline Batch Processing

    Batch interfaces typically accept a set of tasks, process them asynchronously within a time window, and bill them at a lower unit price. This model suits latency-tolerant workloads such as data cleaning, text classification, bulk labeling, offline summarization, and index building.

    Two points need attention when using batch processing. First, the return time is not fixed, so your workflow must support asynchronous callbacks or polling. Second, retries bill again. Validate data before submitting a task, and isolate individual failures instead of rerunning the entire batch.

    3.3 Subscription with Credits

    A subscription plan typically requires a one-time payment in exchange for a set quota. The quota is expressed in credits or an equivalent amount, and each call deducts credits based on the model’s price. The key task with this model is calculating the effective discount.

    The effective discount is calculated as follows:

    Effective discount = Amount paid for the plan ÷ Equivalent list-price value of the usage the plan provides

    For example, if a plan costs 1,000 CNY and provides usage worth 2,500 CNY at list price, the effective discount is 0.4, or 40% of list price. Some plans also apply deduction coefficients by time of day, deducting less during off-peak hours and more during peak hours. Use the rules published by the platform for this conversion, and verify the result with one real call.

    Subscriptions suit two kinds of teams. The first has stable, predictable monthly usage. The second switches frequently between models and wants to manage quotas in one place. If usage fluctuates widely, quota goes unused during low periods, and the actual discount ends up below the advertised figure.

    4. Implementing Cost Accounting in Code

    The example below turns the formulas above into a function. The prices are hypothetical values for demonstration and do not represent any platform’s actual pricing.

    1. def estimate_cost(
    2. input_tokens: int,
    3. cached_tokens: int,
    4. answer_tokens: int,
    5. reasoning_ratio: float,
    6. price_in: float, # CNY per million tokens, uncached input
    7. price_cache: float, # CNY per million tokens, cache hit
    8. price_out: float, # CNY per million tokens, output
    9. discount: float = 1.0 # Discount factor, 0.5 means 50% off
    10. ) -> float:
    11. """Estimate the cost (in CNY) of a single task or a monthly workload."""
    12. fresh_input = input_tokens - cached_tokens
    13. output_tokens = answer_tokens * (1 + reasoning_ratio)
    14. cost = (
    15. fresh_input * price_in
    16. + cached_tokens * price_cache
    17. + output_tokens * price_out
    18. ) / 1_000_000
    19. return cost * discount
    20. # Assumed scenario: 10 million input tokens per month, of which 6 million hit the cache.
    21. # The final answers total 2 million tokens, and the reasoning ratio is 2.
    22. monthly = estimate_cost(
    23. input_tokens=10_000_000,
    24. cached_tokens=6_000_000,
    25. answer_tokens=2_000_000,
    26. reasoning_ratio=2.0,
    27. price_in=1.0,
    28. price_cache=0.3,
    29. price_out=4.0,
    30. discount=0.5,
    31. )
    32. print(f"Discounted monthly cost: {monthly:.2f} CNY") # Output: Discounted monthly cost: 14.90 CNY

    Under these assumptions, the cost before discount is 29.8 CNY. Of that, 24 CNY comes from output, which is more than 80%. In reasoning-heavy workloads, controlling output length and reasoning depth saves more money than lowering the input price.

    Three optimization directions are common:

    • Raise the cache hit rate: Place fixed system prompts and knowledge snippets at the start of each request, and keep the prefix stable.
    • Limit output length: Specify the answer format and length in the prompt, and use constrained output for structured tasks.
    • Choose a model tier by task: Simple classification and extraction tasks rarely need the strongest model.

    5. Choosing a Plan for Five Typical Scenarios

    Scenario 1: A low-traffic internal tool. Monthly usage is small and fluctuates noticeably. Pay-as-you-go fits best because it requires no quota commitment and allows switching models at any time.

    Scenario 2: A high-concurrency, stable online service. Call volume is predictable and cost-sensitive. Compare the effective discount of subscription plans with the actual pay-as-you-go bill, and consider keeping some pay-as-you-go quota as a buffer for spikes.

    Scenario 3: Offline batch workloads. Tasks such as data cleaning and bulk labeling tolerate latency, so prioritize batch interfaces. Schedule offline tasks separately from online requests so that batch jobs do not consume the online quota.

    Scenario 4: Long-context applications with repeated prefixes. Examples include document Q&A and code repository search. The cache hit rate directly determines cost for these applications, so plan the prefix reuse strategy during architecture design.

    Scenario 5: Reasoning-intensive tasks with long outputs. Examples include complex reasoning and long-form generation. Output accounts for a large share of cost. Set a separate output budget and estimate the reasoning ratio through sampling.

    6. How Model Tiers Relate to Pricing

    Within the same vendor, unit prices across tiers can differ several times over. A lightweight tier and a flagship tier may differ in parameter scale, reasoning capability, and service level. When selecting a model, do not ask only which one is cheapest. Ask what minimum capability the task requires.

    A practical approach is to build an evaluation set. Select 20 to 30 representative tasks, run them on different tiers, and record accuracy, latency, and cost per call. Then plot the trade-off between cost and quality. Many workloads find that a mid-tier model handles most requests well, and only a small share of difficult requests need the flagship model. This tiered routing can reduce total cost significantly with little loss in quality.

    7. Risks to Watch For

    1. Discount expiration: If a time-limited price has no clear end date, budget at list price.
    2. Currency and exchange rates: For platforms that bill in foreign currency, the CNY cost changes with exchange rates. Long-term projects should leave room in the budget for exchange rate fluctuations.
    3. Extra aggregation or gateway fees: When calls go through a third-party aggregator or gateway, service fees or markups may apply. Include these in the total cost.
    4. Price changes: Model prices may change with new versions. Check the official pricing pages regularly and keep a record of historical prices.
    5. Compliance and cross-border data transfer: Some businesses cannot send data across borders. Before choosing a platform, confirm the data storage and processing location requirements.

    8. Making Costs a Monitored Metric

    The key to cost management is observability. Log the input tokens, cache-hit tokens, output tokens, model name, and business tag for every call at the application layer, and write these records to a logging service or data warehouse.

    With this data, you can set up the following monitoring items:

    • Cost curves by business line, model, and day.
    • Average cost per task and its percentiles, which help identify unusually long requests.
    • Trends in the cache hit rate.
    • Budget consumption progress, with an alert at 80%.

    When doing cost accounting on platforms such as Baidu AI Cloud, the billing details in the console remain the source of truth. Reconciling the billing details with your own logs helps you detect differences in how usage is metered.

    9. Conclusion and Checklist

    LLM API cost accounting comes down to converting unit prices into the actual cost of each task. To put this into practice, follow these steps:

    • Sample real requests and measure input, cached, and output tokens, along with the reasoning ratio.
    • Calculate the monthly cost of pay-as-you-go, batch, and subscription options using the formulas above.
    • Confirm discount expiration dates, and prepare a backup budget at list price.
    • Assign model tiers by task difficulty, and validate quality with an evaluation set.
    • Deploy cost monitoring and budget alerts, and review them once a month.

    When billable items are clearly separated and discount expiration is factored into the budget, costs can stay predictable without sacrificing output quality.