How to Turn LLM Client Capabilities into APIs: A Practical Guide
This article walks through the architectural shift from a monolithic AI client to composable, API-based capabilities. It covers atomic capability design, model-driven web search in both standard and deep-thinking modes, standardized OCR and speech interfaces, a five-stage orchestration layer, and the reliability, cost, and governance practices needed to run these services in production.
1. From a Monolithic Client to Composable Capabilities
In the past, an AI assistant client often tightly coupled capabilities such as web search, document parsing, and voice interaction inside a single process: the UI layer called internal functions directly, and capabilities passed context to each other through implicit state. This structure is efficient for a demo, but once it reaches production, three problems surface: capabilities cannot be reused by third parties, upgrades require a full regression pass, and canary release and rate limiting are too coarse-grained.
“Breaking the client into APIs” essentially means making the capability boundaries that were hidden behind the UI explicit, forming a set of services with clear semantics that can be deployed and measured independently. For developers, the payoff is being able to replicate the official experience 1:1 using the same building blocks. For enterprises, the payoff is that each capability can scale, be observed, and evolve independently.
The split usually follows three principles:
- Atomic capabilities: each interface solves one class of problem, such as “search,” “extract text,” or “speech-to-text.”
- Orchestration moves up: multi-step flows are not hard-coded on the server side; the caller or an upper orchestration layer decides the order.
- Stable contracts: inputs and outputs use structured schemas and evolve through versioning, avoiding breaking changes.
2. Web Search: From a Two-Stage Pipeline to Model-Driven Decisions
The most valuable point in the original material is this: web search is no longer a fixed pipeline that “retrieves first, then feeds results to the model.” Instead, the model autonomously decides during inference whether to search, what to search for, and when to stop.
2.1 Lightweight Search in Non-Thinking Mode
With the search tool enabled in regular conversation mode, the model judges from the semantics of the question whether it needs to access the network and whether it needs text or images, and it attaches sources to the answer. On the engineering side, this requires the response structure to contain both an “answer fragment” and a “citation list,” so developers can render clickable sources.
Illustrative response structure (pseudocode):
{"answer": "……","citations": [{"title": "……", "snippet": "……", "source": "……"}],"tool_calls": [{"name": "web_search", "query": "……", "type": "text"}]}
2.2 Multi-Step Search in Deep Thinking Mode
After switching to thinking mode, the model embeds search into its chain of thought: it first decomposes the question, then gathers evidence item by item, reads the content of links, continues searching after finding gaps, and finally converges on a conclusion. Compared with a fixed pipeline, its advantage is “evidence on demand,” which reduces ineffective searches and significantly improves accuracy on multi-hop questions that require chaining multiple facts.
Developers should note that multi-step search introduces latency jitter, so the interface layer should support streaming intermediate steps, and the frontend should present them as “verifying clue N,” avoiding a long blank screen for the user.
3. OCR and Speech: Standardizing Multimodal Input
Replicating the client experience requires multimodal input. The common approach is to abstract the two capabilities into separate interfaces:
- OCR interface: takes an image or scanned file as input and outputs text blocks with coordinates and reading order, making downstream structured extraction easier.
- Speech interface: covers two directions, speech-to-text and text-to-speech. Transcription outputs timestamped sentences; synthesis supports voice and speed parameters.
The engineering focus is normalization: regardless of whether the input comes from a photo, a screenshot, or an audio stream, it is first converted into a unified intermediate representation (an array of text blocks, an array of timestamped sentences) before being handed to the inference layer. This way, upper-layer orchestration logic does not need to be aware of input format differences.
# Pseudocode: normalize multimodal inputdef normalize(inputs):blocks = []for item in inputs:if item.type == "image":blocks += ocr(item.data) # returns text blocks + coordinateselif item.type == "audio":blocks += asr(item.data) # returns timestamped sentenceselse:blocks.append({"text": item.data})return sorted(blocks, key=lambda b: b["order"])
4. Designing the Orchestration Layer to Replicate the Client
Once you have atomic capabilities, the orchestration layer is what really determines the experience. A five-stage approach is recommended: intent recognition, plan generation, tool invocation, result validation, and rendering.
- Intent recognition: determine whether the request is chitchat, search-based Q&A, document Q&A, or a voice command.
- Plan generation: the model outputs a sequence of tool calls instead of hard-coded if-else logic.
- Tool invocation: run independent calls concurrently and dependent calls sequentially.
- Result validation: validate citation completeness, timestamps, and coordinates against the schema; retry or degrade on failure.
- Rendering: stream the answer, citation cards, and voice playback.
When implementing this on Baidu AI Cloud, you can combine general-purpose capabilities: use the container platform to host stateless orchestration services, use a message queue to smooth peaks and decouple long-running tasks (such as batch document recognition), use object storage to keep original files and intermediate artifacts, and use logging and monitoring with alerting for full-link tracing and quota alerts. This keeps the interfaces elastic while making costs measurable.
5. Reliability, Cost, and Governance
After capabilities are split, governance complexity increases and needs to be designed upfront:
- Rate limiting and quotas: set QPS and concurrency limits per interface to prevent search-type interfaces from dragging down the whole system.
- Caching strategy: apply short-TTL caching to high-frequency, low-timeliness search results to reduce latency and cost.
- Degradation path: when search is unavailable, fall back to the model’s internal knowledge and clearly label the answer as “not from the web.”
- Observability: record the latency, hit rate, and failure reasons of each tool call to form a traceable call chain.
- Security and compliance: manage the lifecycle of uploaded images and audio, and mask sensitive data before it enters logs.
6. Conclusion
Breaking client capabilities into APIs is not simply an “interface refactoring”; it is a shift in architectural paradigm: atomic capabilities, orchestration moved up, and stable contracts. When web search evolves into model-driven multi-step evidence gathering, and when OCR and speech are normalized into a unified intermediate representation, developers have all the building blocks needed to match the official experience. With general-purpose capabilities on Baidu AI Cloud such as the container platform, message queue, object storage, and monitoring with alerting, teams can build, observe, and continuously evolve their own AI client at a low marginal cost.
