LLM API Billing Optimization: Search and Web Fetching Merged into Token Metering

    This article explains a shift in LLM API billing where server-side web search and page fetching are no longer charged as separate per-request items and are instead reflected through token usage. It covers why per-request pricing misaligned cost with value, how the change affects AI agents and RAG applications, and four practical levers for cost optimization: tiered filtering of retrieval results, explicit decisions about when to enable web access, caching and reuse, and output-side constraints. Engineering guidance on observability, retries, compliance, and capacity planning is also included.

    1. What Changed: From Per-Request Billing to Token-Based Billing

    A cloud provider announced a change to how its LLM API is billed: starting from a specified point in time, the web search and page fetching actions triggered by the server during a model call are no longer billed separately. Charges are tied only to the model’s token usage.

    One clarification matters here: “no longer billed separately” means the standalone per-request charge has been removed, not that these actions are free. The retrieved web pages and fetched page bodies still enter the model input as context, so they are still reflected on the bill as tokens. Understanding this is the prerequisite for accurate cost budgeting.

    Three typical entry points trigger server-side web access: the model’s built-in web tool, the web search tool enabled when the API is compatible with third-party interface specifications, and the web search tool in the response API. What they share is the same flow: the model decides during inference that it needs external real-time information, the server performs the retrieval and fetching on its behalf, and the results are assembled into the context so generation can continue.

    2. Why the Change: The Structural Flaws of Per-Request Billing

    Before this, the more common industry model was “charge retrieval by the number of requests.” As an example of earlier pricing on one platform, the search and fetch interfaces were priced at five yuan per thousand successful requests: the search interface returned structured results for a query, and the fetch interface converted a single web page into Markdown text containing the title and body.

    The problem with per-request billing is that cost does not align with business value:

    • One request may return only a small amount of usable information or a large amount of noise, at the same price.
    • When an agent makes multiple rounds of tool calls, the request count inflates quickly and the bill becomes hard to predict.
    • Users still pay when fetching fails, content is invalid, or results are discarded by the model.
    • Budget estimation requires maintaining two separate ledgers, “requests” and “tokens,” which makes capacity planning complex.

    Merging retrieval into token metering converges billing to a single dimension: you pay for the amount of information that actually enters the model context. The number of retrieval calls is no longer the billed object, the marginal cost of an invalid fetch drops significantly, and the cost curve becomes smoother and more predictable.

    3. Practical Impact on Agents and RAG Applications

    1. The cost structure of multi-round tool calls changes

    A typical agent behavior is “think, retrieve, think again,” and triggering multiple searches within a single task is normal. Under per-request billing, a longer call chain meant higher fixed cost. With token billing, that fixed cost disappears, and long-chain tasks become noticeably more cost-effective.

    2. The cost center shifts to context management

    The new cost center is context length. Retrieved page bodies often run to thousands of characters, and inserting them into the prompt as-is makes input tokens pile up quickly. Context trimming, reranking, and compression therefore move from “optimization items” to “requirements.”

    3. The psychological burden of retrying failures drops

    Fetch failures caused by network fluctuations and parsing errors caused by page structure changes cost real money on every retry under per-request billing. After the change, retry strategies can be more aggressive, which makes high availability easier to achieve in engineering terms.

    4. Four Levers for Cost Optimization

    Lever 1: Tiered filtering of retrieval results

    Do not send all retrieval results straight to the model. Apply a lightweight filter first: score relevance by title and summary, keep only the top K, then extract at the paragraph level from the body.

    1. def build_context(query, docs, top_k=3, max_chars=4000):
    2. scored = sorted(docs, key=lambda d: relevance(query, d), reverse=True)
    3. picked, budget = [], max_chars
    4. for d in scored[:top_k]:
    5. body = d["content"][:budget]
    6. picked.append(f"[{d['title']}]\n{body}")
    7. budget -= len(body)
    8. if budget <= 0:
    9. break
    10. return "\n\n".join(picked)

    Lever 2: Make “whether to go online” an explicit decision

    Do not let the model decide on its own whether to retrieve at every step. A more reliable approach is to control it at the application layer: run an intent check first, enable web access only when the request involves real-time data or time-sensitive facts, and route everything else through the pure model path.

    Lever 3: Caching and reuse

    Build a cache of retrieval results for high-frequency queries, keyed on the normalized query text, with a reasonable expiration time. For the fixed portion of knowledge, use a stable system prompt prefix; combined with an inference service that supports context caching, this can further reduce the cost of repeated input.

    Lever 4: Converge the output side too

    Money saved on the input side is easily consumed by verbose output. Explicitly constraining the output structure, fields, and length, and using a structured format to bound the generated result, is a frequently overlooked step with direct returns.

    1. {
    2. "answer": "concise conclusion",
    3. "evidence": ["source title 1", "source title 2"],
    4. "confidence": 0.86
    5. }

    5. Engineering Implementation Notes

    • Observability: instrument input tokens, output tokens, retrieval trigger count, and cache hit rate separately, connect them to logging and monitoring with alerts, and build a cost dashboard broken down by business dimension.
    • Idempotency and retries: retrieval and fetching are external dependencies, so configure timeouts, backoff retries, and fallback paths to keep a single point of failure from bringing down the whole chain.
    • Data compliance: fetched content may involve copyright and personal information, so retain source attribution, limit the retention period, and where necessary keep only summaries and vectors.
    • Capacity planning: use “average input tokens per task” rather than “retrieval calls per task” as the core metric, and recalibrate quotas and rate-limiting thresholds accordingly.

    6. Summary

    The essence of this billing change is to restore retrieval and fetching from standalone products to one stage of the model inference chain, so that price returns to the real volume of information entering the context. For developers, the optimization focus shifts accordingly: from compressing the number of calls to managing context quality. Getting these four things right, tiered retrieval filtering, explicit web-access decisions, caching and reuse, and output constraints, yields both lower cost and more stable results under the new metering. If the overall solution runs on Baidu AI Cloud, general capabilities such as object storage, message queues, container platforms, and monitoring with alerts can be combined to turn the retrieval chain into a standard component that is observable and elastically scalable.