How to Evaluate LLM API Pricing: From Token Rates to Effective Cost

    A practical framework for comparing large language model APIs beyond headline token prices. Learn how to calculate per-call and effective costs, assess latency and reliability, measure task success rates, build reproducible evaluations, and choose models based on business priorities.

    1. Unit Price Is Not Total Cost

    Large language model APIs are typically priced per million tokens. Although pricing tables are easy to find, they describe only one aspect of the overall cost.

    The total cost of a real-world task usually includes three components:

    • Direct API charges
    • Rework costs caused by inadequate output quality
    • Waiting costs caused by slow responses

    Comparing token prices alone can therefore lead to misleading conclusions.

    For example, one model may have a lower price but achieve only a 60% first-pass success rate on complex code-generation tasks. Developers may need to retry requests and manually correct the results. A more expensive model with a higher first-pass success rate may have a lower overall cost. The evaluation target should therefore be the cost of producing one valid result, not simply the cost of one API call.

    2. Break Down the Pricing Structure

    Most model services use a pricing structure that includes some or all of the following components:

    • Input tokens: User prompts, system instructions, conversation history, and retrieved context.
    • Output tokens: Content generated by the model. Output tokens are often priced higher than input tokens.
    • Caching-related charges: Reused prompt prefixes may qualify for separate discounts or pricing rules. Always refer to the provider’s official documentation.
    • Service tiers: Some providers offer different priority or speed tiers with different prices.

    Two points deserve particular attention.

    First, output tokens are often the primary cost driver, especially when generating long documents or large code blocks. Second, a larger context window allows more input in a single request, but it also increases the input cost of each call. Application designs should remove irrelevant context instead of sending the entire conversation history or document without filtering.

    3. Evaluate Performance Across Multiple Metrics

    Performance should not be reduced to a single measure of “speed.” A useful evaluation separates it into four metrics:

    1. Time to first token: The time from sending a request to receiving the first output token. This strongly affects perceived responsiveness in interactive applications.
    2. Output throughput: The number of tokens generated per second. This determines the total generation time for long outputs.
    3. Context window: The maximum number of tokens supported in one request. This determines whether the model can process long documents or large codebases in a single call.
    4. Reliability: Timeout rates, rate-limit frequency, and error-code distribution. These factors determine production availability.

    The importance of each metric depends on the use case. Chat assistants typically prioritize time to first token. Batch document processing places more weight on throughput and cost. Code review tasks often depend more heavily on context capacity and output quality.

    4. Quality and Effective Cost

    Quality can have a greater impact on final cost than the listed token price. A useful approach is to define a measurable task success rate: the percentage of model outputs judged usable after automated validation or human review.

    Effective cost can be estimated as follows:

    1. Effective cost = Cost per call ÷ Task success rate

    This formula assumes that every failed attempt results in another call and that failed and successful calls have the same cost. In practice, a failed result may require only a partial correction, making the actual cost lower than this estimate. If a failure requires substantial human intervention, labor costs should be added separately.

    The value of this formula is that it provides a consistent basis for comparing different models.

    5. Build a Reproducible Evaluation Process

    A practical evaluation process can follow these steps:

    1. Extract representative samples from real business workloads. Include simple, medium, and difficult tasks, with at least 100 samples recommended.
    2. Define clear success criteria for every sample. Use automated checks whenever possible, such as validating JSON structure or running unit tests.
    3. Keep the prompt template, sampling parameters, and maximum output length consistent across models.
    4. Record input and output token counts, latency, and evaluation results for every call in structured logs.
    5. Aggregate per-call cost, effective cost, average latency, and success rate, then apply weights based on business priorities.

    Model versions may change, and provider-side behavior can also evolve. Evaluation results should include the test date and model version, and the tests should be repeated regularly.

    6. Example Code

    The following example calculates per-call cost, effective cost, and estimated latency. The prices and performance values are hypothetical and are provided only to demonstrate the calculation method. They do not represent the pricing of any real service.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class ModelProfile:
    4. name: str
    5. input_price_per_m: float # Price per million input tokens
    6. output_price_per_m: float # Price per million output tokens
    7. output_tps: float # Average output speed in tokens/second
    8. success_rate: float # Task success rate, from 0 to 1
    9. first_token_s: float = 0.8 # Average time to first token in seconds
    10. def cost_per_call(p: ModelProfile, input_tokens: int, output_tokens: int) -> float:
    11. return (input_tokens * p.input_price_per_m + output_tokens * p.output_price_per_m) / 1_000_000
    12. def effective_cost(p: ModelProfile, input_tokens: int, output_tokens: int) -> float:
    13. if p.success_rate <= 0:
    14. raise ValueError("success_rate must be greater than 0")
    15. return cost_per_call(p, input_tokens, output_tokens) / p.success_rate
    16. def latency(p: ModelProfile, output_tokens: int) -> float:
    17. return p.first_token_s + output_tokens / p.output_tps
    18. if __name__ == "__main__":
    19. models = [
    20. ModelProfile("Model A", input_price_per_m=2.0, output_price_per_m=8.0,
    21. output_tps=60, success_rate=0.85),
    22. ModelProfile("Model B", input_price_per_m=5.0, output_price_per_m=20.0,
    23. output_tps=120, success_rate=0.95),
    24. ]
    25. inp, out = 3000, 800
    26. for m in models:
    27. print(f"{m.name}: per-call cost {cost_per_call(m, inp, out):.4f}, "
    28. f"effective cost {effective_cost(m, inp, out):.4f}, "
    29. f"estimated latency {latency(m, out):.2f} seconds")

    The results are:

    • Model A: Per-call cost: 0.0124 yuan; effective cost: 0.0146 yuan; estimated latency: 14.13 seconds.
    • Model B: Per-call cost: 0.0310 yuan; effective cost: 0.0326 yuan; estimated latency: 7.47 seconds.

    Based on effective cost, Model B is approximately 2.2 times more expensive than Model A. Based on latency, Model B is roughly twice as fast. Which model is preferable depends on how the application weights cost and responsiveness.

    For batch and offline workloads, cost is usually the priority. In real-time interactive applications, latency typically carries much more weight.

    7. Common Mistakes

    • Looking only at the listed price: Ignoring success rates and retry costs can underestimate the actual expense of a low-priced model.
    • Looking only at peak throughput: Evaluate latency under concurrency and peak load, including percentile metrics such as P95 and P99.
    • Drawing conclusions from a single sample: Results from small samples can vary significantly. Use a batch of representative tasks.
    • Ignoring context growth: As conversations become longer, input token counts continue to increase, and costs can rise rapidly. Use truncation or summarization when appropriate.
    • Ignoring engineering costs: Integration, monitoring, and fallback mechanisms require engineering effort and should be included in the total cost.

    8. Practical Recommendations

    • Select models according to task difficulty. Use lower-cost models for simple tasks and upgrade to more capable models for complex work.
    • Implement fallback and degradation strategies so requests can switch to a backup model during timeouts or rate limiting.
    • Set a maximum output length and instruct the model to answer concisely when appropriate.
    • Reuse frequently repeated prompt prefixes to reduce duplicate input.
    • When using model services through platforms such as Baidu AI Cloud, rely on the pricing information in the relevant official console or documentation and review billing records regularly.