LLM API Billing Shifts to Token-Based Metering for Web Search

    This article explains how a major model service changed its API billing so that server-side web search and page fetching are no longer charged per call but are covered by model token usage. It breaks down the two integration paths (built-in retrieval versus standalone search and fetch APIs), shows how to estimate costs under token metering, and outlines practical techniques for context engineering, three-layer caching, rate-limit handling with backoff and fallback, and token-centric observability. Developers will learn where the real cost center now sits and how to keep connected AI workloads predictable and under budget.

    1. Background: A Change in Billing Scope

    A model service recently changed how it bills its API: starting at noon on a certain day, web search and page fetching triggered by the server during model calls are no longer charged separately per request. They are now settled only through model token usage. In other words, when developers ask a model to “look things up and then answer,” the extra “search fee” and “fetch fee” that used to apply are removed, while the model’s input and output tokens are still billed as usual.

    This may look like a small line of fine print on a pricing page, but it actually changes the cost structure of the entire web-connected pipeline. Previously, a single search-augmented Q&A request produced a bill made up of three parts: model tokens, search calls, and fetch calls. Now it converges to two parts: model tokens and (optionally) standalone API call fees. For high-frequency web-connected scenarios, the bill becomes far more predictable, but the idea that “tokens are the only cost center” also makes context management more important than ever.

    It is worth stressing that this does not mean all retrieval is free. If developers bypass the model and call the standalone search API and page-fetch API directly, they are still billed per successful request, with a common industry price range on the order of a few RMB per thousand successful requests. What is free is the retrieval the model does along the way internally; what is charged is using retrieval as a standalone capability.

    2. The Boundary Between the Two Paths: Built-in Retrieval vs. Standalone APIs

    To understand this change, the key is to distinguish two paths.

    The first is the model’s built-in path: after a request enters the model service, the server initiates retrieval and fetching on its own based on the task’s needs, the results enter the model context, and only tokens are settled in the end. Its traits are “black box, worry-free, pay by token,” making it suitable for scenarios where the deliverable is a generated result, such as Q&A, summarization, and information roundups.

    The second is the standalone API path: developers orchestrate the flow of “retrieve first, then filter, then feed to the model” themselves, where retrieval and fetching are explicit steps billed per successful call. Its traits are “white box, controllable, reusable retrieval results,” making it suitable for scenarios that need the raw document list, secondary ranking, or building a private knowledge base index.

    The two paths are not mutually exclusive. A mature approach usually defaults to the built-in path to reduce complexity and cost, and only switches to the standalone API when raw results are needed, when retrieval must be reused across models, or when retrieval sources must be strictly audited.

    3. The Cost Model: How to Do the Math Under Token Billing

    In the per-call billing era, the focus of cost optimization was “call retrieval a few fewer times.” In the token billing era, the focus shifts to “stuff a little less into the context.” A simplified model can be used to estimate this:

    1. Cost per request ≈ (system prompt + retrieved snippets + user question) × input price
    2. + generation length × output price

    The retrieved snippets are often the biggest variable. Stuffing 5 to 10 full web pages into a single web-connected Q&A request can easily add thousands or even tens of thousands of input tokens. So the first lever for cost optimization is not “how many retrievals” but “how much content to keep per retrieval.”

    A practical budgeting formula:

    1. Monthly cost ≈ daily requests × avg input tokens × input price × 30
    2. + daily requests × avg output tokens × output price × 30
    3. + standalone API calls × per-thousand price / 1000

    Monitoring “average input tokens” as a core metric reflects the real bill better than monitoring call counts.

    4. Context Engineering: Compress Retrieved Content to “Just Enough”

    Since retrieved content counts directly toward input tokens, you need a “post-retrieval processing” pipeline rather than dumping whole page bodies into the context.

    1) Extract first, then summarize. Score the fetched body by paragraph, keep only the few segments most semantically relevant to the question, and discard the rest.
    2) Structured compression. Convert the body into a structure of “title + bullet points + key figures,” which usually compresses the volume by more than 50% while retaining the main information.
    3) Deduplication and near-duplicate merging. Multiple sources often reprint the same content; merge them by text similarity to avoid being billed repeatedly for the same fact.
    4) Layered context. Keep the system prompt concise and stable, and put retrieved content in a replaceable context zone to make cache hits easier.

    Illustrative code (pseudo-implementation, expressing the flow only):

    1. def build_context(question, docs, budget=2000):
    2. ranked = rank_by_relevance(docs, question)
    3. picked, used = [], 0
    4. for d in ranked:
    5. snippet = compress(d.body, keep_points=3)
    6. if used + count_tokens(snippet) > budget:
    7. break
    8. picked.append(snippet)
    9. used += count_tokens(snippet)
    10. return "\n\n".join(picked)

    5. Caching and Reuse: Reduce Repeated Work to Zero

    Web-connected scenarios are highly repetitive: the same batch of hot questions and the same batch of documents get queried over and over. Caching is the most direct way to cut costs, in three layers:

    • Retrieval result cache: key on “query terms + time window,” cache the document list and body snippets, and set a reasonable TTL to balance freshness and hit rate.
    • Context prefix cache: put the stable system prompt and fixed background at the front of the request, and use the server’s implicit prefix reuse to reduce repeated input overhead.
    • Result cache: cache final answers for high-frequency Q&A directly, so a cache hit skips the model call entirely.

    In engineering terms, it is advisable to design the cache key to include a “freshness level” field: short TTL for breaking-news content, long TTL for evergreen knowledge.

    6. Stability: Rate Limiting, Backoff, and Fallback

    The original text mentioned that the service had previously adjusted its rate limiting, which suggests that the web-connected path must be designed on the assumption that “it will be rate limited.”

    • Exponential backoff + jitter: on 429 or 5xx, retry with base * 2^n + jitter to avoid a synchronized retry storm.
    • Concurrency gate: use a semaphore or token bucket on the client to limit in-flight requests and prevent maxing out the quota and taking the whole system down.
    • Fallback strategy: when retrieval fails, fall back to “answer from model knowledge only,” and clearly tell the user the result may not contain the latest information.
    • Timeout budget: set separate timeouts for retrieval, fetching, and generation, and make priority trade-offs within the total budget; rather retrieve less than time out.
    1. Retry policy example: at most 3 retries, base=500ms, cap 8s, retry only idempotent read requests

    7. Observability: Treat Tokens as a First-Class Metric

    In the token billing era, observability dashboards should be built around tokens:

    • Input/output token distribution per request, split by business line, API, and tenant;
    • Average retrieved snippet length, hit rate, and discard ratio;
    • Cache hit rate and estimated tokens saved by caching;
    • Cost per request, daily cost, and budget watermark alerts.

    With these metrics, you can answer “why did this month’s bill go up” instead of guessing.

    8. Working with General Cloud Capabilities

    In practice, the above capabilities are usually assembled onto general cloud product categories: use object storage to hold fetched bodies and cache snapshots; use a message queue to smooth peaks and serialize fetching tasks; use a container platform to run post-retrieval processing and retry workers; and use logging and monitoring/alerting services for token cost accounting and rate-limit warnings. Baidu AI Cloud offers corresponding capabilities in these general categories and they can be combined as needed, but specific parameters and specifications should be based on the official documentation.

    9. Common Pitfalls

    1) Assuming “free web access” means “free overall.” Retrieval is free, but tokens are still billed, and long context is the main cost.
    2) Stuffing whole page bodies into the context. This is the most common waste under token billing.
    3) Ignoring the per-call fees of standalone APIs. If you build your own retrieval orchestration, the per-thousand price multiplied by call volume can far exceed token costs.
    4) No backoff or fallback. When rate limiting hits, the whole chain collapses.
    5) Cache keys without freshness. This leads to stale answers or caches that never hit.

    10. Summary

    The essence of this billing change is moving the cost of web retrieval from “per call” to “per token,” shifting the optimization focus from “call count” to “context quality.” The developer’s checklist is clear: distinguish the boundary between built-in retrieval and standalone APIs; use post-retrieval processing to compress context; use three-layer caching to improve hit rate; use backoff and fallback to ensure stability; and use token-dimension observability to guard the budget. Do these things, and the cost of web-connected capabilities is both controllable and predictable.