Integrating Web Search and Multimodal Capabilities into LLM APIs
Large language model APIs are moving beyond plain text in and text out. Some services now handle web search, web page reading, file parsing, and speech processing at the API layer. This article breaks these capabilities into modules, compares server-side and client-side orchestration, and covers context budgeting, file ingestion, web access security, voice latency, safety and compliance, and evaluation with cost accounting. It ends with a deployment checklist.
1. From Text Interfaces to Application-Level Capabilities
Early LLM interfaces accepted text and returned text. To build a complete conversational product, developers had to assemble retrieval, file parsing, speech conversion, and other modules on their own. More recently, some services have moved these capabilities into the API layer. Developers can enable them with a parameter switch, and the service handles details such as tool calling and context assembly.
This shift raises two questions. First, which steps suit the service side, and which should stay in your own system? Second, the more capabilities you add, the more concentrated the risks to security, cost, and latency become. The sections below cover each capability module in turn.
2. Breaking Down the Capabilities: Five Relatively Independent Modules
A complete conversational application usually includes the following modules:
- Conversation generation: Produces replies based on the message history. It is the layer that carries all other capabilities.
- Web search: Generates search queries from the user’s question, retrieves web pages or image results, and attaches sources to the answer.
- Web page reading: Identifies links in messages, fetches the main content, and converts it into text the model can read.
- File input: Parses documents and images, and adds the extracted results to the context.
- Speech capabilities: Includes speech recognition, speech synthesis, and text recognition (OCR). These can be called on their own or combined into a pipeline.
Each module has its own failure modes. Retrieval can time out, a web page may require login to access, and OCR on scanned documents can produce wrong characters. Analyzing each module separately makes it faster to locate problems.
3. Where to Orchestrate: Trade-offs Between Server and Client
The tool-calling loop can run on the server or on the client. The differences are as follows:
| Dimension | Server-side orchestration | Client-side orchestration |
|---|---|---|
| Development cost | Low. Enable with a switch. | High. You implement the tool-calling loop yourself. |
| Controllability | Depends on the provider’s policies and versions | Fully controllable. Any component can be replaced. |
| Debugging difficulty | Intermediate steps are opaque and rely on logs | Every step is observable |
| Data boundary | Intermediate content may be processed by the provider | Redaction can be done locally |
| Suitable scenarios | Rapid validation and standardized conversational products | Custom retrieval sources or strict compliance requirements |
Most teams can start with server-side orchestration to prototype and validate the product. Later, sensitive parts of the data path can move back to their own systems.
The following is an illustrative example of client-side orchestration. The function and parameter names are custom placeholders for explanation only. They are not the real interfaces of any platform.
# Illustrative pseudocode: client-side orchestration of the tool-calling loopmessages = load_history(session_id)messages.append({"role": "user", "content": user_input})for step in range(MAX_STEPS): # Set an upper bound to prevent infinite loopsresp = llm.chat(messages, tools=[search_tool, read_url_tool])if not resp.tool_calls:breakfor call in resp.tool_calls:result = run_tool(call.name, call.arguments, timeout=TOOL_TIMEOUT)messages.append(tool_result_message(call.id, result))save_history(session_id, messages)return resp.text
The loop needs two safeguards: a maximum step limit and a timeout for each tool. Without the first, the model may call the same tool repeatedly. Without the second, a single slow request can stall the entire conversation turn.
4. Context Management and Budget Allocation
The context window is a limited resource. Inputs include system instructions, conversation history, retrieval results, and file content. If any one item exceeds its budget, it crowds out the others.
Load context in the following priority order:
- System instructions: Define the role, boundaries, and output format. These must be kept in full.
- Current user question: Directly determines the direction of the answer. Keep it with priority.
- Retrieval results and file excerpts: The factual basis for the answer. Sort by relevance, then truncate.
- Conversation history: The farther a turn is from the current one, the less it is worth keeping. Use a sliding window or summary compression.
budget = context_limit - reserve_for_outputsegments = [system_prompt, current_question, evidence_chunks, recent_turns]for seg in segments: # Load segments in priority orderif used + seg.tokens <= budget:include(seg)else:include(seg.truncate(budget - used))break
Reserving a fixed amount of space for the output is a common practice. Without this reserve, the model’s answer may be cut off partway through.
5. File Input Pipeline
A file usually passes through the following stages from upload to entering the context:
- Format detection: Base it on the file’s actual content characteristics, not just its extension.
- Text extraction: For text-based documents, extract the text directly and preserve paragraph structure.
- Layout and table handling: Convert tables into structured text, such as Markdown tables, so that column relationships are not lost.
- Text recognition: Scanned documents and images need OCR, and the confidence score should be recorded. Low-confidence segments should prompt the user to verify them.
- Cleaning and chunking: Remove repeated content such as headers and footers, split at semantic boundaries, and keep page numbers or location information for each chunk.
- Context injection: Label each segment with its source before it is inserted, so the model can cite it in the answer.
In engineering terms, you also need to handle file size limits, parsing timeouts, and fallback behavior on failure. When parsing fails, tell the user which content was not read. Do not let the model answer with missing information.
6. Web Search and Web Page Reading
6.1 Credibility of Search Results
Search result quality varies widely. Rank sources by type: official documentation, authoritative institutions, and vetted media come first. Forums and personal blogs need cross-checking. When the model answers, each factual statement should map to a source number so users can verify it.
6.2 Security Boundaries for Web Page Reading
Web page reading lets the service access any link on the user’s behalf, which creates a risk of server-side request forgery (SSRF). Key protections include:
- Allow only the http and https protocols.
- After resolving the domain name, reject private, loopback, and link-local addresses.
- Limit the number of redirects, and re-validate the address after each redirect.
- Limit response body size and content types to avoid downloading very large files.
- Connect using the IP address that has already been validated, to prevent DNS rebinding from bypassing the check.
def is_safe_target(url):parsed = parse_url(url)if parsed.scheme not in ("http", "https"):return Falseip = resolve_once(parsed.host) # Resolve once; reuse this result for the connectionreturn not (ip.is_private or ip.is_loopback or ip.is_link_local)
6.3 Web Content Is Untrusted Data
Web page text and
