Multi-Model Integration for AI Office Products: A Guide to Routing, Billing, and Model Selection
This guide explains how to build a multi-model architecture for AI office products. It covers a gateway that normalizes differences between providers, complexity-based routing with fallback rules, quota multiplier billing with a worked example, model selection by task type, and requirements for data masking and auditing.
1. Why AI Office Products Need a Multi-Model Architecture
AI agent-based office products are goal-driven. Users describe a task, and the system breaks it into steps, calls tools, and delivers the result. Tasks vary widely. A one-sentence summary may need only a few hundred tokens, while cross-document analysis and long reports can require tens of thousands of tokens of context and stronger reasoning. A single model rarely balances quality, speed, and cost. For this reason, most platforms integrate both in-house models and third-party models, and the system or the user selects a model for each task.
This article does not refer to any specific product. It describes common industry practices. The thresholds, multipliers, and timeouts cited here are example values that illustrate the design approach. Before deployment, recalibrate them against each provider’s service level agreement (SLA) and your own business data.
2. Unified Adaptation Layer: Smoothing Out Protocol Differences First
Providers differ in authentication, streaming output formats, function calling schemas, and error codes. A common approach is to build a Model Gateway that exposes a unified interface upstream, while adapters handle each provider’s protocol details downstream. The adaptation layer should handle at least five tasks.
- Streaming output: Normalize all providers to one event format. When a client cancels a request, the gateway closes the upstream connection immediately to stop further charges.
- Function calling: Convert each provider’s tool definitions into an internal unified schema. Models that do not support parallel calls process tool requests sequentially.
- Error code normalization: Retry logic depends only on internal error types and never reads vendor error codes directly. See the mapping table below.
- Timeouts and retries: The example first-packet timeout is 5 seconds. Overall timeouts vary by task type. Example values are 60 seconds for interactive tasks and 300 seconds for background tasks.
- Context truncation: When input exceeds 80% of the model’s context window, truncate in this order: keep system instructions, keep the most recent turns, and compress the middle history.
The error mapping table is as follows.
| Vendor signal | Internal error type | Retry | Backoff and limit |
|---|---|---|---|
| 429 rate limiting | RateLimited | Yes | 1 second, then 2 seconds, with random jitter, maximum 2 retries |
| 5xx server error | UpstreamError | Yes | Same as above |
| First-packet or overall timeout | Timeout | Yes | Same as above |
| Content moderation rejection | ContentBlocked | No | Return to the user and prompt them to revise the input |
| 400, 401, 403 parameter or authentication error | ClientError | No | Log an alert, no retry |
3. Intelligent Routing and Fallback
Routing runs in three steps. Step one applies hard constraint filtering. Step two determines the complexity tier. Step three checks quota and model health.
Hard constraints override all other rules. When input exceeds 32k tokens, only long-context tiers are eligible. When the data classification is sensitive, only models on the allowlist are eligible. Both rules also apply during fallback, so downgrading can only happen within the candidate set that passed hard constraint filtering.
The complexity score S ranges from 0 to 100 and is assigned by a lightweight classification model or by rules. Scoring factors include task type, input length, whether multi-step reasoning is required, and whether the task involves code or numerical computation. Example thresholds are shown below.
| S score range | Tier |
|---|---|
| Below 30 | Light |
| 30 to 69 | Balanced |
| 70 and above | Flagship |
Fallback follows these rules. When no healthy model exists in the same tier, drop one tier. When the quota exceeds the user or department cap, also drop one tier. If the lowest tier still exceeds the quota, ask the user to confirm before execution. Fallback only moves downward, never upward.
Health is judged over a 5-minute sliding window. When a model’s failure rate in the window exceeds 5%, the model is temporarily removed from the pool and re-evaluated after the window ends. In the example, no removal occurs when the window contains fewer than 50 requests. This prevents a few failures from causing false positives. When a model switch happens, the result must be labeled “model switched.”
The routing pseudocode is as follows.
MIN_TIER = 0 # 0 light, 1 balanced, 2 flagshipdef route(task):base = filter_by_hard_constraints(task) # context length, data classification, allowlist; filter only onceif not base:return ask_user("No model meets the hard constraints. Adjust the task or the data classification.")tier = tier_by_score(task.complexity_score)for t in range(tier, MIN_TIER - 1, -1): # downgrade onlypool = [m for m in baseif m.tier == tand is_healthy(m) # failure rate in the last 5 minutes does not exceed 5%and meets_latency(m, task)] # interactive tasks: first-token P95 does not exceed 2 secondsif not pool:continue # no healthy model, drop one tiermodel = cheapest(pool)if estimate_quota(task, model) <= task.quota_cap:return model # if t is below the initial tier, label the result "model switched"return ask_user("Estimated quota exceeds the cap. Confirm whether to continue.")
The logic has two key points. First, the candidate set base is filtered by hard constraints before any downgrade, so downgrading cannot break long-context or data classification limits. Second, latency is checked model by model rather than by tier alone. After a downgrade, the router will not select a model that misses the latency target. Quota estimation uses max_tokens as the upper limit for output tokens.
Routing rule changes roll out with A/B testing in three stages: 5%, 20%, and 100% of traffic. The traffic split key is a hash of the task ID or user ID, so the same user consistently lands in the same group over time. The control group and the experiment group are compared on four metrics: task success rate, P95 latency, quota cost per task, and manual review pass rate. Results are broken down by task type. A regression is defined as the experiment group performing at least 10% worse than the baseline on any metric in the unfavorable direction, with the difference statistically significant at the 95% confidence level. When this condition is met, the system immediately rolls back to the previous rule version. Each stage runs for at least 24 hours, with an example minimum of 2,000 tasks per group. The rule owner performs rollbacks and notifies the on-call channel.
4. Quota Multipliers: Billing Basis and Worked Example
The platform first defines a unified billing unit. In the example, every 1,000 effective tokens count as one billing unit. Each model has a multiplier coefficient that reflects its relative cost. The formulas are as follows.
Effective tokens = (total input tokens − cache-hit tokens) + cache-hit tokens × 0.1 + output tokens + reasoning tokens
Billing units = ⌈effective tokens ÷ 1000⌉ (rounded up)
Task quota = billing units × multiplier coefficient (rounded to one decimal place)
Cache-hit tokens count at 0.1 because cached input is typically billed at a lower unit price. The exact coefficient follows each provider’s billing rules. Reasoning tokens are counted separately because the hidden thinking process of reasoning models is also billed. The cap rule is that a single task’s quota must not exceed the user or department cap. When the c
