LLM API Cost Optimization: A Practical Guide to Lowering Cost Per Task
Choosing an LLM API by price per million tokens alone often leads to misleading conclusions. This guide explains why cost per task is a better decision metric, breaks down the price structure of a new generation of models (flagship input and output down about 20%, cached input down about 60%, and a mid-tier with upgraded capability at unchanged prices), and shows how prompt prefix stability drives cache hit rates. It also covers a three-tier routing strategy, the engineering metrics teams should monitor, and why retry and truncation rates belong in any real cost calculation.
1. Why “Price per Million Tokens” Can Mislead Your Decisions
When teams evaluate spending on LLM APIs, the first thing they usually look at is the price list: how much for input, how much for output. But real bills often contradict intuition, and the reason is simple — you pay per token, but you deliver per task. One task may involve long-context retrieval, multiple tool calls, and retries for structured output, multiplying token consumption several times over. Another task may be finished in a single call. Comparing prices side by side is like comparing two cars with completely different fuel consumption using only the price per gallon.
A more reasonable approach is to introduce the metric cost per task:
cost_per_task = (input_tokens * p_in+ cached_input_tokens * p_cache+ output_tokens * p_out) / 1_000_000
Here p_in, p_cache, and p_out are the per-million-token prices for input, cached input, and output. Put this on the x-axis and evaluation scores on the y-axis, and you get the “score–cost” curve widely used in the industry. This curve is more explanatory than any single price point: it answers both “how good is the result” and “how much did we pay for that result.”
2. The New Generation’s Price Structure: Three Key Changes
A cloud provider recently released a new generation of model families, and three aspects of the pricing strategy are worth developers’ attention.
First, the flagship tier cut input and output prices by roughly 20% each. Take a flagship model as an example: input is $8 per million tokens and output is $40, both down about 20% from the previous flagship generation. For long-context scenarios (codebase Q&A, contract review, log analysis), the absolute savings from the input-side cut are often larger than from the output side, because input token volume is typically several to dozens of times the output volume.
Second, cached input saw the largest drop, about 60%. Cached input fell from $1 per million tokens to $0.4. Cached input refers to the portion that is exactly identical to the prefix of a previous request and is reused by the server without recomputation. Its unit price is usually significantly lower than regular input, so raising the cache hit rate is the highest-leverage action in cost optimization.
Third, the mid-tier offers “upgraded capability at the same price.” A mid-tier model keeps the previous generation’s pricing (input $2, cached input $0.1, output $10) but with improved capability. This means tasks that previously required the flagship model to complete reliably now have a higher chance of moving down to the mid-tier, delivering de facto cost reduction.
It is also worth noting that the new flagship’s price is identical to that of a competing model released within the same week (also $8 input, $40 output). This shows that top-tier model pricing has entered a highly converged stage, and the room for pure price comparison is disappearing — call efficiency on the engineering side is becoming the main variable.
3. Cached Input: The Underrated Cost Lever
A cache hit requires a stable prefix. The order in which you organize a prompt therefore directly determines the bill:
[System instructions + tool definitions + domain knowledge] ← keep stable, place first[Conversation history / fixed retrieval snippets] ← keep as stable as possible[Current user input] ← the changing part, place last
A common anti-pattern is concatenating timestamps, random IDs, or user nicknames into the system prompt, which makes the prefix different on every request and invalidates the cache entirely. Practical recommendations:
- Move dynamic variables to the end and static content to the front;
- When batch-processing similar tasks, put the shared long document in the prefix and the per-item changing questions at the tail;
- Control the context length of each request and remove redundant snippets unrelated to the task;
- For multi-turn conversations, avoid re-concatenating the entire history every turn; use summary compression instead.
4. Tier Selection by Task: A Three-Level Routing Strategy
Do not send every request to the most expensive model. A workable layering is:
| Tier | Suitable tasks | Cost orientation |
|---|---|---|
| Flagship | Complex reasoning, long tool-call chains, high-value generation | Quality first |
| Mid-tier | Classification and extraction, routine Q&A, formatted output | Balanced |
| Lightweight | Intent recognition, routing decisions, batch labeling | Cost first |
A simple implementation is to have a lightweight model make a “difficulty judgment” first, then decide whether to escalate:
def route(task):if task.estimated_difficulty < 0.4:return "light"elif task.estimated_difficulty < 0.75:return "mid"return "flagship"
With an offline evaluation set, build a “score–cost” data point for each tier, and use marginal gain to decide whether an upgrade is worthwhile: if the flagship’s score improvement over the mid-tier is below a certain threshold while the cost doubles, the mid-tier should be the fixed choice.
5. Turning Cost into Engineering Metrics
Teams should establish three observable metrics and connect them to monitoring, alerting, and logging services:
- Cache hit rate: hit tokens / total input tokens; the target should typically be well above 50%;
- Cost per task: aggregated by business action (not by day), which makes anomalies easier to locate;
- Retry rate and truncation rate: truncated output triggers retries, making it a hidden major cost driver.
effective_cost = nominal_cost / (1 - retry_rate)
When the retry rate is 10%, the actual cost is about 11% higher than the number on paper. Improving output stability (clear format constraints, sensible max output length settings, structured output validation) is therefore as important as a price cut.
6. Conclusion
What the new generation of models brings is not a “plunge” in any single unit price, but an overall downward shift in cost structure: input and output each down about 20%, cached input down about 60%, and better value from the mid-tier. For developers, the real cost-reduction path has three steps: replace unit price with cost per task as the decision metric; raise cache hits through prefix stabilization; and use tiered routing to send tasks to the tier that is “good enough and cheaper.” Combined, these three are usually more effective than waiting for the next price cut.
