Combining Open APIs: A Technical Path to Building an Intelligent Assistant Prototype
This article explains how to build an intelligent assistant prototype using newly opened APIs that combine model calls with built-in tools such as web search, URL content fetching, file parsing, speech-to-text, and text-to-speech. It covers the capability matrix, differences from traditional integration approaches, preparation steps, a minimal integration example, auditing of tool-call records, cost estimation, tool-call frequency control, and common errors in real-time Q&A, document parsing, and voice application scenarios.
Background: Tool Capabilities Moving from Apps to APIs
In the past, if developers wanted a model to answer real-time questions, read files, or process speech, they typically had to integrate a search service, a document parsing component, and a speech recognition interface separately, then orchestrate everything in their own backend. Recently, a cloud provider opened up several capabilities—previously available only inside its own intelligent assistant application—as public APIs. Developers can now declare the required tools within a single model call; the server side handles retrieval, fetching, and parsing, then passes the results to the model to generate an answer.
This approach reduces orchestration code on the client side, but engineering problems do not disappear. Latency, cost, data compliance, and error handling still need to be designed by the developer. This article covers these aspects. All parameter names in this article are illustrative; refer to the target platform’s latest documentation for specifics.
Capability Matrix
| Capability | Input | Output | Common Limitations | Billing Method | Fallback on Failure |
|---|---|---|---|---|---|
| Web search | Natural-language question | Summary with source links | Freshness depends on index updates; result count has an upper limit | Per call | Answer using the model’s built-in knowledge and note that the information may not be current |
| Web page fetching | Specified URL | Body text | Dynamically rendered pages or pages requiring login may not be readable | Per call | Ask the user to paste the content directly |
| File parsing | PDF, images, Word, etc. | Structured text | File size and format limits; scan quality affects recognition accuracy | Refer to the pricing page | Return an error code and ask the user to compress, split, or convert the file |
| Speech-to-text | Audio file or audio stream | Timestamped text | Per-file duration limit; accuracy drops in noisy environments | Per audio duration | Ask the user to rephrase when confidence is low |
| Text-to-speech | Text | Audio | Text length limit; limited voice options | Refer to the pricing page | Fall back to displaying text |
The billing units and specific limits in the table above must be verified against the platform’s pricing page and technical documentation, as they may vary by region and plan.
Differences from Traditional Integration
A traditional solution usually consists of three types of components: an adapter layer for the search service, a document parsing service, and an asynchronous task queue. Each stage has its own timeouts, retries, and error formats, and the longer the chain, the more latency accumulates. The unified tool-calling approach moves the orchestration logic to the model server side, so the client typically only needs to make a single request.
The trade-off is less transparent debugging. Developers must read the tool-call records in the response to know which keywords the model searched for or which page it fetched. This is discussed further in the auditing section below.
Preparation Before Integration
- Create an API key in the platform console and confirm that the required tool capabilities are enabled.
- Store the key in environment variables or a secrets management service. Do not commit it to a code repository or print it to logs.
- Record the SDK version you are using and verify that it supports tool declaration parameters.
- Confirm request timeout and retry policies. Tool calls take longer than plain text conversations, so the timeout should be increased accordingly.
Minimal Integration Example
import osfrom openai import OpenAI # Illustrative: use the SDK or a compatible client provided by the platformclient = OpenAI(api_key=os.environ["PLATFORM_API_KEY"], # Read the key from an environment variablebase_url=os.environ["PLATFORM_BASE_URL"],timeout=60, # Tool calls are slower; set the timeout separately)response = client.chat.completions.create(model=os.environ["PLATFORM_MODEL"],messages=[{"role": "system", "content": "You are an information assistant. When citing search results, note the retrieval time."},{"role": "user", "content": "Please summarize the key points of this article: https://example.com/tech-article"},],tools=[{"type": "web_search"}, # Illustrative: web search{"type": "read_url"}, # Illustrative: URL content reading],)message = response.choices[0].messageprint(message.content)# Read tool-call records for debugging and auditingfor call in getattr(message, "tool_calls", None) or []:print(call.function.name, call.function.arguments)
The final answer text may be generated based on tool results, but it is not the same as the raw content returned by the tools. The raw structured records must be read from the fields specified in the documentation.
Response Structure and Auditing
The final answer is only part of the result. Developers should persist the following: the request ID, the names and parameters of the tools invoked, the source links and retrieval times returned by the tools, and the token consumption of the request. These fields help answer “why did the model respond this way” and serve as a basis for cost reconciliation.
Field names are subject to the platform documentation. Do not assume a field always exists in code; record a null value and raise an alert when it is missing.
Cost Model and Estimation
The cost of a single request typically consists of three parts: model input and output tokens, the number of tool calls, and audio duration for speech. You can estimate per-request cost with the following template:
Cost per request ≈ input tokens × input unit price + output tokens × output unit price + average searches × per-search price + average audio duration × per-duration price
All unit prices should be taken from the platform’s current pricing page. Whether off-peak discounts apply and whether prices include tax should also be confirmed on the pricing page or in the contract.
When estimating, do not base the average number of searches on ideal conditions alone. With automatic tool calling enabled, the model may search multiple times within a single conversation—for example, when a user asks follow-up questions about the same news event. It is recommended to run on gray (canary) traffic for a period, collect the real distribution of search counts, and then set a budget cap accordingly.
Controlling Tool-Call Frequency
Three common approaches:
- Specify trigger conditions in the system prompt—for example, search only when real-time information is involved.
- If the platform supports it, set a maximum number of tool calls per request.
- Cache results at the application layer. Build cache keys from normalized query strings or URLs and set a reasonable expiration time.
Scenarios and Common Errors
Real-Time Q&A
A common problem is that search returns too many results and redundant information fills the context. You can instruct the model in the prompt to extract only data points directly relevant to the question and to note the retrieval time of the information.
Document Parsing and Knowledge Bases
Common issues include files exceeding size limits, incompatible formats, and recognition errors caused by skewed scans. In production, preprocess files before upload: compress or split oversized files, and convert non-standard formats to PDF first. Parsed results should also be spot-checked before being ingested into the knowledge base.
Voice Applications
Short voice commands enable fast interactive feedback, while long recordings should be processed asynchronously. A common problem is that synchronous requests for long audio block
