Evaluating LLM API Cost Efficiency: A Practical Guide

    This guide explains why the lowest per-token price does not always deliver the best cost efficiency for LLM APIs. It breaks down the three billing components—regular input, cache-hit input, and output—and shows how workload shape determines which price dominates. You will learn a vendor-neutral three-tier model selection framework, a routing and fallback pattern, a cost estimation method for different workloads, a nine-item optimization checklist, and the observability metrics needed for continuous tuning. The article also highlights common pitfalls, such as ignoring output amplification or assuming cache hits are automatic.

    1. Why the Lowest Unit Price Is Not the Best Cost Efficiency

    When evaluating LLM API cost efficiency, the most common mistake is comparing only the price per million input tokens. A real bill has three components: regular input, cache-hit input, and output. Their unit prices often differ by several times, and the output price is typically several times the regular input price (commonly in the 4–6x range in the industry).

    This means that for a workload with short input and long output—such as long-form generation, code completion, or structured extraction—cost is almost entirely determined by the output price. For a workload with very long input and short output—such as long-document summarization or retrieval-augmented Q&A—cost is determined by both the input price and the cache hit rate.

    Cost efficiency therefore cannot be judged by the listed price alone. It should be measured by the cost per unit of business output:

    1. Cost per request = input tokens × input price
    2. + cache-hit tokens × cache price
    3. + output tokens × output price
    4. Cost per unit output = cost per request / effective output (e.g., per 1,000 words or per structured result)

    2. Technical Meaning of the Three Billing Components

    1. Regular input: Prompts, retrieved snippets, and user questions that are not reused, billed at the full price.
    2. Cache-hit input: When a request prefix closely matches recent requests, the platform can reuse previously computed intermediate results, usually billed at around 1/10 of the input price. It rewards the engineering habit of “stable prefix + high-concurrency similar requests.”
    3. Output: Generated content billed per token, with the highest unit price. Controlling output length and avoiding ineffective elaboration is the first lever for cost reduction.

    Note that cache hits do not apply automatically everywhere. They depend on an exact prefix match, request timing, and platform policies. In practice, put the invariant parts (system instructions, tool definitions, knowledge base snippets) at the very front of the prompt and the variable parts (user input) at the end.

    3. A General Framework for Tiered Model Selection

    The capability–cost spectrum can be abstracted into three tiers without binding to any specific product:

    • Flagship tier: For complex reasoning, long-chain planning, and professional writing; highest unit price.
    • Balanced tier: A compromise between capability and cost, suitable for most business requests.
    • Lightweight tier: For high-concurrency, low-complexity tasks such as classification, rewriting, extraction, and routing.

    The recommended approach is “routing + fallback”: handle requests with the lightweight tier first, then escalate difficult samples that hit low confidence or rule-based triggers to the balanced or flagship tier.

    1. def route(prompt, features):
    2. if features["est_output_tokens"] < 200 and features["complexity"] == "low":
    3. return "light_tier"
    4. if features["need_long_reasoning"]:
    5. return "flagship_tier"
    6. return "balanced_tier"

    4. Cost Estimation: Calculate the Bill in Advance

    Assume the input/output unit prices of the three tiers follow a 1 : 2 : 5 magnitude relationship (illustrative only; actual prices follow the selected platform’s published pricing). Compare two typical workloads:

    • Workload A (long input, short output): 8,000 input tokens, 300 output tokens, 60% cache hit rate.
    • Workload B (short input, long output): 500 input tokens, 2,000 output tokens, 0% cache hit rate.

    The pattern is stable: Workload A is sensitive to the input price and cache capability, while Workload B is sensitive to the output price. Therefore, long-form generation should prioritize a tier with a low output price, while knowledge base Q&A should prioritize a tier with a mature caching mechanism and a low input price.

    5. Nine Optimization Actions You Can Apply Immediately

    1. Stabilize the prefix: Fix system prompts, tool schemas, and examples to improve cache hits.
    2. Constrain output: Use format constraints and length limits to compress redundant output.
    3. Semantic caching: Cache results for high-frequency similar questions and return directly on a hit.
    4. Batching and async: Run offline tasks off-peak and use queues to smooth traffic.
    5. Context trimming: Rerank retrieved snippets and keep only Top-K, removing duplicates and noise.
    6. Small model first: Perform intent recognition and parameter extraction first to reduce large model calls.
    7. Streaming responses: Improve experience and make it easier to terminate low-quality generation early.
    8. Observability: Log usage of the three token types, hit rate, and retry rate.
    9. Budget guardrails: Set quotas and alerts per business line, with automatic fallback on abnormal usage.

    6. Observability and Continuous Tuning

    Build a minimal cost dashboard with fields including request volume, distribution of input/cache/output tokens, cache hit rate, average output length, cost per unit output, and number of fallback triggers. Conduct a weekly “price–usage” review on two dimensions: the price dimension decides whether to switch tiers, and the usage dimension decides whether prompts and retrieval strategies need changes. If you use Baidu AI Cloud capabilities, you can combine its monitoring and alerting, log service, and object storage to build this dashboard and attribute cost to business lines.

    7. Common Pitfalls

    • Looking only at the input price and ignoring the output amplification effect.
    • Assuming cache hits are guaranteed without prefix governance.
    • Running all traffic on the flagship tier with no fallback path.
    • Setting no output limit, allowing long-tail requests to consume the budget.
    • Lacking retry and timeout strategies, so failed retries create double billing.

    8. Conclusion

    During price increase cycles, control over cost efficiency lies on the engineering side rather than the procurement side. By formalizing the cost formula, classifying workloads, and making routing and caching solid, you can reduce the cost per unit output to a reasonable range without degrading capability. Start with a two-week baseline measurement, then gradually roll out tier switching, and complete model selection with data rather than intuition.