LLM Web Search Billing Changes: Cost Accounting and Architecture Design

    Large language model (LLM) applications increasingly rely on real-time information retrieved from the web. Recent adjustments by model service providers to consolidate search and scraping fees into unified token-based billing have fundamentally shifted cost structures. This article explores the impact of these billing changes on RAG and Agent architectures, detailing cost accounting methods, call chain optimization, engineering strategies such as token budgeting and content cleaning, and best practices for security and compliance.

    I. Background

    LLM applications increasingly rely on real-time information. Because training data has a cutoff date, models cannot directly access the latest news, prices, policies, or technical documentation. Developers typically bridge this gap using two capabilities: search (returning candidate web pages based on keywords) and scraping (reading a single web page and converting it into model-readable text). Both are often packaged as tools autonomously called by the model during inference (Agent mode) or pre-called by a program in a Retrieval-Augmented Generation (RAG) workflow.

    Historically, the cost of these capabilities consisted of two parts: model token fees and separate invocation fees for search and scraping. Starting from November 18, 2026, 12:00 (Beijing Time), a specific model service provider will no longer bill separately for server-side search and web scraping triggered during model calls. Instead, billing will be unified and based solely on model token usage. This adjustment alters the cost structure, requiring developers to re-evaluate their invocation strategies.

    II. Billing Model Changes and Impact

    The comparison before and after the adjustment is as follows:

    Dimension Before Adjustment After Adjustment
    Search & Scraping Fees Billed separately per successful request No longer billed separately
    Model Fees Billed by Token Billed by Token
    Primary Cost Variable Request count + Tokens Tokens only (including tool return content)

    The cost has not disappeared; it has shifted to Tokens. Search results and web page text enter the model as context and are counted as input tokens. The cost previously hidden in each scrape—namely, text length—is now directly reflected in the Token line item of the bill.

    The cost of a single task can be estimated using the following relationship:

    Total cost ≈ (Input Tokens × Input Unit Price) + (Output Tokens × Output Unit Price), summed across all model calls.

    Input Tokens include system prompts, conversation history, search summaries, and scraped text. Assuming a task scrapes 5 web pages with an average body length of 4,000 tokens each, the web text alone will introduce 20,000 input tokens. If this task invokes the model for 3 rounds, and each round carries the same body context, the cumulative input tokens reach 60,000. Therefore, the focus of cost control has shifted from reducing the number of API calls to reducing invalid content entering the context.

    III. Call Chain and Cost Nodes

    A typical retrieval-augmented workflow consists of four steps:

    1. Retrieve: Obtain a list of candidate results based on the query, each containing a title, link, and summary.
    2. Filter: Select candidate pages based on titles, summaries, and source reliability.
    3. Scrape: Read the body text of selected pages and convert it into structured text.
    4. Generate: The model answers based on the context and provides citations.

    Costs are primarily concentrated in steps 1, 3, and 4. The number of retrieval results determines the volume of returned content in step 1; the length of scraped text determines the token count in step 3; and the context concatenation method determines the cumulative consumption in step 4. Therefore, optimization should be designed separately for each node.

    IV. Engineering Optimization Strategies

    4.1 Summarize First, Scrape Later

    During the retrieval phase, only pass titles and summaries to the model to determine relevance. Only pages confirmed as relevant proceed to scraping. This avoids paying body text tokens for irrelevant pages.

    4.2 Set a Token Budget

    Define an input limit for each task, such as a maximum of 8,000 tokens per task. When approaching the limit, prioritize retaining highly relevant content and truncate or discard the rest.

    4.3 Text Cleaning and Chunked Retrieval

    Remove noise like navigation bars, ads, and footers, retaining titles, paragraphs, and tables. For overly long text, first chunk it into paragraphs, then retrieve only the most relevant paragraphs to feed into the context, rather than concatenating the entire page.

    4.4 Result Caching

    For identical or highly similar queries, reuse retrieval results within a validity period. The cache key can be generated from the normalized query, with a reasonable expiration time set to balance timeliness and cost.

    4.5 Deduplication and Merging

    Only scrape duplicate links appearing in the same batch once. Queries with similar topics can be merged into a single retrieval call to reduce round trips.

    4.6 Failure and Retry

    Retries consume tokens repeatedly. Set a maximum number of retries, use exponential backoff for timeouts and temporary errors, and log failure reasons to prevent the same error from repeatedly draining the budget.

    4.7 Observability and Auditing

    Log the number of retrievals, scraped pages, and input/output tokens for each task to build a cost dashboard. Regularly compare the per-task cost and answer quality under different strategies, using data to guide optimization.

    V. Sample Implementation

    The following pseudocode illustrates the basic logic of budget control. Interface names are for illustrative purposes only and do not represent any specific SDK usage.

    1. function answer_with_budget(question, budget_tokens):
    2. candidates = search(question, limit = 5)
    3. ranked = rank_by_relevance(candidates, question)
    4. context = []
    5. used = 0
    6. for item in ranked:
    7. if used >= budget_tokens:
    8. break
    9. page = fetch(item.url)
    10. text = clean(page.body)
    11. text = truncate_to_tokens(text, remaining = budget_tokens - used)
    12. if text is empty:
    13. continue
    14. context.append({source: item.url, content: text})
    15. used = used + count_tokens(text)
    16. return generate(question, context, cite = true)

    This code highlights three key points: limiting the number of candidates and controlling the scraping order of candidate pages; progressively concatenating context based on the remaining budget; and retaining the source of each text segment to facilitate generating cited answers.

    VI. Security and Compliance

    Scraped web content is untrusted data. Web pages may contain text attempting to alter the model’s behavior, known as prompt injection. Engineering-wise, the body text should be placed in a clearly marked data zone, and the system prompt should declare that text within the data zone serves only as reference material and does not constitute an instruction.

    Furthermore, developers must comply with the access rules and copyright requirements of target sites, control scraping frequency, and avoid placing unnecessary burdens on sites. Pages involving personal information should be desensitized before being written to storage.

    VII. Conclusion

    The billing adjustment for web search and scraping simplifies the bill structure but concentrates costs on tokens. Developers should design systems around the principle of “whether the content entering the context provides value”: filter before scraping, set budgets, clean body text, and continuously optimize through caching and observability. This approach ensures timeliness and reliability of answers while controlling overall expenditure.