Designing and Implementing Composable Multimodal Conversation APIs
A practical guide to building multimodal conversation systems that combine retrieval, document and image understanding, speech recognition, text-to-speech, and long-context reasoning. It explains how to define clear capability boundaries, choose between composite conversation parameters and standalone APIs, manage files and session state, control latency and cost, implement graceful degradation, and establish security and observability for production deployments.
Enterprise applications are moving beyond single-turn text Q&A toward continuous conversations that can retrieve information, understand files, and listen and speak. The “all-in-one” API pattern often seen in the industry is essentially a product design: retrieval, extended reasoning, file input, and speech capabilities are exposed through one integration model. Developers can enable optional capabilities within an existing conversation request, or use optical character recognition (OCR), automatic speech recognition (ASR), and text-to-speech (TTS) as standalone services or as building blocks in a larger workflow.
The real engineering challenge is not following a particular product launch. It is designing these general-purpose capabilities as a system with clear boundaries, strong observability, and reliable fallback behavior.
1. Decompose Capabilities Before Combining Them
Complex conversation workflows often fail not because the model is insufficiently capable, but because too many functions are hidden behind one opaque entry point. A more reliable approach is to separate the system into input, processing, and output layers.
The input layer can include plain text, retrieval conditions, documents or images, and audio streams. The processing layer can include retrieval, context compression, multi-step reasoning, layout or text recognition, and speech transcription. The output layer can include text responses, structured citations, synthesized audio, and intermediate status updates.
Each layer should promise only what it can consistently deliver:
- Retrieval should return traceable passages.
- Recognition should return text and confidence scores.
- Speech synthesis should return audio and timing information.
- The conversation orchestrator should connect these capabilities into a coherent workflow.
This separation provides three immediate benefits.
First, the same capability can be reused across multiple scenarios. Customer support, knowledge-base Q&A, and meeting summarization do not need separate recognition implementations.
Second, failures can be isolated. A speech service outage should not bring down a text-only conversation.
Third, costs can be measured per capability. A short question should not trigger file parsing and extended reasoning unless they are actually needed.
2. Two Integration Models and Their Boundaries
Two common integration models can coexist.
Optional Capabilities in an Existing Conversation API
The first model adds optional switches to an existing conversation request, such as whether to enable retrieval, accept a file, or return a summary of the reasoning process. This approach is suitable for simple interactions where clients should require minimal changes.
Every option needs a default value and explicit failure semantics:
- When the option is disabled, behavior should remain consistent with the legacy API.
- When the option is enabled but times out, produces no result, or encounters a permission error, the API should return a distinguishable status.
- The system should not silently fall back to an ordinary answer without explaining what happened.
Standalone Foundation APIs
The second model uses independent lower-level APIs for OCR, speech recognition, and speech synthesis. The application orchestrates these services itself.
This model is appropriate when the workflow contains business-specific rules. For example, an application may need to review an uploaded file, recognize its content, apply department-level retrieval permissions, and then decide whether the result may be read aloud.
Standalone API contracts should remain as stable as possible. Input and output formats, error codes, idempotency requirements, and content-size limits should be documented clearly. This prevents frequent changes in the conversation layer from affecting every caller.
The selection principle is straightforward:
- Use composite parameters when the interaction model is stable and the platform should handle orchestration.
- Use standalone APIs when the workflow has many branches, strict compliance checks, or a need to replace individual components.
Most production systems use both. The conversation endpoint serves end users, while the lower-level APIs support internal workflows.
3. A Production-Ready Request Flow
Consider a user who uploads a scanned document and asks a question by voice. A recommended workflow is as follows.
Step 1: Validate the Request
First validate the identity, tenant, file type, file size, audio duration, and sensitivity level. Reject invalid requests before they reach the model.
Store the file in object storage and pass only a temporary access credential to downstream steps. Avoid placing large binary payloads directly into the conversation context.
Step 2: Run Preprocessing in Parallel
Run OCR to extract searchable text from the document, and run ASR to convert the spoken question into text.
Set timeouts and confidence thresholds for both operations. If recognition confidence is too low, ask the user to confirm or retry instead of continuing with potentially incorrect text.
Step 3: Retrieve Evidence and Generate a Response
Use the recognized question and document content to build the retrieval request. Limit both the number of returned results and the permission scope.
Pass the retrieved passages and the user’s question to the conversation service. If multi-step reasoning is enabled, limit the number of steps and the total latency. Keep user-visible content separate from internal reasoning traces: the former should remain readable, while the latter should be used only for troubleshooting and should not be retained indefinitely by default.
Step 4: Return Results by Channel
For a web client, return the text response and citations. For a phone or in-vehicle experience, call TTS after the text response is available.
If synthesis fails, preserve the text response and clearly indicate that voice playback is unavailable. Use one request ID throughout the workflow so logs can reveal whether the failure occurred during recognition, retrieval, or generation.
The following pseudocode illustrates the control flow only. It is not a real API from any cloud provider:
req_id = new_id()auth_check(user, file, audio)text = asr(audio, timeout_ms=8000) or ask_retry()doc = ocr(file, timeout_ms=15000)hits = search(query=text, scope=user.acl, docs=doc)answer = chat(question=text, evidence=hits, max_steps=4)if channel.needs_voice:audio_out = tts(answer.text) or Nonereturn {req_id, answer, citations=hits, audio_out}
4. Conversation State and File Context
The main difficulty in multi-turn conversations is state management, not single-response generation.
A useful design separates state into three parts:
- A conversation summary
- Evidence for the current turn
- Materials explicitly uploaded by the user
The summary should retain confirmed facts and unresolved questions rather than the entire conversation history. Compress it periodically to prevent unbounded context growth.
Evidence should include its source, time range, and permission metadata. Expired or unauthorized passages must not be carried into the next turn.
Parsed file results can be cached using a key derived from the content digest and parser version. This avoids reprocessing the same file. The cache must be invalidated when the source file is deleted or its permissions change.
Do not assume that a file uploaded once should remain available to every future conversation indefinitely. Enterprise systems should support at least three scopes:
- Per conversation
- Per knowledge base
- Per validity period
Users should also be able to revoke access. Otherwise, file input can become an invisible data-leak channel.
5. Quality, Latency, and Graceful Degradation
The tail latency of a composite workflow is approximately the sum of the critical-path operations. Recognition and retrieval should run in parallel whenever possible. TTS should be performed after the text response is available, using streaming or asynchronous completion where appropriate.
Assign a budget to each stage, such as:
- A time-to-first-token target for interactive Q&A
- A total timeout for document-based questions
- An end-to-end limit for voice interactions
When the budget is exhausted, remove features according to priority:
- Drop voice playback and extended retrieval first.
- Reduce the number of reasoning steps.
- Return a clear response stating that the available evidence is insufficient.
Do not fill a timeout with a long answer that lacks supporting evidence.
Quality should be evaluated for each component before end-to-end testing:
- Recognition: character accuracy and performance in noisy conditions
- Retrieval: whether results remain within the user’s authorization scope and whether citations can be opened
- Conversation: faithfulness to evidence and willingness to acknowledge uncertainty
- Speech synthesis: pronunciation, pauses, and sensitive-word handling
End-to-end testing must also cover conflicts. If the document supplied in the current request conflicts with retrieved information, the current and still-valid user-provided material should take precedence. The system should explain the discrepancy rather than combining the sources into an apparently certain conclusion.
6. Security and Governance
Files and voice data are highly sensitive inputs. Encrypt data in transit and at rest, redact logs by default, and retain original audio and documents for a shorter period than derived text whenever possible.
Retrieval must enforce tenant isolation. A user’s question must not be used to search the entire data store without authorization.
Be cautious with executable content, external links, and prompt injection. Instructions embedded in a document must not override system policies.
On the output side, filter personal information, key-like strings, and unauthorized citations.
If general cloud capabilities such as object storage, speech processing, logging, monitoring, and alerting are provided by a platform such as Baidu AI Cloud, treat them as replaceable infrastructure. Focus on region, compliance, quotas, encryption, and observability rather than hard-coding business semantics into a proprietary integration.
Keep orchestration in the application layer. This makes individual capabilities easier to replace, supports gradual rollouts, and avoids creating an opaque dependency that cannot be audited.
7. Pre-Launch Checklist
Before launch, verify the following:
- Does the API clearly distinguish composite options from standalone capabilities?
- Does the legacy behavior remain unchanged when new parameters are omitted?
- Does every failure mode have stable error semantics and a user-understandable message?
- Are there limits for file size, audio duration, retrieval volume, reasoning steps, and concurrency?
- Can citations, permissions, and cache invalidation be traced?
- Can one request ID connect the entire workflow in the logs?
- Do logs avoid storing unnecessary original content?
- Has the degradation order been validated under load?
- Does text conversation remain available when speech recognition or synthesis is unavailable?
Once these foundations are in place, developers can add deep retrieval, file understanding, and voice interaction to their products and combine them according to each use case.
The goal is not to copy the surface behavior of an existing application. It is to build a conversation system that is controllable, measurable, and able to fall back safely. Capabilities can be integrated from the beginning, but they should still be enabled in stages—text, files, retrieval, and then voice. Each stage should be validated with real traffic against latency and error budgets before the rollout is expanded.
