Evaluating LLM API Costs: Token Efficiency as the Core Metric

    This article explains why listed API prices alone do not reflect real LLM costs, breaks down the key billing factors (input, cached input, output, and time-of-day pricing), and provides a practical script to estimate per-task expenses. It also compares pay-as-you-go versus subscription plans, offers cost-control strategies for long-running agent tasks, and outlines actionable steps for building a reliable cost baseline before selecting a model.

    Why Sticker Prices Don’t Tell the Whole Story

    Most teams start by comparing the price per million tokens when shortlisting models. This approach assumes that two models consume the same number of tokens for the same task — but in practice, that assumption rarely holds. Reasoning style, the verbosity of tool calls, and how context is organized all affect total token consumption. For a code-modification task, one model might read a dozen irrelevant files while another locates only the two key code sections. The resulting bill could differ by several times.

    Therefore, LLM cost evaluation should be split into two questions: what is the price per token, and how many tokens does a task actually consume? Multiplying these two figures gives the real cost per task.

    Four Key Items in the Billing Structure

    1. Regular Input vs. Cached Input

    LLM services typically divide input tokens into two categories. Regular input is billed at the standard rate. Cached input refers to prefix content that the server has already computed and reuses within a validity period; it is usually priced noticeably lower than regular input.

    For multi-turn conversations and agent-based applications, every request carries a large amount of identical system prompts, tool definitions, and historical context. The higher the cache hit rate for this content, the lower the effective input cost. Therefore, cache hit rate deserves more attention than the unit price alone.

    Note that some services may assign different rates to cached input, and in certain time windows the cached rate can be higher than expected. Always refer to the official price sheet rather than making assumptions.

    2. Output Token Pricing

    Output tokens generally cost more per unit than input tokens. For tasks that generate large code blocks, long documents, or detailed reasoning traces, output cost can dominate the total bill. If the task includes a “thinking” phase or lengthy intermediate reasoning, that consumption also counts as output.

    3. Peak vs. Off-Peak Pricing

    Some services vary prices by time of day. Unit prices during business peaks may be higher than during off-peak hours. For batch tasks that can run on a flexible schedule, choosing off-peak hours directly reduces cost. For interactive scenarios, peak pricing is unavoidable; evaluate with peak rates to avoid underestimating your budget.

    4. Token Efficiency

    Token efficiency refers to the number of tokens consumed to achieve a result of equivalent quality. It is not determined by unit price, but rather by the model’s behavioral patterns, prompt design, and the toolchain. A more efficient model can complete a task with fewer reads, writes, and reasoning rounds. Even if its unit price is slightly higher, the total cost may be lower.

    Comparing Pay-as-You-Go vs. Subscription Plans

    Subscription plans attract users with a fixed monthly fee. But whether they are worthwhile depends on how much of the included quota you actually use and how the quota translates to pay-as-you-go rates.

    Follow these steps to compare:

    1. Confirm the plan’s monthly fee, included quota, and how that quota is measured.
    2. Convert the quota into an equivalent pay-as-you-go monetary value. For example, if the quota is based on request counts, first estimate the average token consumption per request, then multiply by the pay-as-you-go unit price.
    3. Calculate the break-even point: divide the monthly fee by the per-task cost under pay-as-you-go pricing. This tells you how many tasks per month you need to complete.
    4. Compare your historical workload data against the break-even point.

    If your actual usage is far below the quota, pay-as-you-go is usually cheaper. If usage consistently approaches or exceeds the quota, the subscription may be advantageous. Keep in mind that discounts often apply only when the quota is fully used; when underused, the effective unit price rises significantly.

    Estimating Per-Task Cost with a Script

    The example below combines the four billing factors into a single cost function. Price fields must be filled in according to each service’s official price list; the example contains no real values.

    1. def estimate_task_cost(
    2. input_tokens: int,
    3. cached_tokens: int,
    4. output_tokens: int,
    5. price: dict,
    6. ) -> float:
    7. """
    8. Estimate the cost of a single task.
    9. price is in "currency per million tokens"; fill in from the official price sheet.
    10. Example price structure:
    11. {"input": regular input rate, "cached_input": cached input rate, "output": output rate}
    12. """
    13. if cached_tokens > input_tokens:
    14. raise ValueError("Cached tokens cannot exceed total input tokens")
    15. uncached_tokens = input_tokens - cached_tokens
    16. cost = (
    17. uncached_tokens * price["input"]
    18. + cached_tokens * price["cached_input"]
    19. + output_tokens * price["output"]
    20. ) / 1_000_000
    21. return cost
    22. def breakeven_tasks(plan_monthly_fee: float, cost_per_task: float) -> float:
    23. """Calculate the break-even number of tasks for a subscription plan."""
    24. if cost_per_task <= 0:
    25. raise ValueError("Cost per task must be greater than 0")
    26. return plan_monthly_fee / cost_per_task

    To use this, collect real token counts — input, cache hits, and output — from your logs, take averages over multiple tasks, and plug those values into different models’ price parameters. The resulting comparison is far more reliable than comparing unit prices alone.

    Cost Control in Long-Running Tasks

    Agent-based applications often require multiple rounds of tool calls, and context grows with each round. Cost control in such scenarios should focus on the following points.

    Control context bloat. Sending the full history every round causes input tokens to accumulate quickly. Truncate tool results to keep only fragments relevant to the current step, and periodically summarize historical context.

    Increase cache hit rate. Put static system prompts and tool definitions at the beginning of each request, and dynamic content later. This helps the server hit prefix caches. Modifying the header portion of a prompt invalidates the cache, so avoid frequent changes.

    Limit irrelevant reads. In file retrieval or code search tasks, use precise paths, keywords, or symbol references instead of reading entire directories. Tightening the search scope usually reduces cost more effectively than switching models.

    Set budget caps. Define a maximum number of rounds and a maximum token budget per task. When thresholds are exceeded, pause the task and return intermediate output, letting a human decide whether to continue.

    Practical Recommendations

    First, establish a baseline. Before selecting a model, run two or three candidate options on typical tasks from your business. Record token distribution and task quality for each.

    Second, evaluate quality and cost together. Looking only at cost may pick a solution that fails quality requirements; looking only at quality may cause cost to spiral. Define clear acceptance criteria for tasks — for example, code passes tests, or documentation covers key points.

    Third, review bills periodically. Model prices, cache policies, and plan terms can change. At least once per quarter, compare actual usage against billing details to confirm that your selection remains valid.

    Fourth, preserve switching capability. In the application layer, abstract model calls behind a unified interface so that changing providers or models only requires configuration updates, not business-logic changes.

    On platforms such as Baidu AI Cloud, you can enable usage and billing detail queries, and set up monitoring alerts with usage thresholds. These capabilities help teams detect abnormal consumption early and prevent costs from rising unnoticed.

    In summary, evaluating LLM costs requires considering unit price, caching, billing time windows, and task-level token consumption. Using the real per-task cost as the comparison baseline leads to more reliable model selection.