Adding On-Demand Web Search and File Reading to Conversational APIs
This article explains how conversational APIs can enable web search, deep search, link reading, and file input on demand, so developers no longer need to build separate pipelines for search, web scraping, file parsing, chunking, retrieval, and model calls. It covers the four capabilities, a reference architecture built around a policy layer, a staged testing method, and practical guidance on cost, latency, and risk governance.
1. From Client Features to API Capabilities: A Shift in Integration
Web search, file reading, and link parsing were once mostly tied to specific client products. Developers who wanted similar experiences in their own systems had to assemble many components themselves: search services, web scraping, file parsing, text chunking, vector retrieval, and model calls. A clearer trend is now emerging. Conversational APIs no longer accept only plain text messages. They let callers enable search, deep-thinking retrieval, link reading, and file input on demand. Information retrieval and content understanding become part of the conversation pipeline and are orchestrated together.
The value of this change is not an extra button. It is the packaging of a complex pipeline into configurable capabilities. In a single request, a developer can declare whether web search is enabled, whether files can be read, and whether deep-thinking retrieval mode is used. This reduces the cost of maintaining a custom pipeline. Voice input and voice output are typically still handled by separate speech interfaces. Search, web scraping, and text recognition may also be available as standalone calls, so different business scenarios can combine them as needed.
On-demand activation matters because capabilities are not enabled by default. Leaving everything on by default can create problems with cost, latency, privacy, and result stability. On-demand activation requires developers to set clear rules in their business logic. They must decide which questions need real-time information, which files may be uploaded, which links may be fetched, and which scenarios require keeping citations and audit records.
2. Breaking Down the Capabilities: Search, Deep Retrieval, Link Reading, and File Input
These capabilities fall into four categories.
The first is web search. It suits questions that depend on current events or external facts. Engineering work should focus on query rewriting, the number of results, source credibility, deduplication, and summary compression. Inserting a large number of search results directly into the context increases token consumption and dilutes key information. Relevance filtering and evidence compression should come first.
The second is retrieval in deep-thinking mode. Here, the model forms queries, gathers more evidence, and revises its conclusions during reasoning. Compared with a single search, this mode works better for multi-hop questions, comparative analysis, and tasks that require cross-checking. Multiple rounds of retrieval, however, increase latency and cost. Developers should set a maximum number of retrieval rounds, a timeout budget, and a fallback strategy for failures.
The third is link reading. The caller passes a link, and the service fetches the page and extracts the main content. Engineering work must handle dynamic pages, anti-scraping restrictions, main-content extraction, encoding detection, and content truncation. On the business side, teams should set domain allowlists, size limits, and sensitive-content rules so that uncontrolled pages do not go straight to the model.
The fourth is file input. Common file types include text documents, spreadsheets, presentations, and scanned documents. Scanned documents usually require optical character recognition (OCR) or layout analysis. Long documents require chunking, summarization, retrieval, and citation localization. The key question for file input is not whether files can be read, but whether results are accurate, traceable, and permission-controlled. Teams should log the file source, parser version, and cited snippets in the request metadata to support later audits.
3. Reference Architecture: Making On-Demand Calls Governable
A workable architecture can be divided into five layers: access, policy, capability, model, and observability.
The access layer handles authentication, rate limiting, request validation, and file upload controls. The policy layer decides whether to enable search, deep retrieval, link reading, or file input. It bases this decision on user intent, business scenario, tenant configuration, and data sensitivity. The capability layer performs search, scraping, parsing, text recognition, chunking, and retrieval. The model layer generates the conversation response, integrates evidence, and annotates citations. The observability layer records request volume, token consumption, latency, failure rate, retrieval hit rate, and cost.
The following pseudocode illustrates the flow:
def handle_turn(request):policy = decide_policy(request.tenant, request.text, request.files)evidence = []if policy.enable_search and need_fresh_info(request.text):queries = rewrite_query(request.text)evidence += search(queries, top_k=policy.top_k, timeout=policy.timeout)if policy.enable_deep_search and is_multi_hop(request.text):for round in range(policy.max_rounds):queries = plan_next_queries(request.text, evidence)evidence += search(queries, top_k=policy.top_k)if enough_evidence(evidence):breakif policy.enable_link and request.links:evidence += read_links(request.links, allowlist=policy.domain_allowlist)if policy.enable_file and request.files:parsed = parse_files(request.files, max_size=policy.max_file_size)evidence += retrieve_relevant_chunks(request.text, parsed, top_n=policy.top_n)context = compress_and_cite(evidence)answer = chat_model.generate(request.text, context=context, mode=policy.mode)return attach_citations(answer, evidence)
The key point of this pseudocode is not the specific interfaces. It is that policy comes first. The system decides whether external information is needed, then controls the number of retrieval rounds, the source scope, the file size limit, and the context compression method. Without a policy layer, “on demand” easily becomes “always on,” which makes cost unpredictable and results hard to explain.
4. Validation: From a Small Baseline to Per-Capability Tests
To validate this kind of API integration, use a four-step method: baseline, component-level testing, standalone calls, and cost review.
Start with a pure conversation baseline and record latency, output quality, and token consumption. Then test each of the four conversation capabilities (web search, deep-thinking retrieval, link reading, and file input) separately. Observe how each one affects answer accuracy, citation completeness, and latency. Finally, call the search capability on its own to confirm that it works outside the conversation pipeline. Standalone web scraping, standalone text recognition, and voice input and output can be tested in later rounds, which avoids introducing too many variables at once.
In a small-scale validation described in public materials, 13 API requests consumed about 17,000 tokens, and the daily bill totaled 0.05 yuan (CNY). This figure is only a rough reference for cost magnitude. It does not represent general billing rules. Developers should build their own cost model by tracking requests, input tokens, output tokens, retrieval calls, file parsing volume, and standalone capability calls separately, then budget against peak business load.
At minimum, monitor average and P95 latency, search hit rate, citation traceability rate, file parsing failure rate, context compression ratio, median tokens per request, retry rate, and the cost of each successful answer. On-demand activation is only operable in production when these metrics are monitored and tied to alerts.
5. Cost, Performance, and Risk Governance
Cost governance comes down to using fewer, more precise resources. Do not inflate the search top_k value without a reason. Set a maximum number of rounds for deep retrieval. Check file type and size before accepting uploads. Retrieve relevant parts of long documents before injecting them into the context. Extract and truncate content when reading links. For frequent questions, caching and result reuse can help. When evidence confidence is low, trigger a fallback instead of forcing a generated answer.
Performance governance should separate synchronous and asynchronous work. Real-time conversation is sensitive to time-to-first-token. The system can show a “searching” status first, then stream the answer. File parsing and deep retrieval can run asynchronously as preprocessing. Timeout policies should be explicit. If search times out, fall back to a pure model answer. If file parsing fails, return an understandable error. If a link cannot be read, tell the user to try a different source.
Risk governance covers permissions, privacy, compliance, and auditing. File input should enforce tenant isolation and least-privilege access. Link reading should restrict domains and content types. Search evidence should keep its source and timestamp. Logs should not store sensitive original text. Outputs should carry citations, so users can verify them. For questions involving personal privacy, trade secrets, or high-risk decisions, external retrieval should be off by default or subject to human review.
6. Engineering Recommendations
First, manage capability switches at three levels: tenant, scenario, and request. Avoid hard-coding them. Second, define a unified evidence object model that includes the source, title, snippet, time, confidence score, and citation location. Third, decouple retrieval, parsing, generation, and citation annotation so each can be replaced or rolled out gradually. Fourth, build a regression test set that covers time-sensitive questions, multi-hop questions, long-document questions, and unreadable links. Fifth, attribute costs continuously by breaking down bills by business line and capability.
Overall, connecting search and file reading to a conversational API means turning “information retrieval, evidence compression, and cited generation” into an orchestrated engineering capability. Developers should build the full pipeline around on-demand activation, policy governance, observability, and risk control. Checking whether a single request succeeds is not enough. Only with these controls can a team keep answer quality high while managing cost, latency, and compliance risk, and build an AI application that can be run sustainably in production.
