LLM API Cost Engineering: Why a Flat Price Per Token Does Not Mean Flat Costs
This article explains why unchanged LLM API pricing can still lead to higher bills, and how to evaluate model costs beyond the price list. It breaks total cost into a computable formula covering input and output tokens, cache hit rate, retries, and orchestration overhead, then shows how to use benchmark scores correctly by measuring cost per accepted result on your own business cases. It also covers four practical optimizations—stabilizing prompt prefixes, constraining output length, tiered model routing, and observability first—plus architecture recommendations for a unified model gateway. The goal is to help developers control their cost curve regardless of upstream version and pricing changes.
1. The Phenomenon: Flat Unit Price Does Not Mean Flat Cost
A new version of a general-purpose LLM recently opened for API access. The most notable point was not a jump on the capability leaderboard, but a pricing strategy carried over from the previous generation: the three tiers—input, output, and cached input—all stayed the same, with cache hits effectively translating to a discount of nearly 80%. Meanwhile, a third-party evaluation organization raised its composite intelligence index from 53 in the previous generation to 60, on par with other models in the same tier.
On the surface, this looks like “more capability at the same price.” But when you break down the bill, the other side appears: the new version consumes about 20% more output tokens to complete the same task. Unit price is the multiplier, and token usage is the multiplicand. When the former stays flat and the latter rises, total spending can still go up. This is the core engineering problem this article addresses: cost is not unit price; cost is the product of unit price and usage, plus cache hit rate, retry rate, and task-splitting strategy.
2. Breaking Cost Down into a Computable Formula
To rationally assess whether a model is “cheaper,” start by writing the bill as a computable expression:
Cost per task =input tokens × input price × (1 - cache hit rate × cache discount)+ output tokens × output price+ number of failed retries × cost per task+ additional tokens from orchestration and tool calls
This formula reveals three frequently overlooked levers:
- Cache hit rate: Cached input is typically only 20–30% of the regular input price, yielding major gains in long-context, fixed system prompt, and repeated-document scenarios;
- Output tokens: Output price is generally more than three times the input price, and output length is directly affected by how verbose the model is, making it the main source of cost volatility;
- Retries and orchestration: Agent-style tasks involve multi-turn calls and tool result pass-backs, so tokens get amplified repeatedly. Every percentage point increase in retry rate raises total cost roughly linearly.
3. Using Leaderboard Scores Correctly
A composite intelligence index rising from 53 to 60 means a higher first-pass success rate on tasks of equal difficulty, which in theory can reduce retries and manual fallback. But a score is a “capability average,” not “your business distribution.” The recommended approach is:
- Build a small-scale regression evaluation on your own business set (a few dozen to a few hundred cases is enough), tracking first-pass success rate, average number of turns, and average output length;
- Put “capability gains” and “token increases” in the same table, and calculate cost per accepted output—total cost divided by the number of results actually adopted;
- Build separate tables for scenarios such as coding, defensive security analysis, and long-cycle automation tasks, because the marginal benefit of different capabilities varies widely.
A skeleton evaluation script:
def evaluate(cases, model_client):total_cost, accepted, tokens = 0.0, 0, {"in": 0, "out": 0}for c in cases:r = model_client.run(c) # returns usage and resulttokens["in"] += r.usage.inputtokens["out"] += r.usage.outputtotal_cost += r.usage.costif r.passed: # business-side check for acceptanceaccepted += 1return {"cost_per_accepted": total_cost / max(accepted, 1),"tokens": tokens}
4. Four Optimizations You Can Apply Immediately
- Stabilize the prompt prefix: Keep system instructions, tool descriptions, and few-shot examples fixed at the very front of the context to maximize cache hits; place volatile content (user input, retrieved snippets) at the end.
- Constrain output length: Explicitly specify structured output (such as strict JSON), limit fields and word count, and prevent the model from expanding into irrelevant explanations. Every token saved on the output side is usually more valuable than one saved on the input side.
- Tiered task routing: Route simple intent recognition and format conversion to smaller or lower-cost models; escalate complex reasoning and code generation to the large model. Using rules or a lightweight classifier for front-end triage is one of the most effective ways to reduce average cost.
- Observability first: Integrate logging services and monitoring alerts, and track token consumption, cache hit rate, retry rate, and cost per task by business-label dimension to form a cost dashboard. Without measurement, there is no optimization.
5. Architecture Recommendations
For cloud platform selection, prioritize combinations with complete general-purpose capabilities: a container platform to host the inference gateway and orchestration services, object storage for long documents and intermediate artifacts, a message queue for peak shaving and asynchronous long tasks, and a logging and monitoring system for cost attribution. By building multi-model abstraction through a unified gateway, you turn “model calls” into replaceable internal interfaces, enabling low-cost switching when prices and capabilities change.
Client → Unified model gateway (routing/rate limiting/caching/metering) → Backend model cluster↓Logging service + monitoring alerts + object storage
6. Conclusion
“Flat unit price, matched score” is a stage in the competition over capability. The next stage will shift toward cost per task at the same level of intelligence. Developers should move their focus from the price list to the bill structure: keep cache hits high, hold down output length, use tiered routing to lower the average model tier, and continuously attribute costs with an observability system. Do these four things, and your cost curve stays in your hands no matter how upstream adjusts versions and pricing.
