A Practical Guide to Built-in Tool APIs for Large Language Models

    This article explains how built-in tool APIs are changing the way LLM applications are built, moving capabilities such as web search, URL reading, file input, OCR, speech, and content moderation from client-side orchestration to the server. It covers the core tool types, setup steps, minimal code examples, context and time-awareness design, file and voice workflows, cost control, observability, and security practices, helping developers build robust applications with declarative tool interfaces.

    1. From Assembling Tool Chains to Built-in Tools: A Shift in Architecture

    Over the past year, building a complete conversational AI application often required developers to handle a large amount of “glue work”: first integrating a search service, then a web page extraction service, followed by file upload and parsing, then chaining speech recognition and speech synthesis, and finally adding a content moderation layer. Each step meant a separate system for authentication, quotas, retries, and error codes. As a result, the application layer became a complex orchestrator, while the actual business logic was buried in tool adaptation code.

    A new interface pattern has recently emerged in the industry: capabilities such as web search, link reading, file input, optical character recognition, speech transcription and playback, and content moderation are built directly into the chat API as “server-side tools.” Developers only need to declare which tools they need in the request; the server handles invocation, context assembly, and returns the execution trace. This model shifts complexity from the client to the server and significantly lowers the implementation barrier.

    It is worth emphasizing that these capabilities are not unique to any single vendor, but represent a direction the industry is evolving toward together. This article does not evaluate any specific product. Instead, it abstracts a general technical model and discusses how to implement a similar architecture in your own system, or how to design robustly when adopting third-party built-in tool APIs.

    2. Core Capabilities of Built-in Tool APIs

    A mature all-in-one chat API typically includes the following types of tools:

    • Web search tool: Generates search queries based on the conversation context, accesses search capabilities, and returns structured result snippets.
    • Link reading tool: Fetches the main content of a user-provided URL, removes noise and summarizes it, then injects it into the context.
    • File input and OCR: Accepts documents or images and extracts text and layout information.
    • Speech capabilities: Speech transcription for input and speech synthesis for reading output aloud.
    • Content moderation: Filters both input and output to reduce the risk of non-compliant content.

    They share a common characteristic: “stateless declaration, stateful execution.” The client only declares intent, and the server completes multiple tool calls within a single request and returns the process as a call trace, making it easy to audit and debug.

    3. Preparation Before Integration

    The first step is to obtain access credentials. Create a key on any open platform that supports these capabilities, and store it in an environment variable to avoid hardcoding it into the code repository.

    The second step is to confirm protocol compatibility. Current mainstream platforms generally support two widely used protocol families: one represented by chat completion and response-style APIs, and the other represented by message-style APIs. Model identifiers are usually provided uniformly by the platform; this article uses placeholders:

    1. import os
    2. from openai import OpenAI
    3. client = OpenAI(
    4. api_key=os.environ["LLM_API_KEY"],
    5. base_url="https://your-gateway.example/v1",
    6. )
    7. MODEL = "your-model-id"

    4. Minimal Working Example: Declare Tools to Enable Web Access

    The sample code below shows how to enable both search and link reading in a single request. Note that tools are passed as a declarative array, and the client does not need to implement any fetching or parsing logic:

    1. resp = client.chat.completions.create(
    2. model=MODEL,
    3. messages=[
    4. {"role": "system", "content": "You are a rigorous assistant. Answers must indicate the time of the information source."},
    5. {"role": "user", "content": "Check today's local weather and travel advice for me. Keep it brief."},
    6. ],
    7. tools=[
    8. {"type": "web_search"},
    9. {"type": "read_url"},
    10. ],
    11. extra_body={"thinking": {"type": "disabled"}},
    12. )
    13. msg = resp.choices[0].message
    14. print(msg.content)
    15. for call in msg.model_extra.get("server_tool_calls", []):
    16. print(call)

    The key is the server_tool_calls field: it returns the execution trace of server-side tools as a list, including the tool name, a summary of input parameters, and result status. In production, this field should be written to a logging system for troubleshooting and performance evaluation.

    5. Context and Time-Awareness Design

    The effectiveness of built-in search tools depends heavily on context quality. In practice, it is recommended to introduce an “environment reminder” message that injects the current date, day of the week, geographic location, output language, and format preference into the model. For example:

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

    This message may seem simple, but it can significantly improve the accuracy of time-sensitive Q&A and reduce the model’s misjudgment about its training cutoff date. It also helps the search tool generate queries that are closer to the real intent.

    6. Orchestrating Files, Speech, and Multimodal Inputs

    File input usually involves two steps: first upload to obtain a file identifier, then reference that identifier in the chat message. Example:

    1. f = client.files.create(file=open("report.pdf", "rb"), purpose="user_data")
    2. resp = client.chat.completions.create(
    3. model=MODEL,
    4. messages=[
    5. {"role": "user", "content": [
    6. {"type": "file", "file_id": f.id},
    7. {"type": "text", "text": "Summarize the three core conclusions of this report."},
    8. ]},
    9. ],
    10. tools=[{"type": "ocr"}],
    11. )

    For the speech pipeline, it is recommended to decouple it into an independent service: audio transcription produces text that enters the conversation, and the reply text is then sent to a synthesis service to generate audio. This makes it easier to optimize streaming and caching separately.

    7. Billing, Rate Limiting, and Cost Control

    Built-in tools are usually billed “per call,” in addition to token-based model billing. Cost control can be approached from four angles:

    1. Tool allowlist: Declare tools only when necessary to avoid triggering search every turn.
    2. Caching strategy: Build result caches for high-frequency identical queries and set reasonable expiration times.
    3. Context trimming: Limit the length of injected web page content, prioritizing conclusion paragraphs.
    4. Tiered models: Use lightweight models for simple intents and upgrade for complex reasoning.

    At the same time, each tool must have a timeout and fallback path. For example, if search fails, fall back to “answer based only on model knowledge and clearly state uncertainty.”

    8. Observability and Performance Evaluation

    It is recommended to collect three types of metrics: tool call success rate, end-to-end latency, and answer traceability. For search-based answers, manually verify samples to check “whether citations actually exist”; for file parsing, monitor character accuracy and layout fidelity; for speech, focus on word error rate and synthesis naturalness. Integrating these metrics into a monitoring and alerting system is essential to prevent quality degradation during iterations.

    9. Security, Compliance, and Engineering Details

    Bidirectional moderation is the baseline: intercept injection and non-compliant requests on the input side, and filter sensitive information on the output side. In addition, when fetching external links, you must comply with the target site’s terms of access and rate limits, and only process addresses explicitly provided or authorized by the user. Keys should be managed in a key management service, combined with least-privilege and rotation mechanisms.

    10. Conclusion

    Built-in tool chat APIs move “search, reading, files, speech, and moderation” from the client to the server, enabling developers to build fully functional intelligent applications in a declarative way. Understanding call traces, context injection, cost control, and observability design provides more long-term value than chasing any single platform. In the general capability systems of cloud service providers such as Baidu AI Cloud, components like object storage, message queues, logging services, and monitoring alerts can naturally integrate with the above architecture, helping you move prototypes to production reliably.