Practical Cost Tiering and Routing Design for Multi-Model Access

    This article explains how to connect multiple large language models in an office AI agent while keeping costs and risks under control. It covers why one model cannot serve every office task, how a unified adapter layer hides provider differences, and how a model registry, routing strategy, and fallback mechanism select and switch models. It also describes quota multipliers for cost governance, evaluation and gradual rollout for model changes, and key security and compliance considerations.

    1. Problem Background: A Single Model Cannot Cover All Office Scenarios

    Office AI agents often handle many kinds of tasks, such as long-form text polishing, spreadsheet data analysis, code snippet generation, and meeting minutes organization. Models differ noticeably in reasoning depth, context length, response speed, and call pricing. If a system relies on one model, simple tasks waste money, while complex tasks may not get enough quality. For this reason, multi-model architectures that choose a model based on task characteristics are becoming a common choice for these products.

    Integrating multiple models creates three engineering challenges:

    • Interface differences: Each provider uses different request structures, authentication methods, and streaming output formats. Business code needs to hide these details.
    • Cost differences: The same conversation can consume resources several times over on different models, so the billing basis must be unified.
    • Availability fluctuations: Rate limits, timeouts, or failures in a single service directly affect user experience, so backup options are needed.

    The key to solving these three problems is to separate model calls from business logic and form an independent abstraction layer.

    2. Architecture Design: A Unified Adapter Layer

    The core idea is to add an adapter layer between business code and model services. Business code calls only the unified interface. The adapter converts each request into the format required by the target service, then normalizes the returned result into a unified structure. With this design, adding or replacing a model only requires changes to its registry entry and its corresponding adapter. The business logic stays unchanged.

    This adapter layer usually contains three components:

    1. Model registry: Records the model identifier, capability tags, context limit, quality level, and unit cost multiplier.
    2. Routing strategy: Selects a model based on task type, minimum quality requirement, and remaining budget.
    3. Fallback and retry mechanism: When the primary model times out or fails, switches to a backup model and logs the reason for the switch to support later troubleshooting.

    The following simplified implementation shows the data structures and routing logic:

    1. from dataclasses import dataclass
    2. from typing import Protocol
    3. @dataclass(frozen=True)
    4. class ModelSpec:
    5. model_id: str
    6. capabilities: frozenset[str] # e.g. {"summarize", "code", "table"}
    7. max_context_tokens: int
    8. quality: int # Quality level; higher is stronger. Determined by internal evaluation.
    9. cost_multiplier: float # Quota consumption multiplier relative to the baseline model
    10. class ChatProvider(Protocol):
    11. def complete(self, model_id: str, messages: list[dict]) -> str: ...
    12. class ModelRouter:
    13. def __init__(self, registry: list[ModelSpec], providers: dict[str, ChatProvider]):
    14. self.registry = registry
    15. self.providers = providers
    16. def pick(self, task: str, min_quality: int, budget_left: float,
    17. exclude: set[str]) -> ModelSpec:
    18. candidates = [
    19. s for s in self.registry
    20. if task in s.capabilities
    21. and s.quality >= min_quality
    22. and s.cost_multiplier <= budget_left
    23. and s.model_id not in exclude
    24. ]
    25. if not candidates:
    26. raise RuntimeError("No available model meets the task, quality, and budget requirements")
    27. # Choose the lowest-cost model among those that meet the conditions
    28. return min(candidates, key=lambda s: s.cost_multiplier)
    29. def call_with_fallback(router: ModelRouter, task: str, messages: list[dict],
    30. min_quality: int, budget_left: float) -> tuple[str, str]:
    31. tried: set[str] = set()
    32. while True:
    33. spec = router.pick(task, min_quality, budget_left, exclude=tried)
    34. tried.add(spec.model_id)
    35. try:
    36. text = router.providers[spec.model_id].complete(spec.model_id, messages)
    37. return spec.model_id, text
    38. except TimeoutError:
    39. # On timeout, move to the next round and try another candidate model
    40. continue

    Several points about this code deserve attention. First, routing filters before it sorts, so any model that fails a condition never enters the candidate set. Second, the fallback logic uses the exclude set to avoid trying the same model twice. When no candidates remain, it raises a clear exception instead of retrying indefinitely. Third, a real system should add finer exception classification, such as distinguishing rate limiting, authentication failures, and content moderation blocks, because each requires different handling.

    3. Quota Multipliers and Cost Governance

    When a product offers multiple models, the price users see is no longer a single number. A common approach is to set a baseline unit. Each call is converted into baseline consumption based on the actual input and output volume, then multiplied by the multiplier for the model used. When showing this to users, the multiplier should be clearly labeled so that users can judge the cost of their choice.

    The following example shows how the calculation works. The numbers are for illustration only and do not reflect the actual pricing of any product.

    • The baseline model consumes 100 units per call with a multiplier of 1.0, so the actual consumption is 100.
    • A lightweight model has a multiplier of 0.5, so the same task consumes 50.
    • A high-performance model has a multiplier of 2.0, so the same task consumes 200.

    Cost governance can cover the following areas:

    • Pre-call budget check: Before a call, check the remaining quota of the user or team against the estimated consumption to avoid requests that fail partway through.
    • Usage logging: Record token usage and converted consumption by model, task type, and user. This provides a basis for reconciling bills.
    • Tiered policies: For low-complexity tasks such as summarization and classification, use low-multiplier models by default. Upgrade to a stronger model only when the user explicitly asks for it or evaluation shows it is necessary.
    • Reconciliation: Periodically compare internal records with the provider’s bills, and investigate discrepancies promptly, such as duplicate charges caused by retries.

    4. Quality Evaluation and Gradual Rollout

    The routing strategy depends on quality levels, and those levels must come from reproducible evaluation rather than subjective impressions. We recommend building a fixed evaluation set for each task type. The set should cover common inputs, boundary inputs, and high-risk inputs. Record each model’s scores on dimensions such as accuracy, format compliance, and the appropriateness of refusals.

    When a new model is integrated, do not switch all traffic to it at once. We recommend the following steps:

    1. Offline evaluation: Run the model on the fixed evaluation set and confirm that the quality level and cost multiplier settings are reasonable.
    2. Small-traffic canary release: Select a small amount of non-critical traffic and observe task completion rate, time to first token, and cost per call.
    3. A/B comparison: Compare the old and new routing strategies on the same tasks, focusing on indirect metrics such as user rewrite rate and regeneration rate.
    4. Full rollout: Expand the scope only after the metrics are stable, and keep a switch that allows fast rollback.

    Every change to a quality level or multiplier in the registry should be treated as a strategy change and go through the same evaluation and rollout process.

    5. Security and Compliance Essentials

    A multi-model architecture expands the scope of data flow, so security design must be strengthened accordingly.

    • Data minimization: Send only the content necessary to complete the task. Before each call, mask or replace sensitive information such as ID numbers, phone numbers, and internal keys.
    • Cross-border transfer and contract review: When data crosses borders or goes to third-party services, the legal and security teams should confirm the data processing terms and clarify retention periods and permitted uses.
    • Key management: Store access credentials for each model service in a key management service or in environment variables. Never write them into code repositories or logs.
    • Regulatory filing: Providing generative AI services to the public in China generally requires filing or registration under applicable regulations. Specific requirements follow the latest rules issued by the competent authorities.
    • Output moderation: Apply content safety detection to model output, block violating content, and keep moderation records.

    6. Implementation Checklist

    When implementing multi-model integration, you can proceed in the following order:

    • Map the business task types, and list the capability and minimum quality requirements for each.
    • Build a unified adapter layer, and first connect one or two models to verify the interface and log format.
    • Complete the registry configuration, including capability tags, context limits, quality levels, and cost multipliers.
    • Implement budget checks, fallback and retry, and usage logging, and add corresponding unit tests.
    • Establish an evaluation set and a gradual rollout process, and include every strategy change in review.
    • Complete the security and compliance review, and confirm the data processing scope and filing status.

    By following this framework, multi-model capabilities can expand step by step within a controlled range of cost and risk, rather than introducing many unmanageable call paths at once.