Composable LLM Capabilities in Practice: From a Single API to Orchestrated Services

    A practical guide to breaking AI applications into reusable capabilities such as web search, webpage extraction, file parsing, speech recognition, and speech synthesis. It covers orchestration patterns, cost estimation, resilience, caching, prompt injection protection, privacy, latency, compliance, and a practical rollout strategy.

    1. Background: The Engineering Gap Beyond Model Calls

    Early large language model APIs focused primarily on text generation and understanding. To build a product that behaves like a mature AI assistant, developers also need capabilities such as search, webpage extraction, file parsing, speech input, and speech output. These capabilities are often provided by different vendors, each with its own authentication methods, pricing models, and error codes. Integrating them into a single workflow can create significant engineering overhead.

    An emerging industry trend is for model providers to break application-layer capabilities into independently callable components. This component-based approach creates two immediate changes. First, developers can select only the capabilities they need instead of paying for unused functionality. Second, developers must design the execution order and coordination between components themselves. The quality of this orchestration directly affects the final user experience.

    2. Breaking Down Common Capability Components

    A complete conversational application commonly includes the following capabilities:

    • Web search: Generate search queries based on the user’s question and return candidate webpage titles, summaries, and links.
    • Webpage extraction: Retrieve the main content from a specified URL, remove navigation elements, advertisements, and other noise, and return structured text.
    • File parsing: Process documents uploaded by users, including text extraction and optical character recognition (OCR) for text contained in images.
    • Automatic speech recognition (ASR): Convert audio into text. Key concerns include end-to-end latency and accuracy in dialect-heavy or noisy environments.
    • Text-to-speech (TTS): Convert text into audio. Important factors include voice naturalness, speech-rate control, and costs charged by character count or audio duration.

    These components can have very different pricing models. Search and webpage extraction are often billed per request, while speech capabilities are commonly billed by duration or character count. File parsing may be priced by page or image. Cost models should therefore be established for each component separately rather than estimating the entire system using a single unified rate.

    3. A Typical Orchestration Workflow

    A question-answering workflow with web retrieval can be divided into five steps:

    1. Determine whether external information is needed.
    2. Generate a search query.
    3. Read the candidate webpages.
    4. Organize the retrieved content into context.
    5. Generate an answer with source citations.

    The following example illustrates this workflow. The tool function names are placeholders; actual interfaces depend on the service being used.

    1. def answer_with_tools(question: str) -> dict:
    2. # Example code: tool function names are placeholders and do not map to a specific API
    3. if not needs_external_info(question):
    4. return {"answer": generate(question), "sources": []}
    5. query = make_search_query(question)
    6. hits = search_tool(query, top_k=5)
    7. pages = []
    8. for hit in hits:
    9. try:
    10. pages.append(read_tool(hit["url"], timeout=8))
    11. except TimeoutError:
    12. continue # Skip an individual page failure without interrupting the workflow
    13. context = build_context(pages, max_tokens=4000)
    14. answer = generate(question, context=context)
    15. return {"answer": answer, "sources": [h["url"] for h in hits]}

    This code demonstrates three important engineering principles:

    1. Timeouts and graceful degradation: Set a timeout for every external call so that a single failure does not prevent the workflow from producing a result.
    2. Context truncation: Webpage content can be very long. It must be trimmed according to a token budget, with relevant passages given priority.
    3. Source attribution: Answers should include citation links so users can verify the information and developers can investigate incorrect content.

    4. Cost Estimation

    The cost of a single question-answering request can be estimated using the following structure:

    1. Cost per request = Number of search calls × Price per search call
    2. + Number of webpage reads × Price per webpage read
    3. + ASR duration × Price per unit of duration
    4. + TTS character count × Price per character
    5. + Model input and output token costs

    Suppose a typical question-answering scenario performs two searches and reads four webpages per request, while speech capabilities are enabled only for some sessions. In this case, webpage extraction may become the largest cost contributor and should be optimized first.

    Common approaches include reducing the number of candidate webpages, caching frequently accessed URLs, and triggering retrieval only when external information is genuinely required. After launch, continue tracking usage for each component and reconcile the measurements with billing data. Any discrepancy should be used to update the cost model.

    5. Engineering Practices

    1. Retries and idempotency

    Search and webpage extraction are read-only operations and can generally be retried safely. Text-to-speech requests may incur a charge, so before retrying, confirm whether the previous request was completed and billed to avoid duplicate charges.

    2. Caching

    When the same URL is read repeatedly within a short period, the extracted content can be cached. Caches need an expiration policy. Content with a short validity period, such as news, prices, and inventory information, should use shorter expiration times.

    3. Prompt injection protection

    Web content and uploaded files are untrusted data. They should be placed in the context as reference material, with explicit instructions that any directives contained in the material must not change the system’s behavior. High-risk actions, such as sending messages or modifying data, should require additional human confirmation.

    4. Privacy protection

    Audio and files often contain personal information. Define data retention periods, redact sensitive fields such as government ID numbers and phone numbers, and obtain user consent before collection. Logs should not contain raw audio or the complete contents of uploaded files.

    5. Latency budgets

    Voice conversations are sensitive to latency. Streaming recognition and streaming synthesis can allow users to hear a response sooner. During orchestration, search and speech recognition can also run in parallel to reduce the waiting time caused by sequential execution.

    6. Compliance and Content Safety

    Generated content should go through appropriate review, especially when it incorporates material from webpages. Verify whether the source permits quotation or reuse, and retain attribution.

    For answers related to medicine, law, finance, or other specialized fields, users should be directed to authoritative sources. Logs should preserve enough information about the execution chain for post-incident audits while following the principle of data minimization.

    7. Selection and Implementation Roadmap

    A practical rollout can follow these steps:

    1. Map business scenarios: Identify which capabilities are essential to the product and which are optional enhancements.
    2. Validate with limited traffic: Run the complete workflow with a small user group and record success rate, latency, and cost per request.
    3. Establish monitoring metrics: At a minimum, track the success rate of each component, end-to-end latency, cost per question-answering request, and user satisfaction.
    4. Isolate vendor dependencies: Encapsulate each provider’s interface behind an adapter layer. When switching providers, only the adapter layer should need to change while the business logic remains stable.

    Component-based capabilities lower the barrier to developing AI applications, but developers still need to manage orchestration, cost control, compliance, and governance. Planning these areas carefully is essential for turning the efficiency gains of composable services into a reliable product.