LLM API Billing Changes and Cost Management for Search and Web Fetching
This article breaks down a recent LLM API billing change that moves server-side search and web fetching triggered inside model calls from per-request charges to token-based billing, while standalone search and fetch APIs remain billed per successful request. It explains the difference between token-based and per-request cost models, proposes a three-layer architecture for routing retrieval through the model call chain, and provides a practical cost-control checklist covering context budgets, result trimming, caching, quotas, retries, and observability. Readers will also find guidance on cost attribution, regression testing to balance task pass rate against cost, and fallback mechanisms for reliability.
1. Background: A Refinement of Billing Scope
A cloud provider recently refined the billing scope for its LLM API. Starting in mid-November, server-side search and web fetching triggered during model calls are no longer billed separately per request; developers pay only for the tokens the model actually consumes. Importantly, this change is explicitly limited to retrieval and fetching automatically triggered inside the model call chain. It does not cover search and fetching capabilities offered as standalone APIs, which are still billed per successful request, typically at a rate of a few yuan per thousand successful requests.
Around the same time, an open-source AI agent framework released a pre-release version that switched its default retrieval strategy: when the underlying model comes from the same provider, it uses the provider’s built-in server-side retrieval by default, with no per-request charges; when switching to another model, it falls back to the standalone retrieval API, billed according to the API’s rules.
Taken together, these two developments point to a clear conclusion: the billing boundary is shifting from a feature dimension to a call-chain dimension. The same retrieval behavior has a completely different cost structure depending on whether it happens inside a model call or as a separate application-side API call. For developers, this is both a cost-reduction opportunity and a new architecture governance challenge.
2. Understanding the Billing Models: Token-Based vs. Per-Request
To understand this change, start by distinguishing two cost models.
The first is token-based billing. It measures the volume of input and output text, and is continuous, cumulative, and strongly correlated with context length. The longer the context and the more turns in a conversation, the higher the cost per request.
The second is per-request billing. It counts successful requests, and is discrete, tiered, and strongly correlated with call frequency. Fetching ten thousand pages in one batch causes costs to grow almost linearly.
The key difference is this: under token-based billing, once retrieved content enters the context, it inflates the input cost of every subsequent turn; under per-request billing, the retrieval cost is one-time, but it stacks up quickly as task concurrency rises.
This leads to a practical principle: converge retrieval and fetching into the model call chain as much as possible, so that one-time retrieval costs are absorbed into token costs. At the same time, strictly control the volume of retrieved content entering the context to avoid the hidden expense of “free retrieval, expensive context.”
3. Impact on Application Architecture: Layer the Call Chain
The billing change directly affects architecture layering. It is recommended to divide capabilities into three layers:
- Interaction layer: handles session management, input preprocessing, and sensitive information filtering.
- Orchestration layer: handles tool selection, retrieval triggering, result trimming, and context assembly.
- Model layer: handles inference and generation, billed by tokens.
Retrieval and fetching should be pushed down as far as possible to the boundary between the orchestration layer and the model layer, triggered automatically by the model call, rather than initiated in the interaction layer as a separate API call for every user request. Example code:
# Bad example: the application triggers retrieval separately for each turn,# incurring per-request charges and context bloatdef bad_flow(query, history):docs = search_api(query, top_k=20) # billed per requestcontext = history + concat(docs) # context keeps expandingreturn model.generate(context)# Good example: retrieval is triggered inside the model call chain,# billed by tokens onlydef good_flow(query, history):context = trim(history, max_tokens=2000) # trim history firstreturn model.generate_with_builtin_search(query=query,context=context,max_search_results=5, # limit the volume fed back)
4. Cost Governance Checklist: From Passive Payment to Active Control
After the billing rule change, work through the following checklist item by item:
- Call layering: distinguish “triggered inside the chain” from “standalone API calls,” and prefer the former.
- Context budget: set an input token limit per request, and use a sliding window or summary compression for history.
- Retrieval result trimming: limit the number of items and the length of each item fed back into the context; rerank before truncating so noise does not consume the budget.
- Cache reuse: build a result cache for high-frequency queries, skipping retrieval and repeated inference on a cache hit.
- Quotas and rate limiting: set requests per minute and daily token quotas at the gateway to prevent abnormal amplification.
- Retry strategy: apply exponential backoff only to retryable errors to avoid stacking invalid requests and charges.
- Observability: instrument each request to record input/output tokens, retrieval counts, and cache hit rate, and build a cost dashboard.
Caching and quotas are the two most easily overlooked items. Caching reduces repeated spending to zero, and quotas cap runaway spending within a threshold. Together they cover most burst-traffic scenarios.
5. Observability and Cost Attribution
Cost governance starts with visibility. Collect at least three categories of metrics: token metrics, including input, output, and cached tokens; retrieval metrics, including trigger counts, success rate, and average volume fed back; and business metrics, including cost per session, cost per task, and active session count.
For attribution, use four-level tagging by environment, model, business line, and caller, so the source of abnormal growth is easy to locate. When cost per session spikes, it can usually be attributed to one of three causes: untrimmed history inflating input, unlimited retrieval results making the context too long, or a retry logic defect causing duplicate calls.
6. Maintaining Quality and Managing Risk
Cost reduction must not come at the expense of collapsing quality. The recommended approach is to build an offline evaluation set and run regression checks on every strategy adjustment, such as trimming thresholds, retrieval item counts, and cache duration. Track two curves, task pass rate and average cost per task, and look for the Pareto optimum. In industry practice, capability improvements often come with higher cost per task, so an explicit tradeoff between the highest pass rate and average cost is needed rather than looking at a single metric.
Also build fallback mechanisms: when built-in retrieval is unavailable, automatically degrade to the standalone API and flag the cost change; when the token budget is exhausted, return an explicit error code rather than silently truncating, so results remain explainable.
7. Combining with Baidu AI Cloud Capabilities
In a general cloud architecture, this kind of cost governance can typically be implemented with standard capabilities: use a container platform to host orchestration services with elastic scaling, use a message queue to smooth concurrent retrieval, use object storage to store evaluation sets and cache snapshots, and use logging and monitoring with alerts to build a cost dashboard and threshold alerts. Baidu AI Cloud offers corresponding products in these general categories, and developers can choose based on their own tech stack. The core principle is to keep the billing scope consistent with the architecture layering.
8. Conclusion
The signal from this billing change is clear: the cost of retrieval and fetching is converging into the model call chain. Developers should complete three things as soon as possible: map out the call-chain layering, establish context and retrieval budgets, and fill in cost observability. Doing these three things lets you benefit from the refined billing scope and stay architecturally flexible when rules change again.
