LLM Web Search Billing Changes: Token Costs and Engineering Practices
A recent billing change in the AI industry moves the cost of built-in web search into token billing, while standalone search and crawling APIs remain billed per successful request. This article explains the cost structure of both retrieval paths and covers routing design, quota and rate-limit handling, and optimization techniques such as caching, deduplication, compression, and reranking. It ends with a launch checklist for developers.
1. Problem Background: Web Search Is Shifting from an Add-On Call to a Context Cost
There are two common ways to add web search to an LLM application. The first is built-in server-side search, provided by the platform. The application makes a single model call, and the platform triggers the search and page fetching on the server side. It then injects the retrieved results into the model’s context. The second is standalone search and crawling APIs. The application calls a search API explicitly to get documents, compresses and filters them itself, adds them to the prompt, and then calls the model to generate the answer.
A recent billing change in the industry is worth watching. For built-in search triggered during a model call, the platform no longer charges separately per search or fetch. Instead, the context consumed by the retrieved results counts toward token billing. If developers call standalone search or fetch APIs directly, they are still billed per successful request.
This change does not make web search free. It moves cost from the per-call fee to the context token fee. For developers, the key is not memorizing one rule. The key is understanding the cost structure, quota constraints, and engineering impact of each path.
2. Cost Model: Where Token Billing Meets Per-Call Billing
The total cost of one web-enabled question and answer can be expressed as:
total cost = input token cost + output token cost + standalone search request fee + standalone fetch request fee
In built-in mode, the search request fee may be zero, but the retrieved results are added to the input context as tokens. In standalone mode, search and fetch are billed per successful request. The application can control how many tokens reach the model through truncation, summarization, and deduplication.
Let p_r be the fee for one standalone search request, p_f the fee for one fetch request, t the average number of tokens that retrieval injects into the context, and q_in the input token price. The approximate costs of the two paths are:
built-in search cost ≈ t × q_instandalone search cost ≈ p_r + p_f + t' × q_in
Here t' is the average token count after the application compresses and filters the standalone results.
When queries are short, results are few, and token prices are low, built-in search may be simpler. When you need batch fetching, structured collection, long-term caching, or fine-grained control over context, standalone APIs make cost governance easier.
These formulas are a general cost framework. They do not reflect the actual prices of any platform. Base real decisions on your own traffic, average context length, cache hit rate, and platform quotas.
Maintain a cost estimation function in your application, and make the retrieval mode a configurable option instead of hard-coding it into business logic:
function estimate_cost(mode, query_count, avg_context_tokens, cache_hit_rate):if mode == "builtin":return query_count × (1 - cache_hit_rate) × avg_context_tokens × input_token_priceif mode == "standalone":return query_count × standalone_search_price+ query_count × fetch_ratio × fetch_price+ query_count × (1 - cache_hit_rate) × compressed_tokens × input_token_price
The value of this function is that it isolates billing changes in the configuration layer. When the platform changes its billing, you only need to re-evaluate the parameters. The call chain itself stays mostly unchanged.
3. Tool Defaults and Routing Design: Don’t Let Defaults Decide Your Bill
Development tools, orchestration frameworks, and AI coding tools often set a default retrieval method when they connect to a model. If these defaults are not transparent, two problems can occur. First, a developer may assume built-in search is in use when the system actually calls a standalone API, which adds per-call fees. Second, when a developer uses another model or a custom pipeline, retrieval and fetch strategies may not be configured explicitly, so costs drift from expectations.
A safer approach is an explicit routing layer that takes model capability, retrieval mode, fetch requirements, and budget limits as inputs:
function handle_query(q, config):if config.retrieval_mode == "builtin" and config.model_supports_builtin_search:r = model_call(input=q, enable_web_search=true)return r.answer, billing_tag="Token"else:docs = standalone_search(q)docs = deduplicate(docs)docs = truncate_and_summarize(docs, config.max_context_tokens)r = model_call(input=q + docs)return r.answer, billing_tag="Token+per-call"
The routing layer should also support fallback. When the standalone search API hits rate limits or its error rate rises, the system can switch to built-in search for a short period. When built-in search context grows too long, the system can switch to a two-stage pipeline: retrieve first, compress second, then generate. Every fallback should produce logs and cost tags so that costs can be traced afterward.
4. Quotas, Rate Limits, and Stability: Retrieval Pipelines Need Circuit Breakers
Web search does not run in isolation. It depends on model-side quotas, search API quotas, fetch concurrency, content safety policies, and the availability of downstream websites. When platform quotas or rate-limit policies tighten, time to first byte and success rate are directly affected. At a minimum, engineering should do the following:
- Separate timeouts from retries: Set timeouts separately for search, fetch, and model generation. Apply exponential backoff only to retryable errors, so that retry storms do not multiply per-call fees.
- Circuit breaking and degradation: When the retrieval success rate falls below a threshold, fall back to cached results or to an answer without retrieval. State the time limitations of the information in the answer.
- Queues and concurrency control: Place batch fetch tasks in a queue and smooth peak load according to budget and quotas. Give priority to interactive queries.
- Budget guardrails: Set daily budgets and per-query context caps for each tenant, application, and API. These limits prevent abnormally long documents from causing token spikes.
For observability, record each request’s retrieval mode, search count, fetch count, input and output tokens, cache hits, P95 latency, error code distribution, and cost tags.
When deploying on Baidu AI Cloud, you can use Log Service to record call chains, monitoring and alerts to track token consumption and retrieval success rates, and object storage to save reusable retrieval snapshots. The cache layer can use in-memory caching or a distributed cache service. Set reasonable expiration times and invalidation policies for either option.
5. Engineering Optimization: Caching, Deduplication, Compression, and Citations
After a billing change like this one, the optimization focus shifts from making fewer API calls to injecting less irrelevant context. Five areas deserve attention:
- Caching: Generate cache keys from normalized queries, document addresses, and time
