Engineering Practice for Integrating Built-in Tools and Capability APIs in Large Language Models
This article explores the engineering practice of integrating server-side built-in tools and capability APIs in Large Language Models (LLMs). It covers the shift of capabilities to the server side, common API protocol types, how to enable built-in tools like web search and file input, and the use of standalone capability interfaces for agent workflows. Additionally, it provides practical guidance on cost management, permission control, and security compliance to help developers build robust and efficient AI applications.
1. Background: Why Capabilities are Sinking to the Server Side
In the past, building a smart application that could access the internet, read files, and process audio required developers to orchestrate multiple components manually: search services for finding information, crawlers or parsers for extracting text, document parsing libraries for reading files, and voice services for audio conversion. Each component needed separate integration, maintenance, and exception handling.
Recently, an increasing number of model services have moved these common capabilities to the server side. Developers simply declare the required capabilities in their requests, and the model autonomously decides when and how to invoke them, integrating the results into its final response. This pattern reduces client-side orchestration code and ensures that capability upgrades no longer depend on application-side releases. Understanding this shift helps determine which capabilities should be delegated to the server side and which should remain under the control of the business system.
2. Three Common API Protocol Patterns
Mainstream model services typically offer three API patterns:
- Message-based API: Organizes context using role-based message arrays, suitable for multi-turn conversations and complete round-trips of tool calls.
- Response-based API: Returns results in a unified response object, placing text, tool calls, and citation information into structured fields for easy parsing.
- Chat Completion API: Retains an earlier request structure, offering broad compatibility and lower migration costs for legacy systems.
When choosing a protocol, prioritize existing code dependencies, team familiarity, and support for streaming output and tool call formats. The core capabilities of these three patterns are largely identical, with differences primarily in field naming and event structures.
3. Server-Side Built-in Tools: Enable by Declaration
The core concept of built-in tools is “enable by declaration.” Developers toggle the corresponding switches in the request, and the model determines whether a call is necessary based on the user’s query. The calling process and results are handled entirely on the server side.
3.1 Web Search
When encountering time-sensitive questions or knowledge blind spots, the model can automatically initiate web or image searches and cite sources in its response. Developers should focus on two aspects: whether the source citations are displayed to end-users, and whether the response is consistent with the sources. It is recommended to retain citation links in the product UI for user verification.
3.2 Retrieval in Deep Thinking
In reasoning mode, the model may perform multiple retrievals, open web pages, and locate specific paragraphs during its thinking process. This capability is suitable for complex questions, such as fact-checking requiring cross-validation or multi-source synthesis. The trade-off is increased response latency and metering costs, so it is recommended to enable this only for requests that genuinely need it.
3.3 URL Reading
For URLs pasted by users in a message, the model can automatically read the main content. This capability reduces the workload of client-side page crawling and cleaning. Note that pages may require login, might have dynamic rendering, or the content itself could be misleading. The business layer should not treat the read results as absolutely trusted facts.
3.4 File Input
After a user uploads common documents, spreadsheets, presentations, e-books, code, or images, the system returns a file identifier, which can then be placed into the conversation message to ask questions. A typical workflow is:
- The client uploads the file and receives a file identifier.
- The identifier is sent along with the question in the message.
- The model answers based on the parsed content.
In engineering, limit file size and type, and perform virus scanning and format validation before uploading. For excessively long documents, consider segmenting and summarizing them first before initiating a Q&A session to control the context length.
3.5 Content Safety
The server side audits both the input and the complete output. Risky content will be directly rejected. The business side should treat such rejections as a normal branch: provide clear prompts to the user, log the event, and avoid infinite retries.
4. Standalone Capability APIs: Splittable Base Components
In addition to built-in tools, the server side may provide base capabilities as standalone APIs, making them easy to embed into proprietary Agents or workflows. Common categories include:
- Web Search: Returns a list of results and summaries. Some implementations include relevance and authority scores for secondary ranking.
- Web Crawling: Takes a URL as input and returns the main content in Markdown format, suitable as a data source for knowledge base construction or Retrieval-Augmented Generation (RAG).
- OCR (Optical Character Recognition): Recognizes text in documents and images, returning text position coordinates to facilitate layout restoration and information location.
- Speech Recognition: Converts audio to text, suitable for meeting minutes, voice commands, and customer service quality inspections.
- Text-to-Speech (TTS): Converts text to audio, supporting streaming synthesis and playback to reduce first-byte latency.
The advantage of standalone APIs is control. Developers can decide when to search, how many results to retrieve, and which results enter the context. They can also insert filtering, caching, and auditing logic in between.
5. Integration Example in Agent Projects
Below is a vendor-agnostic request structure example illustrating how to declare multiple tools in a single call:
{"model": "your-model-name","messages": [{"role": "user", "content": "Please compare the differences between this report and the latest public data"}],"tools": [{"type": "built_in_web_search"},{"type": "built_in_url_reader"}],"stream": true}
During integration, follow these steps:
- Read credentials and service endpoints from environment variables; never hardcode keys into code or logs.
- Set timeout and retry limits for each request, distinguishing between retryable errors and business errors.
- Parse citation information from the response and keep it consistent with the frontend display.
- Render streaming output in chunks to prevent the UI from remaining blank for extended periods.
6. Cost and Permission Accounting
Combining multiple capabilities amplifies costs. When accounting, it is recommended to break it down into three parts: input and output tokens for model inference, the count and unit price of each tool call, and the duration or page count for file parsing and audio processing. Each item should be logged with actual usage and then aligned with business metrics (such as cost per Q&A or revenue per session).
Regarding permissions, adhere to the principle of least privilege. Only enable internet or file capabilities for scenarios that truly require them, allocate quotas by user or tenant, and set alert thresholds for high-cost APIs.
7. Security and Compliance Essentials
- Input Side: Perform whitelist validation on user-uploaded files and links to prevent malicious files and intranet address access.
- Output Side: Retain the handling path for audit rejections, providing understandable prompt text.
- Data Side: Define the retention period for file and audio data, and explain their usage in the privacy policy.
- Citation Side: Retain original links when displaying sources, and do not rewrite source content to avoid misleading users.
8. Conclusion
Server-side built-in tools and standalone capability APIs lower the integration threshold for intelligent applications. When selecting tools, first clarify whether the scenario requires real-time information, or involves files and audio, before deciding between built-in tools and standalone APIs. Before going live, establish four mechanisms: usage monitoring, error classification, security auditing, and cost alerting to ensure these capabilities serve the business stably.
