Integrating Web Search and Web Page Reading Tools with Large Language Model APIs: A Practical Guide

    Large language models have knowledge cutoffs, making them unreliable for questions that depend on current information. This guide explains how server-side tool calling enables real-time search and web page retrieval, covering pricing, API integration, response parsing, cost tracking, and production engineering practices.

    Integrating Web Search and Web Page Reading Tools with Large Language Model APIs: A Practical Guide

    Large language models have a knowledge cutoff. For questions such as “What is the weather today?” or “What has changed in the latest policy update?”, the model’s parametric knowledge alone may not provide a reliable answer.

    A common industry solution is to add tool-calling capabilities to the chat API. Before generating a response, the service can automatically perform web searches, retrieve web pages, and inject the resulting real-time information into the model context. The model then generates an answer based on the retrieved content.

    This article explains the general implementation pattern, including pricing, integration steps, code examples, and production engineering considerations.

    1. Why Use Server-Side Tool Calling?

    Traditional web-enabled applications typically use a client-orchestrated workflow. Developers call a search API, fetch web pages, clean the returned content, and insert the results into the prompt themselves. This creates a longer processing chain and requires additional handling for timeouts, anti-crawling mechanisms, and content extraction.

    Server-side tool calling moves this workflow into the model service:

    • The developer only needs to declare the available tools, such as web search and URL reading.
    • The model determines whether retrieval is necessary, what keywords to search for, and which pages to read.
    • The service performs the search and retrieval, then returns the generated response together with tool-call details and usage information.

    This approach significantly reduces client-side integration work and makes tool-related billing easier to track.

    2. Pricing: Model Usage and Tool Usage Are Separate

    The cost of this type of API is usually divided into two independent components. Estimate them separately when planning your budget.

    2.1 Model Token Charges

    Model input and output are typically priced per million tokens. Many providers also use time-based pricing, such as standard rates during peak business hours and discounted rates during off-peak periods. For example, a pricing tier might charge CNY 2 per million input tokens and CNY 8 per million output tokens during standard hours, with off-peak rates reduced by half.

    Two details require particular attention:

    • Web retrieval adds search results to the context, so input token usage can increase substantially. The actual cost may be much higher than that of a standard chat request.
    • When deep-thinking or extended-reasoning mode is enabled, the tokens generated during reasoning are typically included in output billing. For simple questions, explicitly disabling this mode can reduce unnecessary costs.

    2.2 Per-Call Tool Charges

    Tool usage is billed separately from token usage and is usually charged by call count. Common pricing structures include:

    • Web search and web page retrieval: charged per thousand calls, for example, around CNY 5 per thousand calls.
    • Voice capabilities, such as speech-to-text and text-to-speech: charged by duration. Newly released features may also offer limited-time discounts of approximately 50 percent.

    A basic cost estimate can use the following formula:

    1. Estimated cost per request ≈ input token cost
    2. + output token cost
    3. + tool calls × per-call price

    Combine this estimate with expected daily request volume to project monthly spending and avoid unexpected costs after launch.

    3. Integration: From API Key Creation to a Complete Request

    3.1 Create an API Key

    Start by creating an API key in the relevant provider console.

    For production engineering, use separate keys for different applications or environments, such as development, testing, and production. Inject keys through environment variables and never hard-code them in a source code repository.

    3.2 Choose a Compatible Protocol

    Many modern chat APIs are compatible with a common message-based protocol. Conversation history is passed through a messages array, while available tools are declared through the tools parameter.

    As a result, existing client code can often be migrated with only a few changes, such as updating the base_url and model. This keeps the integration effort relatively low.

    3.3 Declare Tools and Send a Request

    Install an SDK that supports the protocol, or send an HTTP request directly. The request can declare web search and web page reading tools without requiring the client to implement the tool execution logic:

    1. import os
    2. import requests
    3. resp = requests.post(
    4. "https://your-api-endpoint.example.com/v1/chat/completions",
    5. headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
    6. json={
    7. "model": "your-chat-model",
    8. "messages": [
    9. {"role": "system", "content": "Today is 2026-11-14. Location: Shanghai. Answer concisely in Chinese."},
    10. {"role": "user", "content": "What is the weather in Shanghai today? Is it suitable for going outside?"},
    11. ],
    12. "tools": [
    13. {"type": "web_search"}, # Web search
    14. {"type": "read_url"}, # Read a web page
    15. ],
    16. },
    17. )
    18. data = resp.json()
    19. message = data["choices"][0]["message"]
    20. print(message["content"])

    Several details are important:

    • Provide the current time and location: The model does not inherently know what “today” means in a particular user context. Include the current date, time zone, and user location in the system prompt or first message. Otherwise, the generated search query may be inaccurate.
    • Disable unnecessary reasoning: For simple requests such as weather queries, disabling deep-thinking mode can avoid unnecessary output-token usage.

    3.4 Parse Tool Calls and Usage Information

    A well-designed server-side implementation returns the tool-call trace and usage information in the response. Parse and record these fields consistently on the client side:

    1. # Tool-call trace; field names depend on the provider's documentation
    2. for step in message.get("server_tool_calls", []):
    3. for call in step.get("calls", []):
    4. action = call.get("action", {})
    5. print("🔍", call.get("kind"), action.get("queries") or action.get("url"))
    6. # Number of billable tool calls for this request
    7. print("Tool usage:", data.get("usage", {}).get("server_tool_use"))

    This information serves two important purposes:

    1. Observability: You can determine what the model searched for and which pages it read, making it easier to investigate the source of inaccurate answers.
    2. Cost reconciliation: By storing tool usage counts, you can aggregate tool-related spending by day and compare it with billing records.

    4. Production Engineering Recommendations

    • Cache and deduplicate requests: Add short-lived caching for frequently requested information, such as the day’s weather or exchange rates, to avoid repeatedly triggering billable searches.
    • Add budget circuit breakers: Track daily usage by application. When a threshold is exceeded, automatically fall back to a non-web model response and send an alert.
    • Provide failure fallbacks: If a search times out or page retrieval fails, instruct the model to clearly state that real-time information could not be obtained instead of fabricating an answer.
    • Integrate object storage with logging: Store retrieved page snapshots in object storage, and connect tool-call logs to a centralized logging and monitoring system for auditing and later investigation.
    • Evaluate answer quality: Before launch, prepare a real-time evaluation set with reference answers. Use it to verify whether the accuracy improvement from web retrieval justifies the additional cost.

    5. Conclusion

    Server-side tool calling packages the complex “search, retrieve, inject, and generate” workflow into a single API request. Developers only need to declare the available tools and process the returned tool-call details and usage information.

    The core integration work consists of three steps:

    1. Create an API key.
    2. Declare the required tools in the request.
    3. Parse and record tool-call details and billing information from the response.

    The more challenging part is designing a sustainable cost model. Time-based token pricing combined with per-call tool charges requires caching, circuit breakers, and usage monitoring. With these controls in place, web-enabled language model applications can remain both useful and cost-effective in production.