LLM API Integration: Web Search, File Parsing, and Safety in Practice

    This article explains how to build LLM applications that combine web search, file parsing, link reading, and safety checks through API integration. It covers capability boundaries, standalone API usage, orchestration architecture, engineering practices such as timeouts, caching, retries, and context management, and compliance considerations for public-facing applications.

    1. Background: From a Q&A Endpoint to a Complete Application

    Early LLM APIs mainly did one thing: receive text and return text. That was enough for simple Q&A demos, but it was rarely enough to support a usable application. User questions often depend on the latest information, uploaded materials are often PDFs, spreadsheets, and scanned documents, and messages may also include web links. If the model relies only on knowledge from training, its answers may be outdated, and it cannot read the actual materials the user has at hand.

    As a result, developers usually need to build a complete supporting stack themselves: a search service to retrieve external information, a parsing service to convert files into model-readable text, a fetching service to read web page content, and a safety module to filter prohibited content. In the past, each capability had to be purchased, integrated, and maintained separately, which created significant engineering overhead.

    A more mature approach today is for the model service to provide these capabilities directly. Developers use declarative tool configuration to decide whether the model should call them, and they can reuse the underlying capabilities separately through standalone APIs. Understanding the boundaries of these capabilities is the first step in designing the application architecture.

    2. Core Capabilities

    2.1 Web Search in Non-Thinking Mode

    In non-thinking mode, the model does not expand multi-step reasoning when handling a question. After the web search tool is enabled, the model decides whether the question requires external information. If it does, the model automatically initiates a web or image search, integrates the retrieval results into the answer, and includes cited sources.

    This mode is suitable for scenarios such as:

    • Questions that depend heavily on timeliness, such as news, prices, and weather;
    • Reference-style Q&A that needs to provide sources;
    • Customer service scenarios that require fast responses and involve relatively direct questions.

    Note that displaying cited sources is the application layer’s responsibility. Developers should keep source links visible in the interface so users can verify the information themselves.

    2.2 Multi-Step Retrieval in Thinking Mode

    Thinking mode makes the model perform multi-step reasoning before answering. After the search tool is enabled, the model can use intermediate conclusions during reasoning to decide what to retrieve next, which link to open, and whether additional information is needed.

    Compared with a single search, this approach is better suited to complex questions, such as comparing the historical evolution of multiple solutions or providing a comprehensive analysis of a technical controversy. The tradeoff is longer latency, and the number of retrievals during reasoning increases. Therefore, the product should set reasonable timeouts and progress messages so users do not wait for a long time without seeing any progress.

    2.3 File Input: Text Extraction and Mixed Layout Parsing

    File input supports formats such as PDF, Office documents, and images. The system first performs plain text extraction. For files that contain charts, scanned pages, or mixed text-and-image layouts, it performs layout parsing and then concatenates the result into the conversation context.

    In practice, three points deserve attention:

    1. File size and page count affect context length. Long documents should be split first, and only the relevant sections should be sent into the context.
    2. The recognition quality of scanned documents directly determines the accuracy of subsequent answers. Recognition results should be sampled and checked before launch.
    3. Tabular content may lose row-column relationships after being converted to text. For scenarios involving numerical calculations, it is advisable to let the model read both the table headers and the original cell information.

    After the link reading tool is enabled, the model identifies URLs in user messages, fetches the web page content, and answers based on the context. This addresses a high-frequency need: users paste a link and ask the model to summarize it.

    Developers need to pay attention to two types of issues. The first is fetch scope: some pages require login or depend on dynamically rendered scripts, so the fetched result may be incomplete. The second is content credibility: web page content is external data, and the model may be influenced by misleading text on the page. Answers should therefore distinguish between “what the page claims” and “conclusions that have been verified.”

    2.5 Safety Checks

    When the safety check parameter is enabled, the service performs basic risk control on model input and output. When a risk rule is triggered, the API returns a refusal flag, and the application should display a unified prompt based on that flag instead of showing an empty result or the raw error directly to the user.

    Applications that provide public services should always enable this parameter. Safety checks are only a basic line of defense. Application providers still need to establish their own content review processes, including sensitive word lists, manual review channels, and mechanisms for recording and handling abnormal content.

    3. Standalone Capabilities: Compose Underlying APIs as Needed

    In addition to being called automatically by the model during a conversation, the underlying capabilities described above can also be used separately as standalone APIs. The main categories are as follows:

    Capability Typical use
    Search Retrieve candidate web pages and summaries for use in a custom retrieval workflow
    Web page fetching Convert a specified URL into structured body text
    OCR Extract text from scanned documents, screenshots, and receipts
    Speech recognition Transcribe audio into text for meeting notes and voice input
    Speech synthesis Convert text into audio for announcements and voice assistants

    The value of standalone calls lies in controllability. For example, a knowledge base Q&A system can first use the search API to recall candidate materials, then use the web page fetching API to read the body text, and finally pass the result to the model to generate an answer. The output of each step can be cached, filtered, and logged, which makes troubleshooting easier.

    4. Architecture Design: Orchestrating Capabilities into an Application

    The following code is a flow illustration that shows the call order. The function names and parameter names are placeholders; refer to the service documentation for actual API definitions.

    1. # Pseudocode: illustrates the call flow only; function and parameter names are placeholders
    2. def answer_question(user_input, attachments):
    3. # 1. Parse files into plain text first
    4. context_parts = []
    5. for file in attachments:
    6. text = parse_document(file) # document parsing capability
    7. context_parts.append(text)
    8. # 2. Extract links from the user message and fetch page text
    9. for url in extract_urls(user_input):
    10. page = fetch_page(url) # web page fetching capability
    11. context_parts.append(page.text)
    12. # 3. Assemble the request and enable web search as needed
    13. response = call_model(
    14. messages=build_messages(user_input, context_parts),
    15. search_enabled=needs_fresh_info(user_input),
    16. safety_enabled=True, # must be enabled for public services
    17. )
    18. # 4. Handle the refusal flag and citations
    19. if response.refused:
    20. return "This request cannot be processed at the moment. Please adjust your question and try again."
    21. return format_answer(response.text, response.citations)

    This structure has three design points:

    • Clear order: Handle deterministic inputs such as files and links first, then hand the request to the model for open-ended reasoning. This makes it easier to locate which layer caused an error.
    • Controllable switches: Whether to enable search should be determined by business rules rather than enabled by default every time. Enable search for time-sensitive questions and disable it for purely conceptual explanations. This saves latency and reduces irrelevant citations.
    • Traceable results: Citations, refusal flags, and intermediate text should all be logged for later auditing and performance evaluation.

    5. Engineering Practices

    Timeouts and degradation. Web retrieval and web page fetching both depend on external networks, so latency can vary widely. Set an independent timeout for each step and define fallback behavior. For example, if search fails, the application can tell the user, “The latest information cannot be retrieved right now; the following answer is based on existing knowledge,” instead of silently returning a potentially outdated conclusion.

    Caching. Web page content for the same URL and parsing results for the same file are both suitable for caching. The cache key can use a content hash or a normalized URL string. Cache duration should be set according to how frequently the content changes; news pages have a much shorter lifetime than encyclopedia pages.

    Retries and idempotency. Network requests can be retried after failures, but the number of retries should be limited and exponential backoff should be used to avoid amplifying the failure. For calls that incur billing, ensure that retries do not cause duplicate charges. The application layer should record request identifiers for this logic.

    Context management. Putting multiple files and web pages entirely into the context increases cost and reduces the model’s ability to focus on key points. A better approach is to filter for relevance first, keep only paragraphs related to the question, and label the source of each paragraph.

    Security boundaries for input and output. Web page and file content is untrusted data and may contain text that attempts to change model behavior. The application should clearly mark such content as “reference material” and state in the system instructions that instructions inside the material must not be executed.

    6. Compliance and Responsibility

    When these capabilities are used in public-facing products, the application provider bears corresponding legal obligations. Specific requirements depend on applicable laws and regulations and the rules of regulatory authorities in the jurisdictions where the service operates. They commonly include:

    • Enabling and cooperating with safety checks, and establishing content review and manual review processes;
    • Completing required registration or filing procedures for LLM-related services as mandated by applicable regulations;
    • Clearly labeling AI-generated content so users do not mistake it for human-written content;
    • Retaining necessary logs for regulatory review and issue tracing.

    Technical teams should align these requirements with legal and compliance teams at the project planning stage rather than adding them shortly before launch. The earlier compliance design is incorporated into the architecture, the lower the cost of rework later.

    7. Conclusion

    Web search, file parsing, link reading, and safety checks form a complete capability chain from information acquisition to content review. Developers can use them together in conversational scenarios or split them into standalone APIs and embed them in their own workflows. When selecting capabilities, decide which ones to enable based on the timeliness, complexity, and cost sensitivity of the question. From an engineering perspective, focus on timeout fallback, caching, context management, and security boundaries. Before launch, complete compliance checks. Following this approach, teams can quickly build intelligent applications with a clear structure and traceable results.