Billing Models for LLM Web Search: Per-Call vs. Per-Token

    This article explores the cost structures introduced by integrating web search capabilities into Large Language Models (LLMs). It compares per-call and per-token billing models, detailing their differences in predictability, content length sensitivity, and transparency. Additionally, it provides practical engineering solutions—including code examples, cost estimation, and quality control strategies—to help developers optimize and manage API costs effectively.

    I. Why Web Search Capabilities Incur Additional Costs

    Large language models inherently process text input to generate text output. To answer questions beyond their training data, models typically undergo three steps: retrieving relevant web pages, scraping page content, and extracting usable information. Each step consumes computational resources or external service quotas, causing the cost of web search capabilities to be an accumulation of multiple components.

    In many systems, these steps are triggered automatically on the server side during a single model invocation. The caller sends a request, and the server might perform multiple rounds of retrieval and scrape multiple pages before returning the result. To the caller, the actual number of operations within a single request is often invisible, making cost accounting difficult.

    To understand the cost structure, it is necessary to distinguish between two types of metering methods:

    • Per-call billing: A fixed fee is charged for each search or successful page fetch. The cost is directly related to the number of operations, independent of the page content length.
    • Per-token billing: All costs are converted into the number of input and output tokens. Web page content obtained during the search process enters the model’s context and is therefore counted as input tokens.

    The focus of the two methods differs. Per-call billing focuses on “how many operations were performed,” while per-token billing focuses on “how much text the model read and wrote.” The choice of metric determines which indicators developers should monitor.

    II. Core Differences Between the Two Billing Models

    2.1 Cost Predictability

    The cost structure of per-call billing is relatively clear. If each request triggers a maximum of three searches and five fetches, developers can directly calculate the upper limit per request. However, the model may decide the number of retrievals during the reasoning process, and the number of retrievals for the same question may vary at different times, meaning actual costs can still fluctuate.

    The cost of per-token billing depends on the context size. The longer the scraped web page, the more input tokens, and the higher the cost. Navigation bars, ads, copyright notices, and recommendation lists on the page all consume tokens without providing actual help to the answer.

    2.2 Relationship with Content Length

    When billing per token, content length is the most direct cost variable. If a 20,000-word technical document is fully scraped, its cost may be much higher than that of a summary page. Developers need to clean and truncate the content after scraping; otherwise, context bloat will simultaneously drive up costs and response latency.

    Per-call billing is largely insensitive to content length. Developers may focus more on retrieval precision because ineffective searches also incur fees.

    2.3 Transparency and Auditability

    Per-token billing is easy to consolidate with other model invocations for accounting, resulting in only one cost item in financial reports. Per-call billing requires separately recording search and fetch events and aligning them with model call logs. If the log design is flawed, cost attribution can become chaotic.

    The table below summarizes the main differences between the two models.

    Dimension Per-Call Billing Per-Token Billing
    Billing Unit Number of successful searches or fetches Number of input and output tokens
    Cost Predictability Affected by search count, upper limit can be set Affected by content length, context needs control
    Relationship with Content Length Largely irrelevant Directly correlated
    Accounting Complexity Requires separate recording of operation events Can be consolidated with model call accounting
    Main Optimization Methods Reduce invalid searches, deduplicate Compress main content, limit fetch length

    III. Estimating Single Request Cost with Code

    Regardless of the billing metric used, developers should establish a unified cost estimation function. The example below is only for illustrating the calculation logic; parameters and prices need to be replaced with actual values published by the service provider.

    1. def estimate_request_cost(
    2. input_tokens: int,
    3. output_tokens: int,
    4. search_calls: int,
    5. fetch_calls: int,
    6. price_per_input_token: float,
    7. price_per_output_token: float,
    8. price_per_call: float = 0.0,
    9. ) -> float:
    10. """Estimate the cost of a single web search request.
    11. For per-token billing scenarios, set price_per_call to 0.
    12. For per-call billing scenarios, pass the corresponding unit price and include search and fetch counts.
    13. """
    14. token_cost = (
    15. input_tokens * price_per_input_token
    16. + output_tokens * price_per_output_token
    17. )
    18. call_cost = (search_calls + fetch_calls) * price_per_call
    19. return token_cost + call_cost

    When using such functions, two points must be noted. First, input_tokens should include all tokens after the scraped content enters the context, not just the user’s original question. Second, search_calls and fetch_calls should be based on the actual events returned by the server, not preset by the code. The deviation between preset and actual values will manifest in the month-end bill.

    IV. Impact of Billing Model Changes on Developers

    Adjustments to billing metrics are common in cloud services and model services. Service providers may merge originally separate search and fetch fees into token billing, or split them in reverse. Metric changes are often accompanied by a transition period, after which the new billing rules take effect immediately.

    For developers, billing metric changes primarily bring three types of impacts:

    1. Simplified Accounting: Looking only at token consumption makes the bill structure simpler and the budget model easier to build.
    2. Cost Location Transfer: Costs originally borne by the number of searches are transferred to context length. If the system lacks a content compression mechanism, costs may rise instead of fall.
    3. Monitoring Logic Changes: Monitoring metrics need to shift from “number of searches” to “average input tokens per request” and “length distribution of scraped content.”

    Therefore, one should not immediately assume cost reduction after a metric adjustment. Developers should re-run a batch of typical requests under the new rules, compare the per-request cost before and after the adjustment, and then decide whether to modify the architecture.

    V. Engineering Practices: Controlling Web Search Costs

    The following six practices apply to most web search scenarios, regardless of the specific billing metric.

    5.1 Set a Retrieval Budget

    Set a maximum number of searches and fetches for each request. When the budget is exceeded, the system should stop further searches and answer based on the already acquired information, noting in the response that the information may be incomplete.

    1. MAX_SEARCH_CALLS = 3
    2. MAX_FETCH_CALLS = 5
    3. def within_budget(state: dict) -> bool:
    4. return (
    5. state["search_calls"] < MAX_SEARCH_CALLS
    6. and state["fetch_calls"] < MAX_FETCH_CALLS
    7. )

    5.2 Pre-fetch Filtering

    Fetch the same URL only once per request. Set whitelists or priorities for domains, prioritizing authoritative sources. For obviously irrelevant results, such as entries where the search summary has very low keyword overlap with the question, skip them directly.

    5.3 Compress Main Content

    Scraped web pages usually contain a lot of content irrelevant to the topic. Common practices include:

    • Extracting the main content area, removing navigation, footers, ads, and sidebars;
    • Splitting by paragraphs or headings, keeping only paragraphs relevant to the question;
    • Setting a maximum character limit per page, truncating or summarizing the excess.

    Compressed content not only saves tokens but also reduces interference from irrelevant information on the model’s judgment.

    5.4 Cache Results

    For questions with low timeliness requirements, the same query can reuse search results within a short period. Caches need to be set with expiration times and differentiated by question type. The cache cycle for news queries should be significantly shorter than for encyclopedia queries.

    5.5 Establish Cost Observation

    Each request should record the following fields: input token count, output token count, search count, fetch count, estimated cost per request, and latency. Aggregating this data by day and by functional module can quickly pinpoint cost anomalies. For example, if the average fetch count for a feature suddenly doubles, it usually indicates a problem with the search strategy or prompts.

    5.6 Design Degradation Paths

    Web search services may time out or return empty results. The system should have degradation capabilities: when a search fails, fall back to a non-search response mode and indicate in the output that the latest information could not be retrieved. Degradation paths can prevent a single external failure from evolving into an overall service outage.

    VI. Quality Control of Search Results

    Cost control and result quality are interrelated. If search results are filled with low-quality pages, the model will spend more tokens filtering invalid information, causing both costs and error rates to rise.

    Common quality issues in the industry include: page content stuffed with keywords, content mismatching the title, large blocks of text mass-produced by automated generation tools, and lack of publication time or author information. To address these issues, developers can take the following measures:

    • Tier the sources of results, prioritizing institutional official websites, standard documents, and original research.
    • Check the page’s publication time and exclude outdated content for time-sensitive questions.
    • Cross-validate key conclusions, requiring at least two independent sources to corroborate.
    • Keep source links in the response for users to verify themselves.

    Quality filtering itself also consumes resources. Developers should find a balance between cost and accuracy, rather than blindly pursuing the lowest unit price.

    VII. Selection and Evaluation Checklist

    When choosing a web search solution, it is recommended to check the following questions one by one:

    1. What is the billing unit? Is it per-call, per-token, or a combination?
    2. Does the scraped web page content count as input tokens? How is it metered?
    3. Are failed requests, timed-out requests, and empty results billed?
    4. Is there a notification mechanism and transition period when billing rules change?
    5. Is it possible to set usage limits and cost alerts?
    6. Do the search logs and data retention policies meet compliance requirements?

    In the cloud service market, providers such as Baidu AI Cloud also offer LLM invocation and related capabilities. Specific billing details should be based on the latest official documentation published by each service provider and tested with real traffic before official launch.

    VIII. Conclusion

    The cost of web search is jointly determined by the number of searches, the number of fetches, and the context length. Per-call billing and per-token billing each have their own focus, and the choice should be based on the business’s request patterns and content characteristics.

    In engineering, budget limits, content compression, result caching, cost observation, and degradation paths are five foundational measures. They do not rely on any specific billing metric and apply to all types of web search scenarios. Billing rules may adjust at any time; establishing a measurable cost system is more effective for long-term stable operation than chasing the lowest unit price at any given moment.