Engineering Practices for Built-in Web Search and Multimodal Capabilities in LLM APIs
As Large Language Model (LLM) APIs evolve, an increasing number of service providers are handling common pipeline steps, such as web search and web scraping, directly on the server side. This article explores the engineering practices of utilizing built-in LLM tool capabilities. It details common capability categories, compares server-side built-in tools with client-side custom tools, and provides a request design example. Additionally, it covers cost accounting, quality evaluation metrics, engineering best practices, security and compliance considerations, and a framework for selecting the appropriate integration mode. This guide helps developers effectively implement and manage built-in LLM capabilities in production environments.
1. Why LLM APIs Are Starting to Build in Tool Capabilities
In the past, to enable models to answer real-time questions, developers typically had to build their own retrieval pipelines: calling a search service to get results, scraping web page content, cleaning noise, and then concatenating the text into the prompt. Every step could go wrong and required long-term maintenance.
As API capabilities evolve, more and more model services are handling these common steps on the server side. The caller only needs to declare the required capabilities in the request, and the server is responsible for retrieval, reading, assembling the context, and returning the result.
The direct benefit of this shift is a shorter pipeline. Teams do not need to independently handle authentication, rate limiting, and exception handling for each external capability, and it reduces the tool-calling loops that clients must maintain. However, a shorter pipeline also means reduced visibility into intermediate processes. Both cost and quality must be verified through additional observation methods, rather than just looking at the final output.
2. Common Built-in Capability Categories
These capabilities can be roughly divided into five categories:
- Web Search: Generates search queries based on the question and returns the titles and summaries of relevant web pages.
- Web Reading: Given a URL, extracts the main text content and removes noise such as navigation bars and advertisements.
- File Input: Receives documents or images and parses them into text; some services also retain layout and table information.
- Voice Capabilities: Transcribes speech to text or synthesizes text into speech.
- Content Security: Conducts compliance reviews on input or output to identify illegal or sensitive content.
The input and output formats of these capabilities differ, as do their quality measurement methods. Retrieval focuses on relevance and timeliness; web reading focuses on text completeness; OCR focuses on character accuracy; speech transcription focuses on word error rate (WER); and security review focuses on false negative and false positive rates. When evaluating, metrics should be set by category to avoid replacing specific data with a general impression.
3. Comparison of Two Integration Modes
Mode A: Server-side Built-in Tools. The caller enables the corresponding capabilities in the request, and the model service performs retrieval and reading, with the results directly entering the generation process.
Mode B: Client-side Custom Tools. The caller defines tool functions, the model returns the tool-calling intent, the client executes it and passes the results back to the model, looping until the task is complete.
The differences between the two modes are as follows:
| Dimension | Server-side Built-in | Client-side Custom |
|---|---|---|
| Integration Cost | Low, can be enabled with a few parameters | High, requires maintaining tools and call loops |
| Controllability | Medium, limited adjustable parameters | High, custom data sources and filtering rules |
| Observability | Relies on logs provided by the service provider | Fully autonomous control |
| Data Flow | Data processed on the service provider’s side | Partial processing can be done within the intranet |
| Applicable Scenarios | Rapid prototyping, general Q&A | Private data sources, strict compliance requirements |
Neither mode is absolutely superior. In the prototyping phase, the built-in mode is usually preferred to shorten the validation cycle. After entering the production phase, if quality bottlenecks or compliance constraints arise, evaluate whether to switch to the custom mode.
4. Request Design Example
The following code is only used to illustrate the calling structure. Field names are illustrative, and actual parameters should follow the API documentation of the service used.
import osAPI_URL = "https://api.example.com/v1/chat" # Placeholder addressAPI_KEY = os.environ["LLM_API_KEY"] # Read key from environment variablespayload = {"model": "your-model-name","messages": [{"role": "user", "content": "Please summarize the core points of this article: <URL>"}],"tools": [{"type": "web_search"}, # Illustrative: Enable web search{"type": "read_url"}, # Illustrative: Enable web reading],}response = http_post(API_URL,headers={"Authorization": f"Bearer {API_KEY}"},json=payload,timeout=60, # Tool calls take longer, timeout threshold needs to be set separately)response.raise_for_status()result = response.json()
Note the following when calling:
- Inject keys through environment variables or a secret management service; do not write them into code or logs.
- Tool calls take significantly longer than pure generation; the timeout threshold should be evaluated separately.
- Validate the returned structure and do not assume that fields will always exist.
5. Cost Accounting Approach
The cost of built-in tools usually consists of three parts:
- Model Inference Cost: Metered by the number of input and output tokens.
- Tool Calling Cost: Usually billed per call, such as per search or per read.
- Multimedia Cost: Audio is often billed by duration; file parsing may be billed by page count or number of images.
Some services also differentiate between peak and off-peak pricing, so the cost of the same request may vary at different times.
The cost of a single request can be estimated as follows:
Single Cost = Input Tokens × Input Unit Price + Output Tokens × Output Unit Price + Tool Calls × Tool Unit Price + Media Duration × Duration Unit Price
An easily overlooked point here is that retrieval results and web page text will be concatenated into the context, meaning the input token count may far exceed the user’s question itself. When estimating, the average input length should be tracked by request type, rather than just looking at the length of the user’s original question.
The following measures can be taken during implementation:
- Record costs bucketed by request type to identify high-cost scenarios.
- Set a maximum number of tool calls per request to prevent the model from repeatedly searching.
- Configure budget alerts to intervene promptly when costs are abnormal.
6. Quality Evaluation Methods
Evaluation should use a test set close to the business context, preferably containing 50 to 200 real questions covering the following types:
- Questions requiring the latest information.
- Questions about obscure or long-tail knowledge.
- Questions requiring comparison from multiple sources.
- Common questions whose answers are already in the model’s training data, used to check whether unnecessary retrieval is introduced.
Core metrics are as follows:
- Retrieval Relevance: The proportion of relevant results in the top K results, annotated by humans.
- Answer Accuracy: Whether the answer is correct, determined by humans or scoring rules.
- Citation Reliability: Whether the sources cited in the answer genuinely support the corresponding conclusions.
- Latency: Record P50 and P95 durations, focusing on long-tail requests.
- Voice and OCR Quality: Use proprietary business samples to calculate Character Error Rate (CER) or Word Error Rate (WER). Results from public leaderboards can only serve as a reference and cannot directly replace business data.
It is recommended to conduct comparative experiments with built-in capabilities enabled and disabled on the same test set, using data to determine whether this capability brings actual benefits.
7. Engineering Implementation Points
- Timeout and Retry: Tool calls take longer, so timeouts should be set separately. Retries should only be applied to idempotent requests to avoid duplicate billing or duplicate writes.
- Caching: Apply short-term caching to results from the same link or query to reduce repeated calls. The cache duration should be determined in conjunction with the timeliness requirements of the information.
- Degradation Strategy: If a tool call fails, you can fall back to answering based only on existing context and note in the response that the information may be incomplete.
- Concurrency Control: Batch tasks should limit concurrency to avoid instantly exhausting quotas.
- Logging and Masking: Record request IDs, latency, and tool call counts. User data and sensitive fields should be masked before being written to logs.
8. Security and Compliance
- Server-Side Request Forgery (SSRF) Risk: If the web reading function allows arbitrary addresses, it may be used to access intranet services or cloud metadata interfaces. The accessible protocols and address ranges should be restricted, and access to intranet addresses should be prohibited.
- Prompt Injection: Web pages or files may contain text that induces the model to ignore original instructions. External content should be treated as data, and its boundaries should be clearly defined in the system prompt.
- Data Flow and Privacy: Confirm the scope of data processing and retention period by the service provider, and follow the principle of minimization for personal information.
- Copyright: Indicate the source when outputting summaries to avoid copying large sections of the original text.
- Content Security: Public-facing products should filter sensitive content before output.
9. Selection Decision Framework
You can evaluate item by item using the following five questions:
- Does the business require real-time information? If the questions rely mainly on fixed knowledge, the benefit of built-in web search is limited.
- Is data allowed to flow to external services? When sensitive data is involved, the custom mode should be prioritized for evaluation.
- Are the quality requirements high enough to necessitate custom retrieval sources or filtering rules?
- Does the team have the capability to maintain the tool calling pipeline and related monitoring?
- Is the cost increment per request within an acceptable range?
