3 Surprises and 1 Unexpected Issue from a 10-Million-Token LLM Long-Running Task Test
This article shares findings from a stress test that pushed cumulative LLM token consumption to the tens of millions. It explains why single-turn tests miss real engineering problems, then covers three surprises—prefix caching lowering marginal costs, total bills growing slower than unit prices, and engineering safeguards for long-context stability—plus one unexpected issue: cache hit rates can suddenly collapse. It includes practical implementation tips, sample code, and a deployment checklist for treating cost as an observable, attributable, and governable engineering metric.
1. Test Background: Why Stress Testing at the Ten-Million-Token Scale Matters
A single question-and-answer exchange typically consumes only a few hundred to a few thousand tokens, which is rarely enough to expose real engineering problems. Only when cumulative consumption is pushed into the tens of millions do three previously overlooked phenomena appear in long-running tasks: the hidden overhead of repeatedly transmitting the same context, the peak-shaving effect of caching on the total bill, and occasional nondeterministic outputs in long call chains.
The goal of this test was not to score any particular model. It was to answer a more general question: when call volume scales up by three orders of magnitude, how do cost, latency, and stability change, and what should engineering teams modify?
It should be noted that cloud providers differ significantly in billing rules, caching strategies, and rate-limiting policies. This article only discusses mechanisms and practices that generally hold across the industry; it does not cover the specific parameters of any particular product.
2. Surprise 1: Cache Reuse Lowers the Marginal Cost of Long-Running Tasks
Long-running tasks—codebase Q&A, long-document review, and multi-turn agent orchestration—typically share one characteristic: a highly repetitive prefix. The system prompt, tool definitions, conversation history, and reference material are often identical across consecutive calls. The mainstream industry approach is prefix caching, where only the newly added portion is billed when the same prefix is matched.
Key practices:
- Prioritize prefix stability. Move volatile content (timestamps, random IDs, user nicknames) from the top of the prompt to the bottom so the entire prefix does not become invalidated.
- Layer the prompt. Arrange the fixed layer (role and rules), the semi-fixed layer (tools and templates), and the dynamic layer (current-turn input) from top to bottom.
- Make hit rates observable. Use a logging service to record the prefix fingerprint and hit flag for each request, and aggregate hit rates by business line.
Illustrative code:
def build_prompt(fixed, semi_fixed, dynamic):# Order cannot be changed arbitrarily; prefix changes invalidate the entire cachereturn f"{fixed}\n{semi_fixed}\n{dynamic}"
A counterintuitive conclusion is that optimizing prompt length often yields less benefit than improving prefix stability.
3. Surprise 2: Total Bills Grow Much Slower Than Unit Prices
When unit prices rise, the total bill does not necessarily increase proportionally, for three reasons. First, cache-hit portions are usually billed at a lower price. Second, output accounts for a large share in long-running tasks, and there is substantial room for output-side optimization (structured short outputs, avoiding repetition). Third, after failed retries and invalid calls are brought under control, the total volume itself declines. Therefore, cost evaluation must look at “cost per unit of effective output,” not unit price.
It is advisable to build a cost dashboard with dimensions including: business line, API, cache hit rate, input-to-output token ratio, retry rate, and single-task success rate. Only by placing the numerator (spend) and the denominator (number of effectively completed tasks) together can the impact of a price increase be explained.
4. Surprise 3: Long-Context Stability Can Be Backstopped by Engineering Means
Long call chains are more prone to format drift and truncation. Reliable practices include: enforcing structured output and performing schema validation on the server side; setting segmented checkpoints for critical steps; splitting and summarizing overly long material before it enters inference; allowing safe retries for idempotent operations and introducing idempotency keys for non-idempotent operations.
{"schema_check": true, "max_retries": 2, "idempotency_key": "task-8821"}
5. The Unexpected Issue: Caching Is Not Always Profitable—Hit Rates Can Suddenly Collapse
The most unexpected phenomenon in testing was a cliff-edge drop in hit rate. A minor prompt-template tweak, moving a dynamic field to the front, or a concurrency scale-up that changed routing could all cause the hit rate to fall from a high level to nearly zero, with the bill jumping accordingly. The response is to treat cache hit rate as a first-class monitoring metric with threshold alerts; roll out template changes through canary releases and regression testing; and add a “prefix fingerprint diff” check to the release process.
6. Implementation Checklist
- Establish a unified prompt assembly layer and prohibit business teams from hand-writing concatenation.
- Set up token budgets and quotas, with caps by task type.
- Monitor hit rate, retry rate, and success rate on the same screen.
- Include cost-impact assessment in change reviews.
- If using general-purpose cloud capabilities, build a closed loop with object storage for archiving long text, message queues for peak shaving, container platforms for elastic scaling, and monitoring and alerting.
7. Conclusion
The real value of a ten-million-token test is not arriving at a particular number, but establishing a methodology: treating cost as an observable, attributable, and governable engineering metric. Once this is achieved, unit-price fluctuations become merely parameter changes rather than an out-of-control bill.
