Multi-Model Architecture for Office Platforms: Routing, Fallback, and Cost Control

    This article walks through the engineering practices behind an office platform that scaled from three fixed model options to a pool of more than ten models from multiple vendors. It covers a unified access layer that abstracts heterogeneous APIs, a routing strategy split into hard constraints and soft scoring, fallback chains that never escalate capability tiers, context and cost controls such as context compression, semantic caching, and tiered quotas, and a three-layer evaluation and observability system. A phased rollout path is included to keep models pluggable without touching business code.

    1. Background: From Picking One Model to Operating a Model Pool

    When an office platform expands its capabilities from three fixed options to more than ten models, the engineering focus shifts. Previously the job was to keep a single path available; now the team faces a compound set of problems: differences in model capability, different context windows, uneven latency and cost distributions, and inconsistent vendor API styles. The situation described here — an office platform launching ten models from several vendors at once, covering general-purpose flagships, lightweight fast models, reasoning-enhanced models, and preview releases — is essentially a turning point where capability supply moves from scarce to abundant. Once supply is abundant, a platform’s competitiveness no longer depends on whether it has models, but on how mature its scheduling strategy, quality assurance, and cost governance are.

    The model list itself is only surface information. What actually determines experience is three things: whether a request can be routed to the most suitable model; whether it can switch smoothly when that model is unavailable or over budget; and whether the input and output of every call are fully recorded for later review. The sections below follow these three layers.

    2. Unified Access Layer: Collapsing Heterogeneous APIs into One Abstraction

    With multiple vendors on the same platform, the first technical debt is API fragmentation: authentication methods, request fields, streaming protocols, error codes, and rate-limiting policies all differ. A workable approach is to insert an abstraction layer between business logic and models, encapsulating the differences inside adapters.

    1. from dataclasses import dataclass
    2. from typing import Protocol, AsyncIterator
    3. @dataclass
    4. class ModelSpec:
    5. name: str # logical name, e.g. general_max / fast_flash
    6. ctx_window: int # context limit
    7. supports_stream: bool
    8. supports_tool_call: bool
    9. price_tier: str # tier label only, not tied to specific billing
    10. class ChatAdapter(Protocol):
    11. async def chat(self, messages: list[dict], **opts) -> str: ...
    12. async def stream(self, messages: list[dict], **opts) -> AsyncIterator[str]: ...
    13. class Registry:
    14. def __init__(self) -> None:
    15. self._specs: dict[str, ModelSpec] = {}
    16. self._adapters: dict[str, ChatAdapter] = {}
    17. def register(self, spec: ModelSpec, adapter: ChatAdapter) -> None:
    18. self._specs[spec.name] = spec
    19. self._adapters[spec.name] = adapter
    20. def get(self, name: str) -> tuple[ModelSpec, ChatAdapter]:
    21. return self._specs[name], self._adapters[name]

    Two constraints are critical for the abstraction layer. First, logical names must be decoupled from physical models: business code only recognizes stable identifiers such as general_max and fast_flash, so swapping the underlying implementation does not affect upper layers. Second, capability declarations must be explicit: whether streaming is supported, whether tool calls are supported, and the context limit all belong in metadata, where the routing layer can use them for hard-constraint filtering.

    3. Routing and Fallback: Turning Model Selection into Configurable Policy

    The value of multiple models is only released when routing is done well. A practical design splits routing into two steps: hard constraints plus soft scoring.

    Hard constraints eliminate unavailable options: context limit exceeded, tool calls required but unsupported by the model, tenant not on the allowlist, and so on. Soft scoring ranks the remaining candidates along common dimensions such as task-type fit, historical success rate, measured latency percentiles, and cost tier.

    1. routing:
    2. default: general_max
    3. rules:
    4. - match: {task: summarize, tokens_in: "<=8k"}
    5. prefer: [fast_flash, general_max]
    6. timeout_ms: 8000
    7. - match: {task: code_review}
    8. prefer: [reasoning_pro, general_max]
    9. timeout_ms: 20000
    10. fallback:
    11. chain: [fast_flash, general_max]
    12. on: [timeout, rate_limited, upstream_5xx]
    13. budget:
    14. daily_token_cap: 50000000
    15. degrade_to: fast_flash

    Fallback chains should follow a “no capability escalation” rule: dropping from a flagship to a lightweight model is acceptable, but promoting from lightweight to flagship leads to runaway cost; preview models should stay out of the default path and serve only as canary candidates. In addition, timeout budgets need to be bound to task type: summarization tasks get a short timeout and fast degradation, while code review tasks get a long timeout but limited concurrency.

    4. Context and Cost: The Hidden Bill in the Multi-Model Era

    As the number of models grows, cost risk moves from unit price to repeated input. If the same long document is sent to several different models for comparison, token consumption multiplies. Engineering can contain this in three places:

    • Context compression: perform structured extraction first (key points, tables, action items), send only the compressed result to the model, and keep the original long text in object storage for retrieval on demand.
    • Semantic caching: build cache keys for high-frequency, stable requests such as polishing with fixed templates or format conversion, where the key is derived from normalized input plus the policy version.
    • Tiered quotas: set daily and hourly quotas per tenant and scenario, and degrade automatically to a lightweight model once the cap is reached rather than rejecting outright, preserving availability.
    1. def cache_key(messages: list[dict], model: str, policy_ver: str) -> str:
    2. norm = "|".join(f"{m['role']}:{m['content'].strip()}" for m in messages)
    3. return f"{policy_ver}:{model}:{hash(norm)}"

    5. Evaluation and Observability: No Measurement, No Governance

    With more than ten models live, the biggest risk is quality drift that nobody notices. Three layers of measurement are recommended: an offline evaluation set (covering typical office tasks such as summarization, rewriting, extraction, and code, with fixed samples and scoring criteria), online canary releases (ramping traffic by percentage and comparing success rates with human spot-check scores), and runtime metrics (time to first token, overall latency, error code distribution, fallback trigger rate, and token consumption per task).

    Metrics should be collected centrally into the logging service and the monitoring and alerting system, with threshold alerts for sudden spikes in fallback rate, error codes concentrated on a single model, and per-task cost exceeding three times the average. When a model version changes, the evaluation set needs a regression run to avoid silent degradation.

    Phase one builds the abstraction layer and metadata to close the API differences first. Phase two adds routing and fallback, driving switches through configuration rather than hardcoding. Phase three fills in caching, quotas, and evaluation to form a closed governance loop. Throughout the process, models stay pluggable: adding a model means adding one adapter and one metadata record, with no changes to business code — the core of sustainable evolution for a multi-model platform.