Million-Token Long-Context LLMs: Evaluation, Cost Modeling, and Engineering Practices

    Long context has become a key battleground among flagship models, yet a million-token window is only a capacity metric—not a guarantee of business value. This article explains how to measure a model's effective context length, assess long-horizon stability and factual accuracy, and model token-based costs. It covers needle-in-a-haystack testing (single-needle, multi-needle, and refusal), terminal-restricted and long-horizon coding benchmarks, safety alignment through two-stage data filtering and the pass@k trade-off, the four billing dimensions of token pricing with cache break-even analysis, and a reusable cost-estimation script. It closes with a context-layering architecture, a metrics framework, and a practical selection checklist for evaluating the next generation of long-context models.

    Introduction: From “fitting more in” to “using it well”

    Long-context capability has become a major dimension in the competition among flagship models. An advertised million-token window means a model can accept more material, but business outcomes are not determined by window size alone. Three questions really matter:

    • How long is the effective context;
    • Can long-horizon tasks be completed reliably;
    • Is the cost per task under control.

    “A million tokens” is, by itself, just a capacity metric. What tends to decide success or failure in practice is effective context length, long-horizon stability, factual accuracy, and cache and output costs. Building on publicly available evaluation methods, this article discusses how to evaluate a model, how to estimate costs, how to organize context in engineering practice, and provides a reusable checklist.

    Note: The example data in this article is used only to illustrate the analysis approach and does not constitute an evaluation of any specific product; the illustrative code expresses design ideas only and does not contain any vendor-specific API implementation.

    1. Evaluation: Unpacking the Real Capability Behind “One Million Tokens”

    1.1 Why the effective context is shorter than the advertised window

    The industry often refers to the length of information a model can reliably use in practice as its “effective context.” This is usually noticeably shorter than the advertised window, for several reasons:

    • Attention dilution: critical signals get drowned out by large volumes of irrelevant tokens;
    • Positional bias: information at the beginning and end is more easily used, while information in the middle is more easily lost—the so-called “lost in the middle” effect;
    • Noise interference: repeated, outdated, or irrelevant fragments can lead the model to answer the wrong question;
    • Error propagation: mistakes in earlier steps keep accumulating downstream.

    Take a long-horizon task as an example. If the single-step accuracy is 99%, the probability of complete success after 100 consecutive steps is only 0.99^100 ≈ 36.6%. So testing only “how much can be stuffed in” is not enough; you must also test the model’s ability to locate, integrate, and refuse within a long context.

    1.2 Long-context testing: single-needle, multi-needle, and refusal

    Long-context evaluation can usually be divided into three levels:

    • Single-needle retrieval: plant one unrelated piece of information in a long document and test recall at a specified depth;
    • Multi-needle aggregation: plant several pieces of information with related questions to assess cross-paragraph synthesis;
    • Refusal capability: ask about information that is not in the document and observe whether the model can clearly answer “not mentioned.”

    An illustrative test-case construction is shown below:

    1. def build_case(doc: str, needles: list[dict], question: str, answerable: bool) -> dict:
    2. """needles: [{"text": fact, "depth": 0.0~1.0}, ...]"""
    3. for n in needles:
    4. pos = int(len(doc) * n["depth"])
    5. doc = doc[:pos] + "\n\n[archived fragment] " + n["text"] + "\n\n" + doc[pos:]
    6. return {"prompt": doc + "\n\nQuestion: " + question,
    7. "expected": "not mentioned" if not answerable else None}

    An example depth-recall curve is shown below:

    Depth 0% 25% 50% 75% 100%
    Previous-gen model (320K tokens) 91.2% 89.7% 78.3% 87.6% 90.5%
    New model (1M tokens) 92.8% 92.1% 89.6% 91.4% 93.0%

    As you can see, the previous-gen model collapses sharply at the 50% depth, showing a classic “lost in the middle” pattern, while the new-gen model stays around 90% at every depth across the million-token range. This depth curve says far more than the “advertised window” or the maximum context length alone.

    1.3 Terminal-restricted tasks and long-horizon coding: avoid being misled by averages

    The focus of flagship model upgrades is shifting from “code completion” toward “completing tasks in real environments.” Terminal-restricted tasks generally refer to multi-step work completed in a real terminal with a limited toolchain—for example, environment setup, dependency repair, script debugging, and build-artifact verification.

    Using publicly available example data, the new model scores about 65.7% on terminal-restricted tasks, higher than an international example’s 58.2%, and about 0.7 percentage points behind the current strongest example at 66.4%. Benchmarks differ in methodology, so specific numbers should be understood alongside verifiable sources, but the way to read them is consistent:

    • The gap between top models on terminal-restricted tasks has narrowed to single-digit percentage points;
    • Top models generally fall below 70%, indicating that most remaining failures stem from environmental complexity and long-horizon constraints;
    • Further improvement requires finer-grained failure attribution and long-horizon stability optimization.

    On an internal long-horizon coding benchmark, the example data is 55.95% for the previous generation and 61.2% for the new generation—a gap of about 5.25 percentage points. This gap is smaller than the one on terminal-restricted tasks, but it should not be dismissed as merely “obvious” either, because different task distributions affect the size of the gap, and it should not be extrapolated into a universal conclusion.

    For tool-based tasks such as parametric 3D modeling, game-engine scripting, and 3D-modeling-software scripting, model performance depends heavily on the toolchain and deterministic programs. In the absence of publicly verifiable data, it is best to treat these as qualitative judgments rather than writing them up as measured conclusions.

    1.4 Factuality: single-sentence error rate is not the same as whole-document error rate

    In knowledge-intensive tasks such as long-document summarization and industry research reports, factual accuracy is often the top metric. The single-sentence error rate and the whole-document error rate must be considered separately.

    Suppose an answer contains n statements, each with an error rate of p. Under the simplifying assumption that errors are independent, the probability that the entire answer is “completely correct” is:

    (1 − p)^n

    Example:

    Single-sentence error rate p n=1 n=2 n=5 n=10
    23.4% 76.6% 58.7% 26.4% 6.9%
    8.3% 91.7% 84.1% 64.8% 42.0%

    The key point here is that reducing the single-sentence error rate from 23.4% to 8.3% is a relative reduction of about 65%, but in multi-statement answers the improvement in whole-document correctness is significantly amplified. Taking n=10 as an example, the previous generation’s probability of being completely correct was only about 6.9%, while the new generation raises it to about 42.0%.

    Two common interpretations need to be distinguished:

    • If “42.4%” is the absolute whole-document error rate, at p=23.4% it roughly corresponds to about 2 statements;
    • If “42.4%” is a ratio relative to the old version’s whole-document error rate, under the independence assumption it roughly corresponds to 2 to 3 statements;
    • You cannot derive a conclusion of “7–8 statements” from this.

    At the same time, note that the formula above assumes errors are mutually independent, whereas in practice a model’s errors within the same answer are often correlated. The formula is suitable for order-of-magnitude judgments, not for precise extrapolation. Official examples also typically note that such tests may focus on error-prone cases, so the single-sentence error rate does not represent the overall error rate in everyday use.

    2. Safety Alignment: The Triangle of Capability, Risk, and Compliance

    The greater the capability gains, the greater the potential impact of misuse. This applies especially to improvements in coding ability, terminal-operation ability, and safety ability. Safety alignment cannot rely only on final refusal; it should be handled in layers across the data, training, and evaluation stages.

    2.1 Two-stage data filtering

    Judging from publicly described methods, safety policies typically include two stages:

    • Mid-training stage: after pre-training and before post-training, introduce high-quality, domain-focused data while identifying and removing data related to network attack and defense, reducing the model’s ability to master offensive details at the knowledge level;
    • Reinforcement learning stage: through reward design and preference data, guide the model to be more cautious in safety-sensitive scenarios, forming behavioral boundaries such as refusal, clarification, and minimal output.

    The benefit of layered intervention is that it is interpretable and regression-testable. Each stage can be evaluated independently, avoiding leaving the problem to a “black-box” remedy at the very end.

    2.2 pass@k: measuring the cost of “gatekeeping”

    On an internal development benchmark, the example data is as follows:

    • The unfiltered version solves 90.5% of problems under pass@3;
    • The final release version reaches 81.0%, meaning filtering reduced pass@3 by 9.5 percentage points.

    pass@k means that the model is allowed k attempts on the same task, and it counts as passing as long as at least one attempt succeeds. The drop can be broken down into two causes:

    • False positives on legitimate use cases: normal system hardening, troubleshooting, and security-testing tasks are filtered out along with everything else;
    • Changes in stability across multiple samples: filtered data also affects the quality of the model’s exploration on similar tasks.

    Therefore, safety building cannot be outsourced to the model. Application owners should:

    1. Establish an abuse-risk assessment on the business side, defining which tasks must be refused and which are legitimate defensive needs;
    2. Build a bidirectional evaluation set covering both “high-risk refusal” and “legitimate pass-through,” to avoid a one-size-fits-all safety policy;
    3. Set up human review and least-privilege mechanisms for sensitive scenarios, keeping a human in the loop;
    4. Retain auditable call records to meet compliance and traceability requirements.

    3. Pricing: Cost Estimation for Token-Based Billing Models

    3.1 Four billing dimensions

    Token-billed LLM services can usually be broken down into four parallel dimensions:

    • Basic input: the token cost of the request prefix and new input;
    • Basic output: the token cost of the model’s generated content;
    • Cache hit: the discounted cost when a request prefix hits already-cached content;
    • Cache write: the cost of writing a prefix into the cache, usually split into two validity tiers of 5 minutes and 1 hour.

    The fast tier is not a validity category but an acceleration tier. It generally manifests as basic input, output, and cache-write prices being about twice those of the standard tier, while the cache-hit price is the same as the standard tier. When choosing, focus on the relative relationships among the billing dimensions rather than looking only at absolute prices.

    3.2 Relative price multiples

    With the standard input unit price set to 1.0, the example prices normalize as follows:

    Billing item Standard Fast
    Input 1.00 2.00
    Output ≈5.23 ≈10.46
    Cache hit ≈0.10 ≈0.10
    Cache write (5 min) 1.00 2.00
    Cache write (1 h) 2.00 4.00

    Three patterns are worth noting:

    • The cache-hit price is about one-tenth of the input price, so there is substantial room for savings when the long context is reused;
    • The output unit price is more than 5 times the input price, so trimming output often reduces cost more than compressing input;
    • The fast tier’s cache-hit price equals the standard input price, so the fast tier suits output-heavy, latency-sensitive scenarios and is not suited to tasks with massive input.

    3.3 Cache-write break-even point

    A cache write is a one-time investment that can only be recovered if there are enough subsequent hits. Let the full input unit price be P and the hit unit price be 0.1P, then:

    • The 5-minute cache-write price is about P, so break-even requires P ÷ 0.9P ≈ 1.1 hits;
    • The 1-hour cache-write price is about 2P, so break-even requires 2P ÷ 0.9P ≈ 2.3 hits.

    If the same prefix is requested once every d interval, using a continuous approximation, the break-even time is about ceil(break-even hits × d). Examples:

    Scenario Repeat interval 5 min cache 1 h cache
    Multi-turn dialogue 30 sec ~33 sec ~70 sec
    Coding assistant (same repo) 5 min ~6 min ~11.5 min
    Batch document processing (same template) 30 min ~33 min, exceeds the 5-minute validity, not recommended ~69 min, near or beyond the 1-hour validity, also not recommended in strict mode

    It must be emphasized that tiers whose break-even time exceeds the cache validity are not recommended. In production, you should also recheck against integer hit counts, request intervals, and cache-expiry policies, rather than relying only on theoretical approximations.

    For high-frequency, short-duration scenarios such as multi-turn dialogue, the 5-minute cache usually reaches break-even more easily; the 1-hour cache is only more cost-effective under sustained high activity. For low-frequency, long-cycle scenarios such as batch processing, the 5-minute cache often cannot break even within its validity; the 1-hour cache also needs requests to be dense enough, otherwise the write cost cannot be recovered once the cache expires.

    3.4 Cost-estimation script and reproducible results

    Below is a reproducible cost-estimation script. Prices are all expressed in units of the standard input unit price P, and the total cost includes the output cost.

    1. INPUT, OUTPUT, HIT = 1.0, 5.23, 0.10
    2. WRITE = {"5m": 1.0, "1h": 2.0}
    3. SPEED = 2.0
    4. def estimate(n_req=1000, ctx=100_000, out=2000,
    5. ratio=0.6, cache=None, speed=False, writes=1):
    6. k = SPEED if speed else 1.0
    7. out_cost = n_req * out * OUTPUT * k
    8. if cache is None or ratio == 0:
    9. in_cost = n_req * ctx * INPUT * k
    10. return round(in_cost + out_cost, 2)
    11. prefix = int(ctx * ratio)
    12. fresh = ctx - prefix
    13. write_cost = prefix * WRITE[cache] * k * writes
    14. hit_cost = n_req * prefix * HIT
    15. fresh_cost = n_req * fresh * INPUT * k
    16. total = write_cost + hit_cost + fresh_cost + out_cost
    17. return round(total, 2)

    Example parameters: 1000 requests, each with 100K input tokens and 2000 output tokens, with a reusable prefix accounting for 60%. The results are as follows:

    Strategy Total cost (in P) Effective input unit price Savings vs. no cache
    No cache 110460000 1.1046 —
    5 min cache (1 write) 56520000 0.5652 48.8%
    1 h cache (1 write) 56580000 0.5658 48.8%
    Fast + 5 min (1 write) 107040000 1.0704 3.1%

    Notes on methodology:

    • The total cost includes the output token cost;
    • Effective input unit price = total cost ÷ (number of requests × input tokens per request);
    • The “1 write” in the table applies to scenarios where requests are concentrated within the cache validity period.

    If the 1000 requests are spread over about 8 hours, the cache will expire and be rewritten multiple times. Approximate estimates:

    • The 5-minute cache needs about 96 writes, with a total cost of about 62220000P, saving about 43.7% versus no cache;
    • The 1-hour cache needs about 8 writes, with a total cost of about 57420000P, saving about 48.0% versus no cache.

    So the caching strategy must be driven by access frequency and cannot be assumed to save money just because it is turned on.

    In this example, the output cost is 1000 × 2000 × 5.23 = 10460000P, about 9.5% of the total cost. If the output were halved, the total cost would drop by only about 4.7%. Only when output tokens exceed about 19% (i.e., 1/5.23) of input tokens could output become the main cost item. If output tokens are much smaller than input tokens, you should prioritize optimizing input length, cache hit rate, and prefix stability.

    4. Engineering: Context Layering and Observability

    4.1 Context layering management

    In engineering practice, it is advisable to divide the context into three layers, each matched with an appropriate caching and governance strategy:

    • Stable layer: system prompts, tool definitions, code-repository indexes, and business knowledge-base summaries. The content is basically unchanged, so it should be written to the cache with a longer validity first;
    • Session layer: multi-turn dialogue history and task progress. Trimmed with a sliding window, it is suited to a short-validity cache;
    • Retrieval layer: document fragments dynamically recalled for the current question. With a low hit rate, it is not recommended to cache.

    An illustrative assembly logic is shown below:

    1. MIN_OUTPUT_RESERVE = 1000
    2. def count_tokens(msgs):
    3. # Illustrative only: in production, replace with a real tokenizer
    4. return sum(len(str(m.get("content", ""))) for m in msgs) // 2
    5. def build_context(system: str, tools: list, history: list[dict],
    6. retrieved: list[str], budget: int = 1_000_000) -> list[dict]:
    7. stable = [{"role": "system",
    8. "content": system + "\n\n## Available tools\n" + str(tools)}]
    9. remaining = budget - count_tokens(stable)
    10. kept = []
    11. for msg in reversed(history):
    12. t = count_tokens([msg])
    13. if remaining - t < MIN_OUTPUT_RESERVE:
    14. break
    15. kept.append(msg)
    16. remaining -= t
    17. for doc in retrieved:
    18. t = count_tokens([{"role": "user", "content": doc}])
    19. if t <= remaining:
    20. kept.append({"role": "user", "content": doc})
    21. remaining -= t
    22. else:
    23. # Drop low-relevance fragments when the budget runs low
    24. break
    25. return stable + list(reversed(kept))

    The key point is that the stable layer must be placed first and its content kept as unchanged as possible—this is the prerequisite for improving the prefix-cache hit rate. If the session layer and retrieval layer are inserted before the stable layer, the prefix will change frequently and the cache will invalidate frequently.

    4.2 Metrics system

    It is advisable to monitor at least the following metrics:

    • Quality: task success rate (pass@k), long-context recall rate, hallucination rate, and refusal accuracy;
    • Cost: cache hit rate, effective input unit price, cost per task, and output token share;
    • Performance: end-to-end latency, time to first token, and output token rate;
    • Safety: risk-request interception rate and false-interception rate on legitimate requests.

    When deploying stateless agent runtimes on a container platform, combined with object storage to archive corpora and run logs, and then connecting to a general-purpose cloud platform’s logging, monitoring, and alerting capabilities, you can form a closed loop. For example, you can set alerting rules for “cache hit rate dropping,” “cost per task rising month over month,” and “abnormal proportion of high-risk interceptions.”

    5. Selection Checklist

    When facing a new generation of long-context models, it is advisable to evaluate them in the following order:

    1. Effective context: use a “retrieval-and-refusal” test set with multiple depths and multiple lengths to confirm the recall rate at the length your business requires;
    2. Long-horizon tasks: use a terminal-restricted task set close to your business, examining both success rate and number of steps to completion;
    3. Factuality: convert to “whole-document correctness” based on the average number of statements, rather than looking only at the single-sentence error rate;
    4. Safety and compliance: use a bidirectional evaluation set to test interception effectiveness and avoid harming legitimate defensive needs;
    5. Cost: first estimate with a reproducible model, then choose the cache tier based on actual access frequency, with output trimming and cache hit rate as the primary optimization directions.

    Conclusion

    The focus of competition around million-token windows is shifting from “capacity” to “effectiveness.” What developers really need to answer is: can the model complete tasks in a real terminal, can it ensure factual accuracy in long-form generation, can it balance legitimate needs under safety constraints, and how much does each task cost. Breaking these questions into measurable, regression-testable metrics and continuously monitoring and iterating on them is how long-context capability can truly be turned into business value.