Building an Integrated LLM Application API: A Technical Practice
This article walks through the technical practice of moving from assembling multiple third-party services to using an integrated LLM application API. It explains the two-layer capability model of atomic tools and composable features, shows an illustrative call skeleton, and highlights engineering priorities such as citation traceability, context budgeting, and retry handling. It also covers cost and performance control, security and compliance, and observability, using Baidu AI Cloud Qianfan as an example of the same engineering paradigm.
1. From Assembling Third-Party Services to an Integrated Application API
To build a usable conversational AI application in the past, developers often had to act as integrators: model inference in one place, web retrieval in another, document parsing somewhere else, and speech recognition and synthesis in two more. Finally, they had to write glue code to align the data structures returned by each vendor and reassemble the context into the prompt. The longer the chain, the more failure points it had, and the worse the observability became.
The core idea of an integrated application API is to push this orchestration logic, originally scattered across the application layer, down to the server side. The model side exposes only a few switch-style parameters, while the platform handles tool selection, call sequencing, result truncation, and context backfilling. For developers, the complexity converges from “integrating multiple vendors” to “parameter configuration plus result consumption.”
On platforms such as Baidu AI Cloud Qianfan, the same engineering paradigm holds: model services, retrieval augmentation, document understanding, and speech capabilities are provided as general product categories, and developers can combine them as needed without building the entire middleware stack themselves.
2. Capability Layers: A Two-Dimensional Matrix of Atomic Tools and Composable Capabilities
Integrated openness typically has two layers, and understanding them is the prerequisite for designing the architecture.
The first layer is composable capabilities, enabled through switches in the chat interface:
- Web search: in non-reasoning mode, the model automatically initiates web or image retrieval based on the question and attaches citation sources at the conclusion;
- Deep reasoning retrieval: in reasoning mode, the model autonomously initiates retrieval during multi-step thinking, reads candidate links, and incorporates the evidence chain into the final answer;
- File input: supports formats such as portable documents, office documents, and images, with optional plain-text extraction or layout-aware parsing, and injects the results into the conversation context;
- Link reading: recognizes URLs in messages, fetches the main content, and answers in combination with the context;
- Content safety: applies basic risk control to inputs and outputs, and returns a refusal flag when a risk is hit.
The second layer is atomic tool interfaces. Retrieval, web crawling, optical character recognition, speech recognition, and speech synthesis can be called individually or in combination. This layer determines the “upper bound” of an application: when the automatic orchestration of the chat interface does not meet requirements, developers can build their own flows to implement more refined reranking, deduplication, and citation strategies.
3. Parameters and Context: An Illustrative Call Skeleton
The following code only illustrates the call shape; field names are subject to the actual documentation:
resp = client.chat.completions.create(model="<your-model-name>",messages=[{"role": "user", "content": "Compare the recall differences between two vector retrieval schemes"}],tools=[{"type": "web_search", "search_mode": "deep"}, # Deep reasoning retrieval{"type": "read_url"}, # Link reading{"type": "file_parse", "parse_mode": "layout"} # Layout-aware parsing],safety_check=True, # Input and output risk controlstream=True)
Three points deserve particular attention in engineering practice. First, citation traceability: require key conclusions in the answer to carry clickable sources for manual verification. Second, context budget: retrieval snippets and file parsing results both consume tokens, so set an upper limit on the number of snippets and apply summary compression. Third, idempotence and retries: tool calls are external side-effect operations, so implement fallback handling for timeouts, rate limits, and empty results.
4. Cost and Performance Control
Tool-based capabilities are usually billed separately by call volume, on top of model token fees. Effective cost-control measures include: routing by intent, so simple Q&A does not enable retrieval; caching high-frequency queries and already-parsed documents; performing structured extraction on long documents before putting them into context; and setting per-session tool call limits and daily quotas. On the performance side, it is recommended to use streaming output to reduce time to first token, parallelize retrieval and parsing, and instrument slow queries to form traceable call-chain logs.
5. Security, Compliance, and Observability
For applications that provide services to the public, in addition to enabling safety checks, obligations such as content moderation, algorithm and model filing, and generated-content labeling must be fulfilled. Technically, implement bidirectional filtering of inputs and outputs, masking of sensitive information, and retention of audit logs, and set thresholds through monitoring and alerting for refusal rate, retrieval hit rate, and tool error rate. Gray release and switch-based configuration keep the risk of launching new capabilities under control.
6. Conclusion
Capability integration does not weaken the value of developers; instead, it frees their energy from “connecting pipes” to scenario design and data closed loops. Atomic interfaces guarantee the lower bound, composable capabilities raise the upper bound, and security and cost run through everything as two horizontal lines. This methodology can be reused on any compliant model service, and it is also a pragmatic path for rapidly building conversational applications on Baidu AI Cloud.
