LLM Cost Breakdown: Task-Tiered Model Selection in Practice
This article explains why LLM API costs are difficult to compare directly, identifies four core cost variables, presents a simple cost model with pseudocode, and describes a task-tiered model selection approach supported by usage calibration, quality fallback, and engineering controls.
I. Why LLM Costs Are Hard to Compare Directly
Two calls to a large language model for the same task can produce bills that differ by dozens of times. The reason is that providers do not use a unified billing basis. Looking only at the price per million tokens can easily lead to a one-sided conclusion. Before comparing costs, you need to clarify the billing unit and then break the task down into variables that can be calculated.
II. Four Core Variables That Affect Cost
Input and output prices differ. Most models price output tokens noticeably higher than input tokens. The longer the output, the faster cost grows. Controlling output length is often more effective than compressing input.
Input-to-output ratio. Summarization and classification tasks usually have long input and short output, so cost mainly comes from input. Code generation and long-form writing tasks have a high output share, so cost mainly comes from output. The same model can have very different actual costs across these two task types.
Cache hits. When the prefix of a request matches previous requests, some services offer a lower unit price for the matched input portion. The higher the hit rate, the lower the effective input price. Whether caching is supported and how it is billed should be based on the provider’s currently published rules.
Context length. In multi-turn conversations, historical messages are usually resent with each request, so input tokens accumulate as turns increase. The cost growth of long sessions often exceeds intuition, so history should be periodically trimmed or compressed into summaries.
III. Building a Cost Model
The cost of a single call can be written as:
Cost per call = (new input tokens × input price + cached input tokens × input price × cache discount + output tokens × output price) ÷ 1,000,000
Based on this, you can write a simple estimation function:
Define ModelPrice(name, input_price, output_price, cache_discount)Define CostPerCall(price, input_tokens, output_tokens, cache_hit_ratio):new_input = input_tokens × (1 - cache_hit_ratio)cached_input = input_tokens × cache_hit_ratiocost = new_input × price.input_price+ cached_input × price.input_price × price.cache_discount+ output_tokens × price.output_pricereturn cost ÷ 1,000,000
The following numbers are hypothetical values for demonstration only and do not represent the real prices of any service. Assume a high-tier model’s output price is 80 times that of a lightweight model, each call has 2,000 input tokens and 500 output tokens, and there are no cache hits. The high-tier model costs about 0.06 billing units per call, while the lightweight model costs about 0.0025 billing units, a difference of about 24 times. At 1,000 calls per day, the high-tier model costs about 60 units per day, while the lightweight model costs only about 2.5 units per day. This shows that assigning all tasks to the same model is often both wasteful and unnecessary.
IV. Task-Tiered Model Selection
The core idea of tiered selection is: high-cost models handle judgment, while low-cost models handle repeated execution. This can be divided into four roles.
- Planning and review: task decomposition, solution design, and final result validation. Call frequency is low, but reasoning quality requirements are highest, so a high-tier model is suitable.
- Complex reasoning: multi-step derivation and decisions under complex constraints. Quality requirements are relatively high, but call volume is moderate, so a mid-tier model can be used.
- Main execution: routine code changes, text rewriting, and structured extraction. Call volume is high, and stable quality is sufficient, so a cost-effective lower-mid-tier model is suitable.
- Batch simple tasks: classification, labeling, format conversion, and other work with clear rules. Call volume is highest, so the lightest model is suitable.
The routing logic can be written as:
Define SelectModel(task):If task.needs_planning or task.needs_final_review:Return HighTierModelIf task.complexity == "high":Return MidTierModelIf task.is_batch_simple_task:Return LightweightModelReturn PrimaryModel
Quality evaluation must be established before tiering. If the pass rate for a tier of tasks drops, the system should automatically fall back to the previous tier instead of continuing to push costs down.
V. Calibrating Estimates with Actual Usage
The official price list is the basis for estimation, but actual billing may deviate from theoretical values due to billing rules, caching strategies, and metering methods. Calibrate using the following steps.
- Record the input tokens, output tokens, and cache-hit tokens for each call, and aggregate them by day and by task type.
- Use regression fitting between actual billing and usage data to verify whether the price assumptions hold. If the goodness of fit is high, the model matches the data under the current rules.
- Do not treat the fitted result as a long-term valid price. After the provider changes its rules, resample and recalibrate.
- Keep a copy of the latest rule documentation with the calibration date for traceability.
VI. Engineering Implementation Recommendations
- Set budget caps and alerts, monitor daily and weekly, and automatically degrade or pause non-critical tasks when thresholds are exceeded.
- Define quality metrics for each task type, such as format correctness rate and manual sampling pass rate, as the basis for tiering and fallback.
- Keep system prompts and fixed prefixes stable to improve cache hit rates.
- Require models to output structured results and set a maximum output length to avoid ineffective long responses.
- Deduplicate and merge batch tasks to reduce repeated requests.
VII. Summary
The key to reducing LLM call costs lies in three things: breaking tasks down, quantifying cost variables, and tiering models by capability. First build a billing model, then calibrate it with actual usage, and finally use routing, budget monitoring, and quality fallback to balance cost and performance.
