Server-Side Web Search for LLMs: An Engineering Guide

    This article walks through the engineering practice of running web search and page reading on the LLM server side instead of in your own application. It covers why frozen model knowledge needs an external fact source, three preparation steps (protocol compatibility, client initialization, and context injection), how to declare server-hosted tools in the request, how to parse the tool-call trace and track billing, six production requirements, and guidance on when server-side retrieval fits and when a self-built retrieval layer is still needed.

    1. Background: The Model Doesn’t Know What “Today” Is

    A large language model’s parameters are frozen once training finishes, so its internal knowledge has a hard lower bound in time. When a user asks about today’s weather, a policy released this morning, or the result of a match that just ended, the model can only rely on statistical patterns left in its training corpus to guess. The typical outcome is an answer that looks plausible but is out of date, or fabricated details when the model cannot tell. Prompt engineering cannot fix this at the root, because what is missing is not expressive ability but a source of facts.

    Engineering-wise, there are usually three paths. The first is client-side retrieval: the application calls a search service to get candidate pages, then fetches, splits, and cleans the content, and finally stitches the fragments into the prompt. This path offers the most control, but you have to maintain a whole pipeline of crawling, de-noising, rate limiting, caching, and retry-on-failure. The second is to wrap retrieval as a tool the model can call, letting the model decide when to search and what to search for, while the client only implements the tool functions. The third, and the focus of this article, is to push retrieval and page reading entirely down to the model server side: the client only declares which capabilities it needs through parameters, and the server executes them and returns the process.

    Server-side hosting delivers three benefits: client code shrinks to nearly zero, with no crawler or parsing pipeline to maintain; the model decides when to retrieve, which cuts wasted calls; and the execution process comes back in a structured form, making it observable and auditable by nature.

    2. Three Preparation Steps Before Integration

    2.1 Protocol Compatibility and Interface Shapes

    Enterprises often run several technology stacks at once. Some teams stick with interface conventions centered on chat completions, some use a message-list-plus-tool-declaration shape, and others need finer-grained step-by-step execution semantics. So during selection, confirm that the target service is compatible with both mainstream industry interface protocols and covers three interface shapes: chat completions, stepwise responses, and message orchestration. The direct payoff is that the same business code can move between teams, and SDK dependencies are not locked into a single ecosystem.

    Model naming needs to be unified early as well. Abstracting the capability identifier into a fixed model alias, rather than scattering concrete version numbers everywhere, makes later capability upgrades invisible to the business.

    2.2 Dependencies and Client Initialization

    Take the most common Python ecosystem as an example: after installing the official client library, you only need two things at initialization, the API key and the base URL. The key must come from an environment variable or a key management service, and must never be hardcoded into the repository.

    1. import os
    2. from openai import OpenAI
    3. client = OpenAI(
    4. api_key=os.environ["LLM_API_KEY"],
    5. base_url=os.environ["LLM_BASE_URL"],
    6. )

    2.3 Context Injection: Giving the Model a Time and Place

    When a user asks “Is it a good day to go out?”, the model needs two implicit premises: the current date and the user’s city. A reliable approach is to insert a system-level reminder message at the head of the message list, describing the time, location, usage scenario, and language preference in structured text. This message is not counted for billing and does not affect role ordering in multi-turn conversations, but it determines the quality of the retrieval keywords the model constructs. Without city information, the model can often only search for “weather today,” and the geographic relevance of the results drops noticeably.

    3. Core Implementation: Declaring Server-Side Tools

    The key difference shows up in the request parameters. Traditional tool calling requires the client to supply a function list, execute the functions, and feed the results back to the model. In the server-hosted model, you only declare the tool types in the request, and the model orchestrates the call order itself.

    1. resp = client.chat.completions.create(
    2. model="deepseek-flash",
    3. messages=[
    4. {"role": "latest_reminder",
    5. "content": "2026-11-14,Saturday,Shanghai,Web,Chinese"},
    6. {"role": "user",
    7. "content": "What's the weather in Shanghai today? Is it a good day to go out? Keep it short"},
    8. ],
    9. tools=[
    10. {"type": "deepseek_web_search"},
    11. {"type": "deepseek_read_url"},
    12. ],
    13. extra_body={"thinking": {"type": "disabled"}},
    14. )

    The division of labor between the two tools needs to be clear: the search tool expands a natural-language query into several keywords and submits the search, returning candidate links; the reading tool fetches the body of a given link and extracts usable passages. The former solves “where to look,” the latter solves “how to read what you found.” For time-sensitive questions, the model usually searches first and then deep-reads two or three selected links; for a summarization task where the user supplies a link directly, only the reading tool is triggered.

    Disabling thinking mode is a practical detail. Simple factual Q&A does not need long-chain reasoning, and turning it off noticeably shortens time to first token, leaving the budget for genuinely complex tasks.

    4. Parsing Results and Observing the Process

    Besides the final text, the response body contains the full trace of server-side tool calls. Iterating over this trace shows which queries the model constructed and which addresses it read, so you can judge whether the retrieval strategy is reasonable.

    1. msg = resp.choices[0].message
    2. print(msg.content)
    3. for step in msg.model_extra["server_tool_calls"]:
    4. for call in step["calls"]:
    5. print("TOOL", call["kind"],
    6. call["action"].get("queries") or call["action"].get("url"))
    7. print("Billing count:", resp.usage.model_extra["server_tool_use"])

    Two engineering points matter here. First, extension fields do not have strong type definitions in every SDK version, so reading them through the model extension mapping is safer, and null protection is needed. Second, the billing unit is separate from conversation turns: text generation is metered by tokens, while each server-side search or page read is metered per call. Only by landing this field in logs and monitoring alerts can you quickly pinpoint which business scenario is inflating call volume when costs spike.

    5. Six Things Production Requires

    • Timeouts and retries: the retrieval path depends on external sites, so set an overall timeout and apply limited backoff retries to idempotent queries.
    • Result caching: cache briefly using the normalized query plus city as the key, which lowers both latency and call count.
    • Fallback: when server-side retrieval is unavailable, fall back to a plain model answer without tools, and clearly tell the user the information may be out of date.
    • Citations and compliance: show source links alongside the answer, respect the target sites’ access rules, and avoid overstepping on caching and redistribution.
    • Prompt injection protection: page bodies are untrusted input, so the system prompt must constrain the model to treat them as material rather than instructions.
    • Observability: collect tool-call traces, latency, and billing counts into your logging service and monitoring/alerting system to form a traceable audit chain.

    6. Capability Boundaries and Selection Advice

    Server-hosted retrieval fits time-sensitive Q&A, market and weather lookups, link summarization, and competitor activity tracking, with the advantage of extremely low integration cost. But it is not a cure-all: queries that need to reach internal systems cannot be served by public web search, scenarios with strict source allowlists still need a self-built retrieval layer, and the marginal cost at very large call volumes needs to be estimated up front.

    So a combined strategy is recommended: route simple, high-frequency, strongly time-sensitive requests to the server-hosted capability, keep requests involving internal data and strict permissions on the self-built path, and converge both behind a unified tool abstraction layer. This gives you the efficiency of low-code integration while retaining control over critical paths, and lets you make quantifiable tradeoffs among cost, latency, and accuracy.