How to Build a Full-Featured AI Chat Product with Open LLM APIs at Low Cost

    This article explains how opening up the capabilities behind an official AI chat product through APIs changes the way developers build conversational applications. It breaks a production-ready chat product into four layers—model inference, tool extensions, orchestration and state, and delivery and operations—and shows why each capability must be cost-modeled separately, since per-call and volume-based pricing use completely different units. You will find a sample cost-estimation function, engineering practices for reliable tool calls, guidance on letting the model decide when to use tools, and a pre-launch checklist covering timeouts, budget gates, streaming, degradation, and cost monitoring.

    1. From a Single Chat Box to a Full Capability Stack

    Over the past year, many teams building AI chat products have hit the same bottleneck: the model itself is already strong enough, but what really shapes the product experience is the layer of “hands and feet” around the model—web search, web page content extraction, image and text understanding, and speech input and output. These capabilities used to be scattered across different vendors and different API systems, forcing developers to handle authentication adaptation, protocol conversion, error-code normalization, and billing reconciliation themselves. The amount of repetitive work was enormous.

    When a cloud provider opens up every capability behind its official chat product as an API, the engineering implication goes far beyond “one more service to call.” It means the official product and third-party applications now start from the same capability baseline. Developers can use the same building blocks to recreate a fully functional chat application 1:1, shifting their energy from “assembling infrastructure” to “designing interaction patterns and business logic.”

    The technical essence of this shift is taking a tightly coupled product and splitting it into a freely composable set of capability layers. Understanding this layering is the prerequisite for every architecture decision that follows.

    2. Capability Layers: The Four-Layer Structure of a Replicable Chat Product

    A production-ready chat product can usually be abstracted into four layers:

    1. Model inference layer: Handles semantic understanding, reasoning, and generation. It is the core engine of the application, typically billed separately for input and output tokens.
    2. Tool extension layer: Includes text search, image search, web page fetching, optical character recognition (OCR), automatic speech recognition (ASR), and text-to-speech (TTS). This layer determines whether the product can “know what happened today,” “understand an image,” or “make sense of a spoken sentence.”
    3. Orchestration and state layer: Manages multi-turn conversation state, tool-call decisions, result backfilling, context trimming, and caching. This is the most underestimated layer, yet it has the biggest impact on experience.
    4. Delivery and operations layer: Includes streaming output, concurrency control, rate limiting and degradation, log tracing, monitoring and alerting, and cost dashboards.

    The billing structure mentioned in the original text confirms this layering: on top of token fees, tool calls are billed separately. Text and image search cost about RMB 5 per 1,000 calls, web page fetching about RMB 5 per 1,000 calls, OCR about RMB 1.5 per 1,000 pages, ASR about RMB 0.39 per hour, and TTS about RMB 1.5 per 10,000 characters. These prices send a clear engineering signal: different capabilities have completely different cost dimensions and must be modeled separately. You cannot estimate a bill with a single, unified “number of calls” metric.

    3. Cost Modeling: Putting Per-Call and Volume-Based Pricing in the Same Table

    Many teams only discover their bills are out of control after launch, and the root cause is a cost model that is too coarse. It is better to split cost into two dimensions:

    • Call-based: Search and web page fetching, priced per 1,000 calls, with cost scaling linearly with usage frequency.
    • Volume-based: OCR priced per page, ASR per hour, and TTS per character, with cost tied to the scale of the content.

    A sample cost-estimation logic can be written as:

    1. def estimate_cost(token_in, token_out, search_calls,
    2. fetch_calls, ocr_pages, asr_hours, tts_chars):
    3. # Illustrative structure; unit prices are subject to the official billing documentation
    4. cost = token_cost(token_in, token_out)
    5. cost += search_calls / 1000 * 5.0 # call-based
    6. cost += fetch_calls / 1000 * 5.0 # call-based
    7. cost += ocr_pages / 1000 * 1.5 # volume-based
    8. cost += asr_hours * 0.39 # volume-based
    9. cost += tts_chars / 10000 * 1.5 # volume-based
    10. return cost

    What really drives the bill is not the unit price but the call amplification factor. If a single user question triggers 3 searches plus 5 web page fetches, the tool cost of that one interaction can be several times the model cost. So the first principle of cost control is to set budget caps and deduplication caches for tool calls at the orchestration layer.

    4. Engineering Tool Calls: Reliability Over Coverage

    The tool layer is where external dependencies are most concentrated, and it must be designed as a set of “untrusted dependencies”:

    • Separate timeouts from retries: Search and fetching APIs have high tail latency, so they need independent timeouts, and retries should use exponential backoff to avoid cascading failures.
    • Trim results before adding them to context: Web page content can easily run to thousands of words. Stuffing it directly into the context pushes up both token cost and latency. Summarize or extract key passages first.
    • Idempotence and caching: Cache results keyed by “query plus time window” to significantly reduce the call-based fees caused by repeated calls.
    • Degradation path: When a tool is unavailable, the product should fall back to a pure model answer and clearly tell the user the information may not be up to date, rather than throwing an error.
    • Multimodal preprocessing: For images and audio, store them in object storage first and pass only a reference identifier into the orchestration flow, avoiding repeated transfer of large objects across the pipeline.

    5. Orchestration Design: Let the Model Decide Whether to Use a Tool

    Recreating a complete chat product is less about how many APIs you have and more about the quality of decisions. A recommended approach is to describe tools as a structured capability list and let the model choose on its own based on user intent:

    1. {
    2. "tools": [
    3. {"name": "web_search", "when": "real-time or factual information is needed"},
    4. {"name": "page_fetch", "when": "the content of a specific page must be read"},
    5. {"name": "ocr", "when": "the input is an image or a scan"},
    6. {"name": "asr", "when": "the input is audio"},
    7. {"name": "tts", "when": "voice playback is needed"}
    8. ]
    9. }

    Three things are needed alongside this: first, a context budget that reserves a fixed share of the window for tool results and summarizes or compresses anything beyond it; second, externalized session state, keeping multi-turn history in a cache or database and dynamically trimming it against a token budget; third, full-pipeline tracing that records which tools each interaction called, along with latency and cost, so you can pinpoint both experience problems and cost anomalies.

    6. Pre-Launch Checklist

    • Does each type of tool have its own timeout, retry, and circuit-breaker policy?
    • Is there a path where “one question triggers multiple fetches,” and is there a budget gate to control it?
    • Does streaming output optimize time-to-first-token, and can long answers be interrupted?
    • Do the voice and image pipelines enforce size limits and format validation?
    • Is there a daily cost dashboard with alert thresholds?
    • Are degradation messages and user prompts ready for when tools are unavailable?

    7. Conclusion

    Once capabilities are exposed as APIs, the focus of product differentiation shifts from “what you connected” to “how you orchestrate.” The official product is just a relatively basic form, and there is still plenty of unexplored space in how humans interact with models. For developers, the real opportunity lies in using the same freely composable set of capabilities to redesign interaction rhythm and tool strategies for different scenarios—leaving the repetitive foundational work to the platform and the imagination to yourself.