LLM Application API: A Practical Guide to Integrated Search and Parsing
This article examines how exposing application-layer capabilities through APIs changes the work of shipping LLM applications. It breaks tool calling into four categories—search, reading, file parsing, and speech or OCR—outlines key engineering practices with sample code, explains the cost structure, and compares managed APIs with self-built toolchains and hybrid architectures. Readers will find a practical checklist covering tool descriptions, caching, citation validation, fallbacks, and billing attribution to move from a working demo to reliable delivery.
1. The Underrated Engineering Burden: From “Can Answer” to “Can Deliver”
Getting a large language model to produce a fluent answer is not difficult. The hard part is making it search the web on its own, fetch and read pages, parse PDFs and scanned documents, and then organize scattered information into a conclusion with citations. The original material describes a common situation: developers used to assemble this toolchain themselves, including retrieval services, fetching and main-text extraction, document parsing, embedding and reranking, and citation alignment. This system is often as important as the model itself, yet it gets squeezed in the schedule and ends up producing answers that “look right but cannot be traced.”
A cloud vendor recently opened up the capabilities used in its official application as APIs. In essence, this productizes the application-layer toolchain: tools are declared in the request, the model decides autonomously whether to call them, and the server side handles retrieval, fetching, and context processing; files are uploaded and parsed first to obtain an identifier before being used in a conversation; speech and text recognition are offered as standalone interfaces. For developers, the value is not “one more endpoint” but transferring the operational responsibility for self-built components.
2. Capability Layers: Four Categories of Tool Calls
- Search: the model decides per task whether to trigger a web search; the server handles recall, deduplication, and summarization, and returns results with source information.
- Reading: main-text extraction and noise removal for a given link, producing clean text ready for ingestion and solving the “page opens but content cannot be read” problem.
- Files: upload and parse first (PDF, spreadsheets, image-based documents), obtain a file identifier, then reuse it across multiple turns to avoid repeated uploads.
- Speech and recognition: speech synthesis, speech recognition, and text recognition as independent capabilities, suitable as fallbacks and for teams that cannot easily build their own model services.
3. Implementation Notes and Sample Code
Tool declaration is the key. Most interfaces follow the pattern of “list available tools in the request, let the model decide whether to call them,” so parameter design and description quality directly determine call accuracy.
payload = {"model": "<model identifier>","messages": [{"role": "user", "content": "Compare public industry data from the past three years and provide citations"}],"tools": [{"type": "web_search", "web_search": {"max_results": 8, "country": "CN"}},{"type": "fetch_url", "fetch_url": {"max_chars": 20000}}],"tool_choice": "auto"}
Four things are worth adding on the engineering side. First, separate timeouts from retries: search calls should have short timeouts and few retries, while parsing calls should be the opposite. Second, cache results, keyed by “normalized query text + time window,” which significantly reduces duplicate billing. Third, validate citations: every conclusion the model gives must map to the returned source list; if the mapping fails, fall back to an “answer without citations” and label it. Fourth, ensure observability: write the latency, response length, and failure codes of each tool call into a logging service and configure monitoring alerts.
4. Cost Structure: Do the Math Before Launch
Billing usually consists of two parts: token fees and tool call fees. Taking “write an article with research” as an example, community estimates put the cost at under one yuan, showing that the token side is no longer the bottleneck and the real cost lies in engineering and compliance. A usable estimation approach is as follows:
cost per call ≈ input tokens × unit price + output tokens × unit price+ number of searches × price per thousand / 1000+ pages fetched × price per page+ speech duration × price per minute
The recommended optimization order is: first reduce the number of searches (front-load intent detection, merge synonymous queries), then reduce fetched volume (truncate main text, take only effective first-screen paragraphs), and only then consider switching to a smaller model. Note that vendors differ significantly in free quotas and tiered pricing, so selection should be based on measured results using your own average daily call volume rather than someone else’s conclusions.
5. Trade-offs: Self-Built Toolchains and Other Cloud Vendors
The advantage of a self-built toolchain is control and replaceability; the cost is that you handle blocked crawling, parsing format drift, and recall quality fluctuations yourself. The advantage of an open API is fast launch and an experience close to the official application; the cost is an opaque pipeline and unit prices that grow linearly with usage. If the business has strong regulatory requirements on data sources or needs on-premises deployment, a hybrid architecture is more realistic: core retrieval and parsing run on your own services, while long-tail capabilities such as speech and text recognition call external interfaces as a fallback.
6. Experience Gaps and Compliance Red Lines
Speech synthesis naturalness and layout fidelity for scanned PDFs are the two areas most prone to “impressive in a demo, failing in production,” so be sure to run canary evaluations with real samples. On compliance, three points need attention: the robots protocol and copyright constraints of the target site being crawled, the storage period and deletion mechanism for user files, and the traceability of citations in generated content. In similar scenarios, Baidu AI Cloud typically advises customers to combine general-purpose capabilities, such as using object storage for original files, message queues for peak shaving, and logging services to audit the call chain. These practices are vendor-agnostic and belong to general architecture practice.
7. Launch Checklist
Before going live, confirm: whether tool descriptions cover synonymous expressions; whether a maximum number of searches per session is set; whether the cache key includes a time window; whether there is fallback wording for failed citation mapping; whether speech and recognition have a backup channel; and whether billing is tagged by business line for attribution. Meeting these seven points is what turns the benefits of application-layer APIs into real delivery quality rather than something that stays in the demo stage.
