Large Model API Integration: A Practical Guide to Search and Document Parsing
This guide explains how modern large model APIs are shifting from plain text inference to server-side tool execution, covering built-in search, web crawling, document parsing, and voice capabilities. It details capability boundaries, a reusable client skeleton, evaluation methods for six core features, and governance practices for cost, latency, and reliability. Developers will learn how to route requests, cache results, and maintain observability when orchestrating tools on the server side.
1. The Trend: From “Model API” to “Runtime API”
Over the past year, the shape of large model APIs has changed structurally. Vendors no longer offer only “text in, text out” inference endpoints. Instead, they are moving the full runtime that already powers their consumer products—web search, interleaved reasoning and retrieval, web page fetching, document parsing, speech recognition, and speech synthesis—into the chat interface as optional, on-demand features.
For developers, this is not just “a few extra switches.” The position of tool invocation and context assembly has shifted: from the client to the server. Understanding this shift is the prerequisite for every engineering trade-off that follows.
1.1 Two Layers of Capability
From an engineering perspective, these offerings typically have a clear two-layer structure:
- Layer 1: Tool capabilities inside the chat endpoint. Enabled on demand under mainstream API protocols (OpenAI-compatible, Anthropic-compatible, etc.). Common options include web search, deep search (the model decides what to search next during reasoning), file input (PDF, Word, presentations, usually with per-file size and page limits), link reading, and content safety checks.
- Layer 2: Five independently callable atomic endpoints: search, fetch, document parsing (OCR), speech recognition (ASR), and speech synthesis (TTS). They do not depend on chat context and can be reused directly in batch pipelines and offline workflows.
The value of this layering: chat scenarios need loosely coupled, out-of-the-box tools, while data pipelines need composable atomic capabilities. The two should not be forced into the same abstraction.
1.2 The Glue Code You No Longer Write
In the era of inference-only endpoints, building a decent retrieval-augmented application required you to handle: search provider selection and integration, web page text extraction, document pagination and layout restoration, reranking of retrieval results, context trimming, citation annotation, and retry logic. None of this is business logic, yet it consumed more than 60% of early-stage engineering effort.
With the server taking over, the client still owns three things: conversation state management, rendering of server-returned results, and observability of cost and latency. This article focuses on these three.
2. Capability Boundaries and Engineering Constraints (Read First)
Before writing code, document these boundaries in your design spec, or you will likely rework during load testing:
- Tool invocation is model-driven. With deep search enabled, a single turn may include a dozen or more tool operations (search, open page, in-page find). This means latency variance per request is extremely high; timeouts and fallback strategies are mandatory.
- File input has hard limits. Typical constraints: about 100 MiB per file and about 1000 pages. Reject oversized files on the client before sending, rather than waiting for a server error.
- Billing is a mix of per-call and per-token. Tool calls such as search, fetch, and parsing are usually billed per call; the conversation itself is billed per token. Cost estimation cannot look at tokens alone.
- Content safety checks should be on by default. They are both a compliance requirement and a way to keep invalid context out of the model.
3. Implementation: A Reusable Client Skeleton
The vendor-agnostic pseudocode below shows the minimal loop of “enable tools on demand + render server results.”
# Pseudocode: vendor-agnostic tool-enabled chat skeletonclient = LLMClient(base_url=BASE_URL, api_key=API_KEY)resp = client.chat.create(model=MODEL_NAME,messages=[{"role": "user", "content": "Compare the latest funding rounds of two companies"}],tools={"web_search": True, # web search"deep_search": True, # search while reasoning"read_url": True, # read a link"safety_check": True, # content safety check},timeout=90, # deep search requires a longer timeout)for item in resp.tool_trace: # tool trace returned by the serverprint(item.type, item.status, item.latency_ms)print(resp.answer, resp.citations) # answer text + citation sources
Key design points:
- Always log the tool trace. It is your only basis for investigating “why was this request so slow/expensive.”
- Always render citations. A retrieval-augmented answer without source attribution is effectively unusable in production.
- Layer your timeouts: 10–20 seconds for normal chat, 60–120 seconds when deep search is enabled, paired with streaming output to improve perceived responsiveness.
4. Evaluation: How to Test the Six Capabilities Scientifically
Do not judge “good or bad” by feel. Use a repeatable evaluation script:
- Baseline chat: pure inference; record time to first token and total duration as a control.
- Web search: ask a time-sensitive, single-answer factual question and manually verify the answer against authoritative public sources.
- Deep search: give a question requiring cross-source synthesis; observe the number of tool calls and reasoning token consumption.
- Link reading: provide a well-structured public web page and check whether the summary covers the core arguments.
- File input: create a test document with two or three fictional but locatable data points (e.g., a specific budget figure, an internal codename) and verify the model actually “read” them rather than “guessed.” This is the most effective way to distinguish real parsing from hallucination.
- Standalone search endpoint: call it outside the chat flow to verify composability.
A typical finding in practice: enabling deep search causes token consumption to jump by an order of magnitude, because reasoning and retrieval alternate. It is therefore suited to high-value, low-frequency complex questions, not to full traffic.
5. Cost, Latency, and Reliability Governance
- Tiered routing: simple Q&A uses normal mode; complex questions use deep search. Use rules or a small model for pre-classification.
- Cache first: build a semantic cache for high-frequency factual questions; a decent hit rate can significantly reduce the bill.
- Budget guardrails: set daily budget alerts per API key, with threshold notifications via a monitoring and alerting service.
- Fallback path: when search is unavailable, fall back to a pure model answer and explicitly label it “not live,” avoiding silent failure.
- Observability trio: a logging service records tool traces; monitoring and alerting tracks latency percentiles and error rates; object storage archives raw documents and response snapshots for replay.
6. Common Pitfalls
- Making deep search the default. It is a cost amplifier, not a UX enhancer.
- Ignoring context trimming. Long retrieved pages consume the context budget quickly; rerank and truncate.
- Not managing state on the client. The server handles tool assembly, but multi-turn conversation state still lives on the client and must be maintained there.
- Skipping pre-upload file validation. Oversized files should be blocked before upload with a clear message.
7. Conclusion
Moving search, fetch, document parsing, and voice capabilities to the server essentially turns the barrier to building retrieval-augmented applications from an engineering problem into a configuration problem. Developer competitiveness will shift from “can you call tools” to “can you orchestrate tools”—tiered routing, caching, observability, and cost guardrails are the new moat. On platforms such as Baidu AI Cloud, combining general-purpose capabilities like object storage, message queues, logging, and monitoring and alerting to build this orchestration layer is currently the most cost-effective path.
