All-in-One LLM API Integration Guide: How Hybrid Billing Works

    This guide explains what all-in-one LLM APIs can do, including web search, web page fetching, file parsing with OCR, speech recognition, and speech synthesis. It covers how to connect to these APIs with a Chat Completions-compatible SDK, how to estimate costs under hybrid billing, and what to check before launch.

    As large language model (LLM) APIs expand from pure text generation to web search, file parsing, OCR, and speech, the way developers add AI features is changing. Developers used to integrate search engines, document parsing libraries, and speech services on their own. Some platforms now host these capabilities on the server side, so a single request can call them. This article explains what these APIs can do, how to integrate them, how to estimate bills, and which issues to check before launch.

    The code and prices in this article are for illustration only. Field names, billing units, and discount rules vary widely between platforms. Before production use, check the official documentation and price list of your platform.

    1. What an All-in-One API Includes

    An all-in-one API typically packages several tools as server-side capabilities. Developers declare the tools they need in a request. The platform then runs the search, fetch, or transcription, and passes the results to the model to generate the answer.

    The table below lists common capabilities and the points to watch when integrating them.

    Capability Typical Input Typical Output Common Billing Unit Scope Common Failure Modes
    Web search User question or keywords Summaries of candidate web pages Per 1,000 calls Depends on search source coverage. Timeliness depends on how often the index is updated. Empty results, unreliable sources, duplicate searches
    Web fetching URL Body text Per 1,000 calls Dynamically rendered pages, login pages, and paywalled content may not be readable. Timeouts, blocking by the site, incomplete text extraction
    File parsing and OCR PDF, images Text and layout information Per page or per file File size and page count are capped. Scan quality affects recognition accuracy. Files over the limit, misaligned tables, poor handwriting recognition
    Speech recognition (ASR) Audio files or audio streams Text Per minute or per hour of audio Accents, background noise, and sampling rate affect accuracy. Unsupported audio formats, incorrect splitting of long audio
    Speech synthesis (TTS) Text Audio Per 1,000 characters Text length per request is limited. Voice and language support varies by platform. Misread special symbols, output timeouts

    2. Integration: Using a Chat Completions-Compatible SDK as an Example

    Many platforms support the industry-standard Chat Completions interface. You can therefore reuse an OpenAI-format SDK and replace only the base_url and api_key. Compatibility does not mean every field is identical, though. The platform defines how built-in tools are declared. Some platforms use the standard tools field, while others use vendor-specific extension parameters.

    Complete the following steps before integrating:

    1. Install the SDK and pin its version, for example pip install openai==<your version>.
    2. Store the API key and base_url in environment variables. Do not write them into code or logs.
    3. Confirm that base_url points to a platform endpoint that supports built-in tools, and that your account has permission to use those tools.
    4. Set usage limits or alert thresholds in the console to prevent unexpected charges from abnormal call volumes.
    5. Set timeouts and retry counts for requests, and record request IDs to make troubleshooting easier.

    The example below uses the standard function tool format. If the platform requires built-in tools to be hosted on the server, use the fields in that platform’s documentation instead, such as passing vendor extension parameters through extra_body.

    1. import os
    2. from openai import OpenAI
    3. client = OpenAI(
    4. api_key=os.environ["LLM_API_KEY"],
    5. base_url=os.environ["LLM_BASE_URL"], # Must point to a platform endpoint that supports built-in tools
    6. timeout=60,
    7. max_retries=2,
    8. )
    9. tools = [
    10. {
    11. "type": "function",
    12. "function": {
    13. "name": "web_search",
    14. "description": "Search the internet for the latest information",
    15. "parameters": {
    16. "type": "object",
    17. "properties": {
    18. "query": {"type": "string", "description": "Search keywords"}
    19. },
    20. "required": ["query"],
    21. },
    22. },
    23. }
    24. ]
    25. response = client.chat.completions.create(
    26. model=os.environ["LLM_MODEL"],
    27. messages=[
    28. {"role": "system", "content": "You are a professional assistant. Use the latest information to answer questions."},
    29. {"role": "user", "content": "What are the major technology news stories today? Please give a brief summary."},
    30. ],
    31. tools=tools,
    32. )
    33. message = response.choices[0].message
    34. if message.tool_calls:
    35. # If the platform does not run the tool on the server, it returns tool_calls. The client must run the tool and send another request.
    36. print("Model requested tool calls:", [c.function.name for c in message.tool_calls])
    37. else:
    38. print(message.content)

    After running the code, first check which field contains the result. If the platform completes tool calls on the server, the result appears directly in message.content. If the platform returns tool_calls, the client must run the tools, append the results to messages as tool-role messages, and send another request. The code size and latency of the two modes differ noticeably, depending on whether the platform hosts tool calls. Verify this in a test environment before launch.

    3. How to Estimate Hybrid Billing

    Most all-in-one APIs use a hybrid model. The base model is billed by tokens, and tools are billed per call or per unit of usage. The base model cost equals the input token count multiplied by the input price, plus the output token count multiplied by the output price. Tool costs are added up using each tool’s own billing unit.

    The estimation template is as follows:

    Cost per request = input tokens / 1,000 × input price + output tokens / 1,000 × output price + number of searches / 1,000 × search price + number of fetches / 1,000 × fetch price + OCR pages × OCR price + audio duration × ASR price + characters / 1,000 × TTS price

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

    Calculate the average cost per request from sample data. Include the average number of tool triggers in the calculation. Do not assume every request triggers every tool.

    The following example uses hypothetical numbers. Assume the input price is 0.002 yuan per 1,000 tokens, the output price is 0.008 yuan per 1,000 tokens, and the search price is 10 yuan per 1,000 searches. These figures are illustrative only and do not reflect any platform’s actual prices. Assume each request averages 1,500 input tokens and 500 output tokens, and triggers search 0.6 times on average:

    • Input cost: 1,500 / 1,000 × 0.002 = 0.003 yuan
    • Output cost: 500 / 1,000 × 0.008 = 0.004 yuan
    • Search cost: 0.6 / 1,000 × 10 = 0.006 yuan
    • Average cost per request: 0.013 yuan

    At 10,000 requests per day, the daily cost is 130 yuan, and the monthly cost is about 3,900 yuan.

    Your estimate should state its assumptions. These include average token counts, tool trigger rates, cache hit rates, and retry rates. Confirm the billing terms with the platform, including whether search is charged by request count or by other units.