Adding Web Search and File Parsing to Chat APIs: A Practical Guide
This article presents a vendor-neutral framework for integrating web search, link reading, and file parsing into conversational APIs. It breaks down four types of external input, compares embedded versus standalone interface designs, explains where session costs come from, and outlines a baseline-first evaluation approach. Developers will find practical guidance on evidence extraction, chunking, citation binding, cost guardrails, and graceful degradation for building retrieval-augmented chat applications that are both capable and trustworthy.
1. Introduction: Chat APIs Are Moving From “Conversational” to “Verifiable”
Over the past two years, the core metrics for conversational APIs have been language fluency and reasoning coherence. In real business scenarios, however, user questions often depend on external facts: the latest revisions to policies and regulations, version differences in product documentation, specific figures in financial reports, and the exact boundaries of contract clauses. Knowledge contained within model parameters alone cannot guarantee timeliness or traceability. As a result, “connecting search and file reading to chat APIs” has become a shared technical direction across the industry: models no longer just generate text, but can trigger retrieval, fetch web pages, and parse documents on demand within a single session, organizing evidence into their answers.
This article uses a cloud vendor’s release of web search, think-while-searching, link reading, and file reading capabilities in its chat API as technical background, and abstracts a general, vendor-neutral practice framework. It is worth emphasizing that platforms differ significantly in interface shape, billing models, and index coverage; engineering implementation should always defer to the official documentation. This article focuses on how to design, how to evaluate, and how to control costs, rather than a feature list for any single product.
2. Capability Breakdown: What Do the Four Types of “External Input” Actually Solve?
Connecting external capabilities to a chat API essentially adds a layer of “schedulable fact sources” in front of the model’s context window. They can commonly be abstracted into four types:
- Web Search: Given a query, return relevant web entries and summaries. It solves the “I don’t know where to look” problem and suits open-ended, time-sensitive questions.
- Deep Search (think-while-searching): The model first decomposes the question into several sub-queries, then iteratively retrieves, compares, and converges. It solves the “the question is too composite for a single retrieval to cover” problem, at the cost of higher latency and more requests.
- Link Reading (Fetch/Read Link): Given one or more URLs, fetch the content and extract readable text. It solves the “I already know where the information is and just need to read it in” problem, with content extraction quality and noise filtering being key.
- File Input (File/OCR): Upload documents or images, which are parsed and recognized before being used as context. It solves the “facts live in private materials” problem, with difficulties in real-world scenarios like complex layouts, tables spanning pages, and skewed scans.
These four capabilities can be used individually or combined: first use search to locate candidate sources, then use link reading to fetch the content, and finally cross-verify private clauses in files against them. In engineering terms, treat them as “pluggable tools,” with the orchestration layer deciding when to call them, how many times, and how to trim results.
3. Interface Layering: Embedded in Chat vs. Standalone Interfaces
Architecturally, external capabilities are typically exposed in two ways: enabled on demand within a chat request, or called separately as standalone interfaces. The two are not substitutes but serve different scenarios.
- Embedded: A single chat request can carry switches such as “allow web access” and “allow file reading,” and the model decides whether to retrieve on its own. The advantage is simple integration and natural context continuity; the downside is weaker controllability and a tendency toward “unnecessary retrieval.”
- Standalone: Retrieval, fetching, and recognition are each independent interfaces orchestrated by the business logic. The advantage is that every step is observable, cacheable, and retryable; the downside is that you must implement the tool-calling protocol and result backfilling yourself.
The recommended approach is a “two-layer structure”: the chat API handles language organization and tool decisions, while standalone interfaces handle deterministic capabilities. Illustrative pseudocode follows (it only expresses orchestration logic, not any vendor’s real parameters):
# Pseudocode: orchestrating a chat turn with retrievalplan = chat.plan(question) # model decides whether to retrieve and how many timesevidence = []for q in plan.queries:hits = search(q, top_k=5) # standalone search interfacefor h in hits:text = fetch(h.url) # standalone fetch / content extractionevidence.append(chunk(text))answer = chat.answer(question, context=evidence) # generate after backfilling evidence
This layering allows “retrieval quality” and “generation quality” to be evaluated and optimized separately, avoiding mixing the two problems together.
4. Cost Perspective: Where Does a Session Actually Get Expensive?
What developers care about most is the bill. As an example from a real measurement: one API key aggregated about 0.05 yuan, 13 requests, and roughly 17,000 tokens for the day. The number itself has no universal meaning, but it reveals an important fact: external capabilities amplify “one conversation” into “multiple calls.”
Cost is usually made up of three parts: input tokens (including web content and file fragments stuffed into context), output tokens, and per-call billing for capability invocations such as retrieval, fetching, and recognition. Deep search is more expensive because it triggers multiple rounds of sub-queries and multiple fetches. Effective cost-control measures include:
- Evidence trimming: Keep only the passages most relevant to the question, limiting the length of each piece of evidence and the total count.
- Caching: Cache results for high-frequency queries and popular links, with a reasonable TTL.
- Tiered triggering: Route simple factual questions to a single search, and enable deep search only for composite questions.
- Batching and async: Send offline document parsing to asynchronous tasks to avoid occupying the interactive path.
- Budget guardrails: Set a maximum number of retrievals and a maximum context length per session, degrading to “answer without retrieval plus a notice” when exceeded.
5. Quality Evaluation: Establish a Baseline First, Then Talk About Enhancement
Many teams feel “slower and more expensive but not better” after integrating retrieval; the root cause is a missing baseline. The recommended minimal evaluation plan:
- Baseline set: Prepare 50–200 real business questions covering factual, time-sensitive, document-based, and refusal types.
- Baseline run: Turn off all external capabilities and record accuracy, citation rate, and latency.
- Enable one by one: Turn on search, link reading, and file input separately, and observe the increments.
- Combined run: Enable combined capabilities and assess whether the marginal benefit covers the marginal cost.
- Regression: Re-run after every prompt or model version change to prevent capability regression.
For metrics, beyond answer accuracy, also track evidence hit rate (whether citations genuinely support the conclusion), noise rate (the proportion of irrelevant content introduced), and refusal appropriateness (whether it refuses when it should). Illustrative table:
| Configuration | Accuracy | Evidence Hit Rate | Avg. Latency | Cost per Call |
|---|---|---|---|---|
| Pure chat baseline | Baseline | None | Low | Low |
| +Search | Improved | Medium | Medium | Medium |
| +Deep search | Slight gain | High | High | High |
| +File input | Depends on document quality | High | Medium | Medium |
6. Engineering Details: Content Extraction, Chunking, and Citation
The effectiveness of retrieval augmentation depends 80% on the quality of the evidence fed in.
- Content extraction: Web pages are full of navigation, ads, and recommendation slots, requiring template-based cleaning; for dynamically rendered pages, assess whether the rendering cost is worthwhile.
- Chunking strategy: Split by semantic paragraphs and preserve heading hierarchy; keep tables as whole blocks to avoid cross-page breaks.
- Citation binding: Generate a stable ID for each piece of evidence and annotate sources in the answer for auditing and user verification.
- Conflict handling: When multiple sources conflict, prioritize the more recent and more authoritative ones, and explicitly explain the disagreement in the answer.
- Privacy and compliance: File input involves private data, so define data retention policies, encrypted transmission, and access controls, and avoid writing sensitive content into logs.
7. Degradation and Observability
External capabilities are inherently unstable: search may time out, fetching may be blocked by anti-scraping, and recognition may fail. A mature system must have degradation paths: if retrieval fails, fall back to model knowledge with an uncertainty notice; if fetching fails, use only the summary; if file parsing fails, ask the user to re-upload or convert to text. For observability, log the time, number of results returned, token increment, and failure reason for each tool call, and build a dashboard to pinpoint whether “retrieval failed to recall” or “generation didn’t use the evidence well.”
8. Conclusion
Connecting search and file reading to a chat API is not simply adding a few switches; it transforms the conversational system from a “closed-book exam” into an “open-book exam”: the model is responsible for understanding and organization, while external capabilities provide verifiable facts. For developers, the real competitive edge lies not in whether a given capability is used, but in whether orchestration is fine-grained, whether evaluation has a baseline, whether cost has guardrails, and whether degradation is predictable. Building such a retrieval-augmented pipeline on top of general cloud product capabilities offered by platforms like Baidu AI Cloud is what makes conversational applications both smart and trustworthy.
