Rethinking Enterprise Spending on Open-Source LLM Inference

    This article examines why enterprise AI inference costs are driven less by model nationality than by four controllable variables: per-token price, token volume, cache hit rate, and retry amplification. It presents a measurable cost formula, then walks through a four-step implementation path covering request tiering with default model policies, multi-layer caching (exact, semantic, and prefix), routing and batch scheduling, and observability with cost attribution. Common pitfalls and a closing summary are included to help teams reduce AI spending without sacrificing output quality.

    1. The Structural Reasons Behind the Trend

    A recent industry observation has drawn attention: one survey indicates that roughly 89% of the inference spending generated by U.S. companies using open-source large models ultimately flows to model service providers based in mainland China. Over the same period, a technical lead at a digital asset platform said publicly that their engineering team had set two open-weight models as the default inference backends. Combined with request routing optimization and semantic cache reuse, this reduced AI-related spending by nearly half even as token consumption continued to grow exponentially.

    Looking at these two facts together leads not to an emotional judgment such as “one country’s models are stronger,” but to a simpler engineering reality: for large-model inference, cost is determined by four variables — per-token price, total token volume, cache hit rate, and the proportion of wasted calls. The first two are shaped by market supply and demand and by business scale; the last two are entirely in the team’s own hands. Cross-border spending flows are essentially the result of two factors stacking: differences in per-unit price and the ability to self-host open weights. Cutting spending nearly in half, meanwhile, is the inevitable outcome of systematically optimizing the latter two variables.

    It is worth stressing that open weights do not mean zero cost. Self-hosting means taking on GPU compute, batch scheduling, GPU memory capacity, operations, and stability yourself. The real cost advantage comes from having options: you can switch freely among managed APIs, self-hosted inference, and models of different sizes, routing each class of request to the most cost-effective path.

    2. The Cost Model: Get the Math Right First

    Any optimization should start from a measurable cost formula:

    1. Total cost = Σ(request category i) [ Tokens_i × unit_price_i × (1 - cache_hit_rate_i) × (1 + retry_amplification_factor_i) ]

    This equation reveals three frequently overlooked levers:

    1. The retry amplification factor. Retries caused by timeouts, rate limiting, and format validation failures make billed tokens significantly higher than business tokens. For many teams, this is the primary culprit behind inflated bills.
    2. The denominator effect of cache hit rate. Every 10-percentage-point gain in hit rate produces an approximately linear cost reduction for that category.
    3. The granularity of request classification. Mixing “conversational completions” and “long-document reasoning” under the same default model amounts to subsidizing cheap demand with an expensive path.

    3. A Four-Step Implementation Path

    Step 1: Establish Request Tiering and a Default Model Policy

    Layer traffic by task difficulty — for example, simple rewriting, routine code completion, and complex reasoning with long-context analysis — and set a default model and fallback order for each tier. An illustrative configuration:

    1. routing:
    2. - tier: simple # formatting, comments, short-text rewriting
    3. model: small-weight-model
    4. max_tokens: 1024
    5. - tier: standard # routine code and Q&A
    6. model: mid-weight-model
    7. fallback: small-weight-model
    8. - tier: complex # long context, multi-step reasoning
    9. model: large-weight-model
    10. require_eval: true

    The key is the word “default”: default values determine the cost baseline for 80% of traffic, and complex requests should follow explicit escalation rather than default escalation.

    Step 2: Reuse Caches at Multiple Semantic Levels

    • Exact caching: keyed on a hash of the normalized request body, suited to parameterized, repetitive batch tasks.
    • Semantic caching: vector nearest-neighbor matching for synonymous rewrites, requiring a similarity threshold and a manual sampling review process to avoid wrong hits contaminating output.
    • Prefix caching: sharing the KV computation of prefixes across multi-turn conversations and fixed system prompts, which can significantly reduce repeated compute in long-prompt scenarios.

    In practice, track hit rate, false-hit rate, and average tokens saved as three core metrics observed together. Optimizing hit rate alone tends to introduce quality regressions.

    Step 3: Routing and Batch Scheduling

    The routing layer should decide based on four signals: task tier, context length, current backend load, and real-time unit price. On the batching side, separate latency-sensitive requests from offline tasks into different pools, and use larger batches in the offline pool to raise throughput and amortize per-scheduling overhead.

    1. def choose_backend(req, signals):
    2. if req.tier == "complex" and req.eval_passed:
    3. return signals.large_pool
    4. if signals.cache_hit(req):
    5. return "cache"
    6. if req.latency_slo < 800 and signals.mid_pool.load < 0.7:
    7. return signals.mid_pool
    8. return signals.batch_pool # offline first, lowest cost

    Step 4: Observability and Cost Attribution

    Without attribution there is no governance. Instrument the gateway uniformly and record at least: request tier, whether the cache was hit, input and output tokens, retry count, backend identifier, and estimated cost per call. Aggregate logs and monitoring alerts by business line to produce “one cost dashboard per team,” and wire budget-threshold alerts into daily workflows. This is the dividing line between a one-off optimization and a lasting mechanism.

    4. Common Pitfalls

    • Swapping models without routing: after switching the default model to a smaller one, quality on complex tasks drops, and the hidden cost of rework actually rises.
    • Caches with no invalidation policy: after a knowledge update, stale entries keep getting hit and outdated content is returned.
    • Ignoring output tokens: output is usually priced higher, so limiting redundant explanations and repeated code blocks yields clear gains.
    • No evaluation loop: without an offline evaluation set and canary comparisons, no optimization can prove that cost went down without quality going down.

    5. Conclusion

    Where the money flows is only the result; the cost structure is the cause. For enterprises, the sustainable approach is to keep model choice in their own hands, use tiered routing to set the cost baseline, use multi-layer caching to cut repeated computation, use batching to amortize scheduling overhead, and then lock all of it in with an observability system. As token demand keeps growing across the industry, the value of this combination will only increase. If you need more complete general-purpose cloud capabilities — such as managed inference, vector retrieval, and log monitoring — to support the architecture above, you can evaluate options against the general product categories offered by Baidu AI Cloud.