Server-Side Web Search for LLMs: A Practical Integration Guide

    This guide explains how to add real-time web search to large language model applications using server-side tools instead of client-side retrieval pipelines. It covers the difference between client-side function calling and server-side tools, preparation steps such as protocol compatibility, credential configuration, and explicit reasoning-mode control, plus how to declare search and URL-reading tools in a single request. You will also learn how to inject time and location context, parse the retrieval trace and billing fields from the response, and apply engineering practices for retries, caching, timeouts, citations, content safety, and cost planning.

    1. Background: Knowledge Boundaries and the Real-Time Gap

    A large language model’s parameters are fixed once training is complete, so its internal knowledge has a clear cutoff point. When users ask about today’s weather, a recent announcement, live market data, or the content of a page that just went online, the model can only rely on statistical patterns from its training data. This often produces output that sounds plausible but does not match the facts.

    The traditional workaround is to build a retrieval pipeline on the client side: call a search API to get candidate links, fetch and clean the page content, split the text, build a prompt, and then let the model summarize it. This pipeline involves network request orchestration, content extraction, length truncation, and failure retries. It is a lot of engineering work and is easy to get wrong.

    Over the past two years, major model providers have started packaging web search as a server-side capability. Developers only need to declare which tools are available in the request. The server handles query rewriting, retrieval, page reading, and result injection, while the model decides on its own when to search and what to search for within the same inference turn. This article abstracts that capability into general practices and shows how to integrate it without being tied to any specific vendor.

    2. Capability Model: Treat Retrieval as a Server-Side Tool, Not Client Logic

    The key to understanding this approach is the distinction between two tool-calling modes.

    The first is client-side tools (function calling). The model outputs a structured call intent, the client executes a local function or private endpoint, and the result is sent back for the model to continue reasoning. The advantage is flexibility: it can connect to internal enterprise systems. The cost is an extra round trip on every turn, and developers must implement the full execution and return loop.

    The second is server-side tools. The tool implementation lives on the model service side, and the client only declares which tools are allowed. The model completes multiple retrieval steps internally, returns the final answer directly, and attaches an execution trace for auditing and billing reconciliation.

    The value of server-side tools is that complexity is consolidated on the platform side. For developers, hundreds of lines of orchestration logic shrink to a parameter configuration in a single request. For the business, time to first token and total latency are usually more predictable because multiple network round trips are eliminated.

    3. Three Preparation Steps Before Integration

    3.1 Protocol Compatibility

    Enterprises often run two kinds of stacks at the same time: one built around Chat Completions-style message arrays, another built around a more structured message and content-block model, while some teams use a unified stateful interface. The ideal approach is to choose a service endpoint that is compatible with multiple mainstream protocols, so existing code can migrate without a rewrite. During migration, you only need to replace the credentials and base URL, and keep the model identifier consistent to avoid maintaining multiple model-name mapping tables for different interfaces.

    3.2 Credentials and Endpoint Configuration

    Keys should be injected through environment variables or a key management service, and must never be hard-coded in the repository. Keep the base URL and the key in separate configuration entries so you can switch between test and production environments.

    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. )

    3.3 Explicit Control of Reasoning Mode

    Retrieval tasks are latency-sensitive. Most services allow you to explicitly disable or enable reasoning mode through an extension field in the request body. With it disabled, responses are faster and cheaper, which suits weather, scheduling, and simple fact queries. With it enabled, the model plans first and then searches, which suits multi-hop reasoning and complex comparison questions. Exposing this switch as a parameter to the upper-layer business logic, rather than hard-coding it, is a good engineering habit.

    4. Core Implementation: Search and Answer in a Single Request

    The example below shows the minimal viable form: declare two server-side tools, one for web search and one for reading a specific link.

    1. resp = client.chat.completions.create(
    2. model="deepseek-flash",
    3. messages=[
    4. {"role": "system", "content": "You are a rigorous assistant. When real-time information is involved, you must search before answering."},
    5. {"role": "user", "content": "What is the weather in Shanghai today? Is it suitable for going out? Keep it brief."},
    6. ],
    7. tools=[
    8. {"type": "deepseek_web_search"},
    9. {"type": "deepseek_read_url"},
    10. ],
    11. extra_body={"thinking": {"type": "disabled"}},
    12. )

    The responsibilities of the two tools must be clearly separated. The search tool accepts a set of queries and returns candidate results. The URL-reading tool accepts a specific address and returns the page content. The former answers “where to look,” and the latter answers “read this one thoroughly.” In practice, a common pattern is for the model to issue several queries in parallel first, then pick two or three of the most relevant links for deeper reading.

    5. Injecting Time, Location, and Context

    The model does not know today’s date or the user’s city. A reliable approach is to inject a context message into the message array that declares the date, day of the week, location, language preference, and output format requirements together. This message should be generated dynamically by the server at runtime rather than assembled by the client as a string; otherwise it can easily drift out of sync with the real time.

    1. {"role": "user", "content": "2026-11-14, Saturday, Shanghai, Web, Chinese"}

    Note that this kind of context only affects the model’s judgment and wording; it carries no permission semantics. Real access control, data isolation, and sensitive-information filtering must be enforced at the gateway layer and cannot rely on prompt constraints.

    6. Result Parsing: Reconstructing the Retrieval Trace from the Response

    The observability of server-side tools shows up in the response extension fields. The final answer is in the regular content field, while the retrieval trace is usually attached to extra properties of the message object, organized by step, with each step containing several call records that indicate the tool type and the specific action parameters.

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

    When parsing, three things are recommended. First, read extension fields defensively, since field names may be slightly adjusted across versions. Second, log the number of tool calls as a basis for cost attribution. Third, handle empty traces as a fallback: when the model answers a real-time question without triggering retrieval, proactively downgrade to an “insufficient information” response.

    7. Engineering Practices

    • Idempotency and retries: retrieval requests are naturally retryable and work well with exponential backoff; avoid repeatedly triggering expensive retrieval for the same question within a very short window.
    • Caching: build a short-lived cache for high-frequency, low-volatility questions to significantly reduce the number of tool calls.
    • Timeouts and fallback: set an end-to-end timeout for the overall request, and fall back to no-retrieval mode after a timeout while clearly telling the user that results may be outdated.
    • Citations and verifiability: require the model to append source titles after its conclusions so humans can verify them, reducing the business risk of hallucination.
    • Content safety: fetched external pages are untrusted input and require prompt-injection detection and content-length limits on the server side.
    • Cost model: include the “average tool calls per thousand requests” in capacity planning rather than looking only at input and output character counts.

    8. Common Issues and Troubleshooting

    If the model’s answer is clearly outdated, first check whether the date in the context message is generated at runtime. If retrieval is not triggered, check whether the tool declaration is filtered by the gateway and whether the prompt explicitly requires “search first.” If the URL-reading tool returns empty content, the target site is usually blocking crawlers or relying on front-end rendering; in that case, reduce dependence on that source. If latency fluctuates widely, it is usually caused by too many search queries increasing the number of steps; this can be addressed by limiting the number of queries and disabling reasoning mode.

    9. Summary

    Server-side web search turns “real-time capability” from a client-side engineering problem into a parameter configuration task. What developers need to master is not the field names of a specific API but four things: the migration freedom brought by multi-protocol compatibility, the boundary between server-side and client-side tools, the right place to inject context, and the ability to reconstruct the execution trace and cost from response extension fields. Get these four points right, and real-time question answering can be deployed reliably with low maintenance overhead.