A Guide to Integrating Web Search, File Parsing, and Web Page Reading APIs

    This guide walks developers through integrating three independent LLM capabilities—web search, file parsing, and web page reading. It covers capability boundaries, pre-integration preparation, request structure examples, rate limiting and retry strategies, cost control, troubleshooting, and go-live acceptance criteria.

    1. Define the Capability Boundaries First

    Web search, file parsing, and web page reading are three independent capabilities. Before integrating, confirm that each one is available on the model and version you plan to use, and only then decide whether to enable it.

    Capability Problem it solves Primary input Limits to confirm
    Web search Answers that depend on up-to-date information User question Whether citations are returned, search scope and freshness
    File parsing Answering based on user documents PDF, Word, Excel, PPT, images Format, size, page count limits; image OCR capability
    Web page reading Analyzing links provided by the user URLs in messages Fetch success rate, paywalls, dynamically rendered pages

    “Deep thinking mode” is typically supported only on certain models and versions. Before designing features around it, check the model list in the console.

    2. Pre-Integration Preparation

    Complete the following before integration:

    • Create an API key in the platform console. Store it only in server-side environment variables—never in source code or front-end pages.
    • Confirm the model name and version. Different versions may support different tool types.
    • Confirm billing items. Search calls, file parsing, and page fetching may each be billed separately, so estimate them independently.
    • Set timeouts. Web search and page fetching take noticeably longer than a normal chat request, so a read timeout of at least 60 seconds is recommended, adjusted based on load-testing results.
    • Log the request ID of every call. This makes it much easier to report issues to the platform and troubleshoot.

    Once the search tool is enabled, the model decides on its own whether a search is needed. Developers do not need to manually assemble search results, but they should check whether the response contains citation information and keep the source links visible in the UI.

    Below is a structural example. Placeholders must be replaced with real values from the official documentation, and the actual field names may differ:

    1. import os
    2. import requests
    3. API_URL = "<chat completion endpoint provided by the platform>"
    4. API_KEY = os.environ["LLM_API_KEY"]
    5. payload = {
    6. "model": "<model name, as shown in the console>",
    7. "messages": [
    8. {"role": "user", "content": "Summarize the major AI developments from the past week, with sources."}
    9. ],
    10. "tools": [
    11. {"type": "<web search tool type, per the official documentation>"}
    12. ],
    13. }
    14. resp = requests.post(
    15. API_URL,
    16. headers={"Authorization": f"Bearer {API_KEY}"},
    17. json=payload,
    18. timeout=60,
    19. )
    20. resp.raise_for_status()
    21. data = resp.json()

    When parsing the response, do not hard-code field paths. Print one complete response first, confirm where the citation fields are located, and only then write the parsing logic.

    4. Integrating File Parsing

    The recommended workflow for file parsing is:

    1. The server receives the uploaded file and validates its extension and size.
    2. Upload the file according to the platform documentation to obtain a file identifier, or submit it directly with the request if the documentation requires it.
    3. Reference the file in the message and describe the task you want the model to perform.
    4. Check the parsing status and result. If parsing fails, return a clear reason to the user.

    Before uploading, validate the type, size, and page count locally to reduce wasted requests. Scanned documents and images rely on OCR, and recognition accuracy depends on image clarity. Plain text extraction and structured parsing produce different results: for tables and mixed text-and-image content, prefer structured output and spot-check key numbers.

    Uploaded files may contain personal information. Encrypt stored content, set a retention period, and delete platform-side files when the corresponding business data is deleted—provided the platform offers a deletion API.

    5. Integrating Web Page Reading

    Key points for web page reading:

    • Keep the original URL from the user’s message. Do not modify or concatenate links on your own.
    • Enable reading only for links the user actively provides; do not crawl pages in bulk.
    • Fetching can fail due to timeouts, 404 errors, login requirements, paywalls, or anti-scraping measures. On failure, tell the user why rather than letting the model fabricate page content.
    • Keep summaries short and attribute the source. Do not republish full text, to reduce copyright risk.
    • Filter internal and loopback addresses on the server side to prevent users from making your server access internal network resources via crafted links (SSRF).

    6. Rate Limiting, Retries, and Cost

    Rate limiting: Set QPS limits per user and globally. Reject excess requests with a clear message instead of queuing them up.

    Retries: Retry only on 429, 5xx, and network timeouts. Use exponential backoff with random jitter, up to 3 attempts. Other 4xx errors usually indicate parameter or permission problems, where retrying is pointless.

    Cost: Track token usage and tool call counts per feature. Before enabling search or file parsing, estimate per-request cost with sample data, then decide whether to enable it by default.

    Context: Split long documents or generate summaries first to avoid exceeding the model’s context window.

    Log sanitization: Never log API keys, phone numbers, file contents, or other sensitive data. Log only the request ID, latency, status code, and error type.

    If the service runs in the cloud, you can use object storage for uploaded files, a message queue for long-running tasks, and logging/alerting services to monitor error rates and latency. Refer to your cloud provider’s documentation for specific products and configuration.

    7. Common Troubleshooting

    Symptom Possible cause Resolution
    401 returned Wrong key or permission not enabled Check environment variables and console permissions
    Search not triggered Tool not enabled, or model does not support it Check the tools parameter and the model list
    File parsing failed Format/size limit exceeded, or file is encrypted Check limits; ask the user to convert the format
    Empty page content Dynamic rendering or paywall Inform the user and ask them to paste the text
    Slow responses Search and fetch latency stacking up Increase the timeout; switch to async processing

    8. Go-Live Acceptance Criteria

    Before launch, check the following five items:

    • Functionality: Prepare at least 10 real test samples for each of the three capabilities and record the success rate for each.
    • Quality: Sample-check that answers are consistent with their sources and that citation links are accessible.
    • Stability: After load testing, define thresholds for error rate, P95 latency, and timeout rate; launch only when they are met.
    • Cost: Keep the average cost per session within budget.
    • Security: Logs contain no keys or sensitive data, and internal addresses are properly blocked.

    Once all criteria pass, roll out to a small percentage of traffic first, observe for a period, and then scale up gradually.