Server-Side Tool Integration Guide: Web Search and File Understanding

    This article compares client-side and server-side tool calling for model applications, explains how server-side web search and file understanding work, and covers a pre-integration checklist, pseudocode, billing estimation, and privacy compliance for files and voice input.

    1. Two Tool-Calling Approaches: What’s Different?

    When building web-connected Q&A, a common approach is client-side tool calling. The model returns a function name and arguments; your program calls the search API, gets the results, sends them back to the model, and repeats until it generates the final answer. Your code controls the entire loop, so timeouts, deduplication, body extraction, and source display all need to be handled by you.

    Server-side tool calling moves this loop inside the platform. The client declares which tools are enabled in the request; the inference service decides whether to search, which pages to visit, and then merges the results into the context to generate an answer. Your code only needs to receive the final text and the tool-call records returned by the platform.

    The trade-offs are as follows:

    Dimension Client-side tool calling Server-side tool calling
    Network round trips Multiple, between the client and external services Usually fewer, because tools run within the inference service
    Controllability High; search sources, filtering rules, and timeouts can all be customized Lower; search sources and crawling strategies are decided by the platform
    Engineering effort Large; you need to maintain retrieval, crawling, and cleaning code Small; mainly parameter declaration and result parsing
    Observability Determined by your logs Depends on tool-call records returned by the platform; fields vary by platform
    Cost accounting Separate third-party bills need to be aggregated yourself Model and tool fees may appear on the same bill; the accounting method depends on the platform
    Migration cost Existing pipelines can continue to be used Request and response parsing need to be changed; canary rollout is recommended

    If you have strict requirements for search result quality and sources, the client-side approach is more controllable. If your team wants to build a usable version quickly, the server-side approach can significantly reduce integration code.

    2. How Server-Side Tool Calling Works

    A typical request goes through roughly four steps: the model determines whether the current question needs external information; if needed, the platform performs retrieval and crawls relevant web pages; the retrieval results are injected into the model context; the model generates an answer based on that content.

    Three points are worth remembering:

    • Whether to search is decided by the model. You can provide clues such as date and region in the system prompt, but you cannot guarantee that it will search every time.
    • The response usually contains tool-call records, which may include search keywords, visited links, and call types. Field names and structures vary by platform; refer to the platform documentation.
    • Tool usage generally appears in usage-related fields. Whether it is billed per call and what the billing unit is should also be confirmed against the platform’s pricing documentation.

    3. Pre-Integration Checklist

    Before writing code, confirm the following five items one by one:

    1. Account and key: create an API key on the model platform and confirm that the key has permission to call tools such as web search and file understanding.
    2. Protocol and SDK: confirm the protocol supported by the platform, such as OpenAI-style Chat Completions or Anthropic-style Messages, and install the SDK version specified in the documentation.
    3. Model and tool support: confirm that the selected model supports the server-side tools you want to use. Not all models support all tools.
    4. Key storage: store the API key in environment variables or a secrets management service; do not write it into code or logs.
    5. Response field validation: run a test question first and check whether the answer text, tool-call records, and usage fields are all present.

    4. Integration Example (Pseudocode)

    The following code demonstrates the call structure. Tool type names, endpoint, model name, and response fields are placeholders and must be replaced with the actual values from your platform documentation. Copying and running it directly will most likely fail.

    1. import os
    2. from openai import OpenAI # SDK version must match platform documentation
    3. client = OpenAI(
    4. api_key=os.environ["MODEL_API_KEY"], # Read from environment variable
    5. base_url="<inference service endpoint provided by the platform>",
    6. )
    7. resp = client.chat.completions.create(
    8. model="<model name that supports server-side tools on the platform>",
    9. messages=[
    10. {"role": "system", "content": "Current date: 2026-11-24; Region: Shanghai"},
    11. {"role": "user", "content": "What is the weather like in Shanghai today? Is it good for going out? Please answer briefly."},
    12. ],
    13. tools=[
    14. {"type": "<platform-defined web search tool type>"},
    15. ],
    16. )
    17. msg = resp.choices[0].message
    18. answer = msg.content
    19. # The location and field names of tool-call records vary by platform; read them according to the documentation.
    20. tool_records = getattr(msg, "server_tool_calls", None) or []
    21. # Usage fields also follow the documentation.
    22. usage_info = getattr(resp.usage, "server_tool_use", None)

    The expected result is: answer contains weather-related text; if the model actually searched, tool_records is non-empty; usage_info can be used for billing. If tool_records is empty, it means the model may have answered directly without calling search. Response latency depends on platform load, network conditions, and question complexity. Design timeouts based on your own measurements rather than applying fixed values.

    5. Billing: Estimate Model and Tool Costs Separately

    Cost consists of two parts. Estimate them separately and then add them together:

    Single-request cost ≈ input tokens × input price + output tokens × output price + tool calls × per-call tool price

    Keep the following points in mind:

    • Input price, output price, and tool price are subject to the platform’s current price list. The platform may adjust prices by time period, package, or usage tier.
    • Input tokens include the system prompt, conversation history, and web page content returned by tools. After search results are injected into the context, input tokens often increase significantly; this is the part most easily missed during estimation.
    • Tool billing units may be calls, duration, or character count. Speech transcription is often billed by duration, so long recordings need separate estimation.
    • Run a batch of real questions, record average token counts and tool-call counts, and then plug them into the formula. This is more reliable than estimating from experience.

    Ways to reduce costs include: do not declare the search tool for casual chat requests; enable search only for time-sensitive questions such as news, prices, and weather; if the platform supports limiting the number of results or body length, set caps to reduce the content injected into the context.

    6. Files, Voice, and Privacy Compliance

    File understanding and voice input often handle users’ personal information or internal enterprise data, so compliance requirements are higher than for web search. Before launch, confirm the following:

    • Authorization: inform users of the purpose, processing method, and retention period for uploaded files or recordings, and obtain explicit consent.
    • Data retention: read the platform’s data usage terms and confirm whether request content is used for model training, how long it is retained, and how it is deleted. Enterprise users should sign a data processing agreement.
    • Minimization: upload only the content needed to complete the task. Be careful with sensitive fields such as ID numbers, bank card numbers, and phone numbers when uploading.