Practical Guide to LLM API Integration: Search and File Parsing
This guide explains how LLM tool-calling ecosystems are shifting from client-side assembly to server-side integration, using Baidu AI Cloud's Qianfan platform as an example. It covers the two-layer capability model, how usage-based pricing changes cost estimation, a vendor-neutral integration pattern, a minimal validation checklist, and best practices for compliance, observability, and cost control.
1. The Shift: From Assembling Tools to Server-Side Integration
Over the past year, the tool-calling ecosystem around large language models has changed noticeably. Capabilities such as search, web crawling, document parsing, speech recognition, and speech synthesis are moving from “assembled on the client side” to “enabled on demand on the server side.” The most immediate benefit for developers is the elimination of a large amount of glue code: you no longer need to maintain your own search adapter layer, document parsing pipeline, or multi-turn context stitching logic.
Take the LLM services offered by Baidu AI Cloud’s Qianfan platform as an example. Capabilities are typically exposed in two layers: one is a set of optional tool switches inside the chat interface, and the other is a set of independently callable capability APIs. The former emphasizes being “integrated with inference,” while the latter emphasizes being “orchestrated separately.” Understanding the boundary between these two layers is the prerequisite for designing a cost-control strategy.
2. What the Two-Layer Capability Model Means for Engineering
The first layer consists of tool-based capabilities inside the chat API, commonly including:
- Web search: the model retrieves external information before or during generation;
- Retrieve while reasoning: the model decides on its own whether additional retrieval is needed, and a single turn may trigger multiple tool operations;
- Document input: support for common office document formats, with upper limits on individual file size and page count;
- Link reading and in-page lookup: fetching the content at a specified URL and locating key passages;
- Content safety checks: compliance screening of inputs and outputs.
The second layer consists of standalone capability APIs, such as search, crawling, document text recognition, speech recognition, and speech synthesis. They do not depend on the chat context, making them suitable for offline batch processing or as components of your own pipeline.
The key engineering conclusion is a single sentence: once tool invocation and context stitching are moved up to the server side, the client is still responsible for session state management, streaming result rendering, and failure retries, but it no longer needs to implement the tools themselves.
3. How the Cost Structure Changes and How to Estimate It
Capability integration changes the composition of your bill: costs used to fall mainly on tokens, but now there are also per-call charges for retrieval and crawling. When making a technology selection, it is recommended to establish a baseline using an approach like the following:
# Illustration: cost estimation framework for a single-turn request (pseudocode)def estimate_cost(tokens_in, tokens_out, tool_calls):token_cost = tokens_in * price_in + tokens_out * price_outtool_cost = sum(price_per_call[tool] for tool in tool_calls)return token_cost + tool_cost
Three points need to be emphasized. First, retrieval-type calls are often billed per call, on top of token-based billing. Second, “retrieve while reasoning” amplifies the number of calls, and a single turn may involve a dozen or more tool operations. Third, caching and deduplication can significantly reduce the overhead of repeated retrieval. For specific unit prices and quotas, refer to the latest official documentation of the platform you use; this article does not provide any unconfirmed figures.
4. A Reusable Integration Pattern
The following vendor-neutral sample code shows how to “enable tools on demand + handle exceptions uniformly”:
def run_agent(messages, tools=None, stream=True):payload = {"messages": messages, "stream": stream}if tools:payload["tools"] = tools # e.g. ["web_search", "file_parse"]try:for chunk in client.chat(payload): # client is a wrapper around the platform SDKyield render(chunk) # the client handles rendering and state managementexcept RateLimitError:backoff_and_retry(messages, tools)
In production, it is recommended to add three layers of protection: request-level timeouts and a cap on the maximum number of tool calls; structured caching of retrieval results; and a fallback strategy for individual files that fail document parsing.
5. Testing Approach and Validation Checklist
To determine whether a capability meets your business needs, you can use a minimal validation flow: first run a pure chat baseline, then enable retrieval, deep retrieval, link reading, and document input in sequence, and finally call the standalone search API once, checking the request count and token usage on that day’s bill. Focus the validation on three areas: whether citations are traceable, whether fabricated information can be identified, and whether overly long documents trigger truncation.
6. Risks and Best Practices
First, data compliance: desensitize documents before uploading them. Second, observability: it is recommended to write every tool call into a logging service and configure monitoring alerts. Third, cost control: disable deep retrieval on non-critical paths. Fourth, result trustworthiness: require sources for numerical conclusions in model output. Overall, server-side integration lowers the barrier to entry, but it hands more of the initiative in cost governance back to the architecture designer.
