Integrating LLM APIs: Web Search, File Parsing, and a Launch Checklist
A practical guide to integrating LLM APIs with web search, file parsing, and content moderation. Learn how to verify provider capabilities, validate citations, handle refusals, design timeouts and retries, protect sensitive data, and run a pre-launch checklist before going live.
Integrating LLM APIs: Web Search, File Parsing, and a Launch Checklist
1. Start with a Capability Matrix
Even within the same provider, different API endpoints often support different tools and model versions. Before integrating anything, build a capability matrix and verify each item against it.
| Capability | Typical Use Case | Confirm Before Integrating | Billing and Latency |
|---|---|---|---|
| Web search | Time-sensitive info such as news, prices, and policies | Whether the endpoint and model support it, and whether it must be enabled separately | Per the pricing sheet; usually fast |
| Deep-reasoning search | Multi-step reasoning and long-chain research | Whether it’s restricted to specific models | Slow; cost grows with the number of search rounds |
| File parsing | Q&A over contracts, papers, and reports | Limits on format, file size, and page count | Billed by page count or tokens; large files take noticeably longer |
| URL reading | Articles or pages shared in a conversation | Whether the fetching service is available, and which domains and dynamic pages are supported | Per the pricing sheet |
| Content moderation | Reviewing content for public-facing applications | Whether the parameters are available and how refusal results are returned | Per the pricing sheet |
Once the matrix is complete, verify the following in order:
- Confirm endpoint types. Messages, Responses, and Chat Completions endpoints don’t fully match in capability, and the same tool may use different parameter formats across them. Record the available tools for each endpoint type.
- Confirm streaming support. Streaming lets the frontend render content earlier and significantly affects user experience. Record whether each endpoint supports it, and the format of streaming events during tool calls.
- Confirm entitlements. Some capabilities must be enabled separately in the console, or may require business credentials. Verify each entitlement with a real API call in the test environment.
- Look up quota fields. Record the concurrency limits, requests-per-minute, and daily quotas for each capability, and find the field names for querying remaining quota. Field names must follow the provider’s documentation.
This article covers the integration points, risks, and verification methods for these capabilities. It does not include specific prices, complete field definitions for each provider, or model quality benchmarks.
2. Choosing Between Two Web Search Modes
In non-reasoning mode, the model decides on its own whether to search. After searching, it summarizes the results and attaches citation sources. This mode suits Q&A and real-time data lookups — fast responses at low cost.
Deep-reasoning search performs multiple retrieval rounds and step-by-step reasoning, making it suitable for tasks that synthesize multiple sources. It takes longer, and cost grows with each search round. If you’re just looking up a price or a policy, non-reasoning mode is enough.
Before launch, verify citation sources with these steps:
- Check link status. Send a request to each citation URL and record the HTTP status code. Mark any non-2xx response as invalid.
- Check the domain allowlist. If your business only allows citations from specific sites, drop any source whose domain isn’t on the allowlist.
- Compare against the original text. Fetch the page content and confirm that the quoted sentences actually appear on the page. Don’t display citations whose source text can’t be found.
- Handle failures. Retry an invalid link once. If it still fails, remove the source and note in the answer that the information could not be verified.
If no sources survive verification, the system should degrade to answering without citations, or explicitly tell the user that the information is unverified. Never present unverified citations as evidence.
3. File Parsing, URL Reading, and Content Moderation
For file parsing, confirm three limits before integration: format, file size, and page count. Files exceeding these limits should be rejected at upload, with a prompt asking the user to split the file. Since large files take noticeably longer to process, use asynchronous handling with the frontend polling task status.
URL reading has its own boundaries. Some sites require login, and some pages load content dynamically via scripts. When fetching fails, the system should tell the user why — not let the model fabricate the content.
For content moderation in public-facing scenarios, you must handle refusal results. When the API returns a refusal, distinguish three cases: policy violation, parameter error, and service failure. For violation-based refusals, tell the user to rephrase their question; for parameter errors, fix the request and retry; for service failures, apply the retry policy. In high-risk scenarios, route refusal records to human review, and feed the review results back into the rule configuration.
Timeout and retry policies need unified design. Set timeouts based on your business’s P95 latency, and configure longer, separate timeouts for file parsing and deep-reasoning search. Only retry on timeouts, rate limiting, and server-side errors, using exponential backoff with random jitter. Cap the number of retries to avoid amplifying outages.
4. Data Retention and Redaction
Before integrating, confirm the provider’s data retention policy: how long request content is stored, whether it’s used for model training, and whether this can be turned off. These terms are governed by the provider’s formal agreement.
Before launch, do three things:
- Redact before upload. Replace or mask sensitive fields — phone numbers, ID numbers, bank card numbers, email addresses — before sending them to the model.
- Redact logs. Log only request IDs, latency, status codes, and error types. Never log full user inputs or model outputs.
- Manage keys. Read API keys only from environment variables or a secret manager. Never hardcode them in source code, config files, or logs.
5. A Reusable Code Skeleton
The following pseudocode illustrates the structure for API calls, retries, source verification, and redaction. Actual field names, endpoint paths, and response formats depend on the provider’s documentation.
import loggingimport osimport randomimport reimport timeAPI_KEY = os.environ["LLM_API_KEY"] # Read only from environment variablesTIMEOUT_S = 30 # Adjust to your P95 latency; configure separately for file parsingMAX_RETRIES = 3RETRYABLE_STATUS = {429, 500, 502, 503, 504}PHONE_RE = re.compile(r"1[3-9]\d{9}")def redact(text: str) -> str:"""Redact before logging/uploading; this example handles phone numbers only."""return PHONE_RE.sub("[phone number]", text)def call_with_retry(send, payload):"""Retry only on timeouts, rate limits, and server errors, with exponential backoff and jitter."""for attempt in range(MAX_RETRIES + 1):try:resp = send(payload, timeout=TIMEOUT_S)except TimeoutError:logging.warning("Request timed out, attempt %d", attempt)else:if resp.status_code not in RETRYABLE_STATUS:return resplogging.warning("Status %s, retrying", resp.status_code)if attempt < MAX_RETRIES:time.sleep(2 ** attempt + random.random())raise RuntimeError("Retries exhausted")def verify_source(src: dict, allowlist: set) -> bool:"""Source verification: domain allowlist, link accessibility, and quoted text exists."""if src["domain"] not in allowlist:return Falsepage = fetch(src["url"]) # Returns status code and body textif page.status != 200:return Falsereturn src["quote"] in page.textdef handle_result(data: dict, allowlist: set) -> dict:"""Handle refusals, source verification, and degradation. Refusal field names follow the docs."""if data.get("refused"):return {"status": "refused", "message": "Content could not be generated. Please rephrase your question."}verified = [s for s in data.get("sources", []) if verify_source(s, allowlist)]if not verified:return {"status": "degraded", "message": "Information not yet verified. For reference only."}return {"status": "ok", "answer": data["answer"], "sources": verified}def log_request(request_id, latency_ms, status):"""Log metadata only — never user inputs or model outputs."""logging.info("req=%s latency=%dms status=%s", request_id, latency_ms, status)
Quota fields can be read and recorded after each response. When usage approaches the limit, slow down or queue requests in advance. When quota is exhausted, return a clear error message rather than letting requests fail silently.
6. Pre-Launch Checklist
Confirm each item below before going live:
- The capability matrix is complete, and tool support for each endpoint type has been verified in the test environment.
- Entitlements for all capabilities are confirmed, with enablement records archived.
- Concurrency limits, requests-per-minute, and daily quotas are recorded, and remaining-quota queries are wired into monitoring.
- Timeouts are configured separately for each capability, with longer timeouts for file parsing and deep-reasoning search.
- Retries apply only to retryable errors, with a capped retry count.
- Citation sources pass status checks, domain allowlist checks, and original-text comparison, with fallback copy ready when verification fails.
- Refusal results distinguish violations, parameter errors, and service failures, with user-facing prompts for violation-based refusals.
- File format, size, and page count are enforced at upload, and large files go through the asynchronous flow.
- Inputs are redacted before upload, and logs contain no raw user text or model output.
- The provider’s data retention and training terms are confirmed and consistent with your privacy policy.
- API keys are read only from environment variables or a secret manager, with no plaintext keys in the codebase or logs.
- Regression tests cover failure paths such as timeouts, rate limiting, refusals, and invalid citations.
Run through this checklist before launch, and you’ll catch most rework issues in advance.
