Building with Full-Featured LLM APIs: Web Search, File Handling, and Voice

    This guide explains how to use built-in LLM API tools for web search, web page reading, file upload, OCR, speech-to-text, and speech synthesis. It covers how to confirm platform capabilities, estimate and control costs, run a minimal Python example, troubleshoot common errors, deploy on the cloud with attention to data security, and complete a pre-launch checklist.

    1. Understanding Capability Boundaries

    A mainstream large language model platform offers web search, web page reading, file upload, OCR, and speech-to-text and speech synthesis. The platform runs these capabilities on its servers. Developers only need to declare the tools in their request to use them. However, “built-in” does not mean every platform offers the same tools. Supported tool types, parameter formats, and response structures vary by platform, and some platforms provide only a subset. Before integrating, check the official documentation to confirm three things: which built-in tools are supported, how to enable each tool, and whether the response includes a record of tool calls.

    If a platform does not provide a built-in capability, developers must implement it themselves. A common approach is function calling. The model requests an external search service, and the application passes the results back to the model. This approach requires maintaining a separate search interface, web content cleaning, and context assembly logic, which takes considerably more work.

    An LLM’s training data has a cutoff date, so its answers to time-sensitive questions may be outdated. Search tools can supply recent information, but the search results themselves may be inaccurate or incomplete. Applications should therefore require the model to cite its sources, and key scenarios should involve manual review.

    2. Pricing Models and Cost Estimation

    Costs for full-featured APIs usually have two parts: token fees for the base model, and separate fees for each tool. Tools use different billing methods. Common methods include per-call billing (for example, search and web page reading), duration-based billing (for example, speech-to-text), and character-based billing (for example, speech synthesis). Unit prices, free quotas, promotional periods, and regional differences are all defined on the platform’s current pricing page. This article does not list specific prices, so readers do not rely on outdated or inapplicable figures.

    To estimate the cost of a single conversation, use this formula:

    Cost per request = input tokens × input price + output tokens × output price + number of searches × price per search + number of page reads × price per read + speech duration × price per unit of duration

    Monthly cost = cost per request × average daily requests × 30

    Before launch, run a test with a sample of real business questions. Record the average token count and tool call count for each request type, then substitute those values into the formula. The sample should cover different request types, such as simple Q&A, questions that require search, and long document parsing. Otherwise, the estimate may differ significantly from actual costs.

    There are four common ways to control costs. First, limit search conditions in the prompt so the model calls search only when a request needs real-time information. This avoids triggering a full web search on every request. Second, split long documents programmatically and send only the relevant sections to OCR or the model. This reduces repeated processing. Third, cache frequent queries with stable answers. On a cache hit, return the stored result directly without calling the model or any tools. Fourth, if the platform offers off-peak pricing for non-real-time tasks, schedule batch jobs during those hours. Whether off-peak pricing exists depends on the platform’s pricing documentation.

    3. Minimal Working Example

    The example uses the Chat Completions interface from the official OpenAI Python SDK (the openai package). The SDK works with platforms that support the same protocol. However, you must replace the built-in tool names and parameter formats with those in the platform’s official documentation. The tool configuration in the example is only a placeholder and must be replaced before you run the code.

    Setup steps:

    1. Check the official requirements of the openai package for the supported Python version.
    2. Install the package with pip install "openai>=1.0,<2". Before production use, pin a specific version and record it in your dependency file.
    3. Create an API key in the platform console, and confirm that the key has access to the required models and tool services.
    4. Inject the key through an environment variable, for example export LLM_API_KEY="your-api-key". Never write keys into code, configuration files, or logs.
    5. Confirm the base_url from the platform. It usually includes a version path such as /v1. Follow the documentation for the exact value.

    Example code:

    1. import os
    2. from openai import OpenAI, APIError, AuthenticationError
    3. API_KEY = os.environ["LLM_API_KEY"] # Raise an error if the key is missing, so requests are never sent with an empty key
    4. BASE_URL = os.environ.get("LLM_BASE_URL", "https://your-platform.example.com/v1") # Replace with the base URL from the platform documentation
    5. MODEL = os.environ.get("LLM_MODEL", "your-model-name") # Replace with a model the platform supports
    6. client = OpenAI(api_key=API_KEY, base_url=BASE_URL, timeout=30.0)
    7. # The platform defines the built-in tool type names and parameter structures.
    8. # The entry below is a placeholder and must be replaced according to the official documentation.
    9. TOOLS = [
    10. {"type": "web_search"},
    11. ]
    12. def ask(question: str) -> str:
    13. try:
    14. resp = client.chat.completions.create(
    15. model=MODEL,
    16. messages=[
    17. {"role": "system", "content": "You are a concise assistant. When a question involves real-time information, use the search tool and cite your sources."},
    18. {"role": "user", "content": question},
    19. ],
    20. tools=TOOLS,
    21. extra_body={"thinking": {"type": "disabled"}}, # Check the platform documentation to confirm this parameter is supported
    22. )
    23. except AuthenticationError as e:
    24. raise RuntimeError("Authentication failed: check that the API key is correct and that the service is enabled.") from e
    25. except APIError as e:
    26. raise RuntimeError(f"Request failed: {e}") from e
    27. msg = resp.choices[0].message
    28. return msg.content or ""
    29. if __name__ == "__main__":
    30. print(ask("What is the weather in Shanghai today? Is it good for going out? Please answer briefly."))

    If the answer includes specific dates and sources, the search tool is working. If the answer contains only general descriptions, first check that the tool is declared correctly, then check that the model supports it. The example does not rely on tool call record fields in the response, because platforms name these fields differently and do not all return them. To audit tool calls, use the fields described in the platform’s documentation.

    4. Parameter Reference

    Parameter Purpose Notes
    api_key Authentication credential Read it from an environment variable or secrets manager, and rotate it regularly
    base_url Platform API endpoint An incorrect path causes 404 errors, so include the version path
    model Model name Model names are case-sensitive. Use the platform’s model list.
    messages Conversation context Limit the length of long conversations to avoid high token costs
    tools Tool declarations Tool type names and parameter structures follow the platform documentation
    extra_body Platform-specific extension parame