How to Use Built-in Tools in LLM APIs: Integration, Billing, and Risks

    This article explains the built-in tool APIs recently opened by a large language model platform, including web search, web page reading, file parsing and OCR, speech recognition and synthesis, and content moderation. It covers the limits of each tool, how costs are calculated, how to integrate the API with a sample Python client, a pre-launch checklist, and the risks and compliance issues to consider.

    Introduction

    A large language model platform recently opened a set of built-in tool APIs. Previously, developers had to build search, web scraping, and file parsing pipelines on the client side. Now the server can handle these steps. This article outlines the capabilities and limits of these tools, how they are billed, and the key points for integration, for developers planning to adopt them.

    1. Core Capabilities and Limits

    1. Web search: The model decides whether a question needs real-time information. The server runs the search, organizes the web content, and adds the results to the context. Coverage depends on the platform’s index. Niche topics or fast-moving news may return incomplete results. Answers should cite their sources and state when the information was retrieved.
    2. Web page reading: Reads links that users provide. Pages that render dynamically, require login, or have access restrictions usually cannot be read reliably. Businesses should prepare alternative data sources for these cases.
    3. File parsing and OCR: Supports multiple file formats. Text recognition works well on clear, well-structured documents. Handwriting, dense tables, and poor-quality scans have noticeably higher error rates. Key data such as amounts and ID numbers should go through manual review.
    4. Speech recognition and synthesis: Provides speech-to-text and text-to-speech interfaces for voice assistants. Split long audio into segments first, and confirm the platform’s limits on duration and file size.
    5. Content safety moderation: Moderation is built into the pipeline, but the platform defines the rules. If your business has its own compliance standards, add filtering on the output side.

    2. Billing: How to Calculate Costs

    The platform uses two billing components. Base model usage is billed per token. Added tools are billed per call or per unit of time. The two are calculated separately, which makes it easier to identify where costs come from. The estimated cost of a single request is:

    Single request cost = input tokens × input price + output tokens × output price + number of tool calls × price per tool call

    Input tokens include the web content returned by tools. Long search results can increase token usage sharply, which is a common reason projects exceed their budgets. Log model token usage and tool call counts separately, and track them by feature module.

    The platform may set different model prices for different time periods. Currency, prices, and time-period rules follow the platform’s live pricing page. Before launch, run a batch of real samples, estimate the average daily cost, and then set budget alerts.

    3. Integration

    The API is compatible with common chat interfaces, so developers can call it with standard SDKs. Compared with a traditional agent architecture, the tool call loop runs on the server. The client only declares the tools it needs, sends one request, and waits for the final result.

    This reduces client-side code and lowers the chance that a network interruption loses intermediate state. However, failures happen on the server side, so the client must handle timeouts, retries, and fallbacks.

    The example below shows the basic call flow. The tools field is a platform extension. Field names, model names, and endpoints should be taken from the official documentation.

    1. import os
    2. import sys
    3. from openai import OpenAI, APIError, APITimeoutError, RateLimitError
    4. client = OpenAI(
    5. api_key=os.environ["LLM_API_KEY"], # Read from an environment variable. Do not hard-code it or log it.
    6. base_url=os.environ.get("LLM_BASE_URL", "https://api.example-llm.com/v1"), # Placeholder URL. Replace it with the address in the platform documentation.
    7. timeout=60.0,
    8. max_retries=2,
    9. )
    10. def ask_with_tools(question: str) -> str:
    11. try:
    12. response = client.chat.completions.create(
    13. model="your-model-name", # Placeholder. Replace it with the model name in the platform documentation.
    14. messages=[
    15. {"role": "system", "content": "You are a smart assistant. Use tools for real-time information and cite your sources."},
    16. {"role": "user", "content": question},
    17. ],
    18. tools=[
    19. {"type": "web_search"}, # Platform extension tool. Field names follow the official documentation.
    20. {"type": "read_url"},
    21. ],
    22. )
    23. except APITimeoutError:
    24. return "The request timed out. Please try again later or shorten your question."
    25. except RateLimitError:
    26. return "Too many requests. Please try again later."
    27. except APIError as e:
    28. print(f"API error: {e}", file=sys.stderr)
    29. return "The service is temporarily unavailable. Please try again later."
    30. message = response.choices[0].message
    31. if not message.content:
    32. return "The model returned no valid content. Check the logs and try again."
    33. return message.content
    34. if __name__ == "__main__":
    35. print(ask_with_tools("What is the air quality in Beijing today? Is it suitable for outdoor exercise?"))

    The code has three points to note. The API key is read from an environment variable and is never written into code or logs. The request sets a timeout and a limited number of retries to avoid long blocking. On timeouts, rate limits, and service errors, the function returns a readable fallback message instead of raising an exception.

    4. Pre-Launch Checklist

    1. Confirm the permission scope of the API key. Enable only the tools you need.
    2. Log the trace ID, latency, token usage, and tool call count for each request. If the platform returns tool execution records, save them as well for later troubleshooting.
    3. Show information sources in answers so users can verify real-time data.
    4. Anonymize personal information in file and voice data, and define a clear data retention period. For cross-border data transfers, first confirm where the platform is located and which local compliance rules apply.
    5. Set a monthly budget and per-user call limits to prevent unusual traffic from causing runaway costs.
    6. Prepare a fallback. When tools are unavailable, the system can still answer from the model’s own knowledge and state that the information may be outdated.

    5. Risks and Compliance

    Tool use gives the model access to more information, and it introduces new risks. Search results may contain incorrect or malicious content. Text on a web page may embed instructions. The model should treat such text as data and should not follow it. The business layer should limit which actions the model can take, especially in scenarios involving payments, sending messages, or modifying data.

    File and voice data usually contain personal information. Developers should tell users how their data will be used and explain the retention and deletion rules in the privacy policy.

    Summary

    Built-in tool APIs lower the barrier to integration, letting developers hand off retrieval, parsing, and speech processing to the server. Cost, accuracy, and compliance risks still need to be assessed separately at the business level. Start by validating tool performance on a small sample, expand usage gradually, and focus effort on business logic and user experience.