LLM Tool API Integration: Search, Files, Speech, and Content Safety
A practical guide to integrating LLM tool APIs for web search, file parsing, URL reading, speech recognition and synthesis, and content moderation. Learn how to handle streaming events and failures, choose between standalone and combined calls, manage costs, and check operational and compliance requirements before launch.
1. Define the Integration Scope
This article covers web search, deep reasoning, file parsing, URL reading, speech recognition and synthesis, and content moderation. Availability, parameter names, quotas, and billing rules depend on the platform. Consult the latest official documentation before development.
The code below illustrates the request structure only and is not directly executable.
2. Tool Calls in Conversations
When web search is enabled in a non-reasoning mode, the model can initiate a search if it determines that external information is needed, then include source citations in its answer. This approach suits time-sensitive questions with straightforward factual answers, such as weather or price queries.
In deep reasoning mode, the model decides when to search and when to read web pages during multi-step reasoning. This approach is slower and consumes more tokens, but is better suited to complex questions that require cross-checking.
An illustrative request follows. Use the field names specified in the platform’s documentation.
{"model": "<platform-provided-model-version>","messages": [{"role": "user", "content": "What is the weather in Beijing today?"}],"tools": [{"type": "web_search"}],"stream": true}
An integration needs to handle three situations:
- Interleaved streaming events: Tool-call events and text events may appear in the same stream. The client should process each according to its event type.
- Rate limits and insufficient quotas: Handle the relevant error codes with exponential-backoff retries and provide a clear message to the user.
- No search results: Have the model state that it could not find reliable sources rather than inventing missing information.
3. File Parsing and URL Reading: Limits and Failure Handling
File inputs commonly support formats such as PDF, Office documents, and images. Parsing typically begins with text extraction, followed by layout recognition for content that mixes text and images. The extracted content is then assembled into the model’s context.
Tasks such as contract review and research report analysis depend on parsing quality. Before launch, confirm the platform’s supported formats and its per-file size and page limits.
Common responses to parsing failures include:
- Ask the user to convert the file to text or split it into smaller files and upload it again.
- Route scanned documents through a separate optical character recognition (OCR) API to avoid interrupting the entire workflow.
- Record the failure reason and file type to support later improvements.
Long-running tasks can use asynchronous polling and should not block the user interface.
URL reading can also fail. A target page may have anti-scraping restrictions, require authentication, or time out. In these cases, return an explicit “Unable to read this URL” result and allow the user to paste the page content. Do not attempt to bypass access controls on pages that require authentication.
4. Choosing Standalone APIs or Combined Calls
The right approach depends on the systems your team already has.
If an organization has its own retrieval repository and only needs the model for reasoning, disable platform search and pass the retrieved results as context.
If a workflow first uses OCR to convert receipts into structured text and then asks the model to extract fields, separate calls are appropriate. Validate the intermediate results before continuing.
Combined calls reduce orchestration work and can help teams launch more quickly, but provide less control over platform behavior.
Standalone APIs can be replaced like modules. For example, a Fetch API can be replaced with an in-house fetching service without changing higher-level logic, provided the output fields remain consistent.
Cloud function and workflow services can handle orchestration and retries. However, they introduce additional charges that must be included in the cost calculation.
5. The Speech Interaction Pipeline
A basic voice assistant follows this sequence:
- Automatic speech recognition (ASR) converts the user’s speech into text.
- The text is sent to the LLM.
- Text-to-speech (TTS) converts the model’s output into audio for playback.
Latency mainly comes from recognition, inference, and synthesis. To reduce perceived waiting time, synthesize the model’s output sentence by sentence: send each complete sentence to TTS as soon as it is generated.
When the user interrupts playback, the client should send cancellation requests to stop subsequent synthesis and inference.
6. Content Moderation and Developer Responsibilities
Applications serving external users need to moderate both inputs and outputs. Platform safety settings typically block disallowed content before or after a request, or return a refusal indicator.
Developers must incorporate refusal indicators into business logic, give users clear feedback, and record the time, type, and handling outcome of moderation events for review.
Platform safeguards do not replace the developer’s own responsibilities. Teams need to establish moderation procedures, retain necessary logs, and explain data handling in the user agreement or interface. Users who dispute a moderation decision should have access to an appeal channel.
Regulatory obligations vary by jurisdiction. Public-facing generative AI services may be subject to requirements such as algorithm registration or prominent labeling of generated content. Check the applicable requirements issued by the relevant authorities.
For stronger risk controls, cloud content moderation services can be placed before and after model calls, providing both pre-request blocking and post-response filtering.
7. Estimating and Controlling Costs
Total cost can be estimated as:
Total cost = Token unit price × Token usage+ Σ(Tool unit price × Tool usage)
Token usage includes both context input and generated output. Tool charges may be based on calls, pages, duration, or characters. Billing units differ across platforms—for example, per thousand calls, per thousand pages, per hour, or per ten thousand characters.
Three measures can help control costs:
Route Requests by Intent
Use lightweight models with tools disabled for casual conversation and general knowledge questions. Enable more capable models and the relevant tools only when needed for time-sensitive questions, long documents, or speech input.
Cache Reusable Results
Cache search results that do not change over time and file-parsing results. Cache keys can be based on a file hash or a normalized query. Higher cache hit rates reduce repeated OCR and fetching charges.
Cancel Promptly
When a user stops generation or playback, call the cancellation API to avoid continued token usage and speech synthesis charges.
8. Pre-Launch Checklist
Before launch, verify the following:
- Platform authentication and API key management are in place.
- Model versions and parameters match the documentation.
- Rate-limit handling, retries, and error-code handling are complete.
- The interface clearly states file format, size, and page limits.
- A working fallback is available when URL fetching fails.
- Moderation blocking rates and false-positive rates have been tested.
- Log retention periods and user disclosures meet applicable requirements.
- Cost monitoring reports usage separately by tool type.
Completing these checks provides a foundation for stable operation within permission, quota, and compliance constraints. Multimodal capabilities and tool APIs can reduce custom development work, but teams must still make their own decisions about business use cases, data boundaries, and responsibility.
