Design a multi-provider LLM gateway: routing, fallbacks, and the pitfalls teams hit.
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Core: one internal API (in practice, usually OpenAI-compatible plus extensions) with per-provider adapters normalizing request/response formats, streaming event shapes, tool-call conventions, and error taxonomies (whose 429 means what). Centralise credentials, per-tenant quotas, logging/cost metering, and PII redaction in the gateway - it's the one chokepoint where governance is enforceable. Build-vs-buy: LiteLLM/OpenRouter-style gateways or cloud-native (Bedrock/Vertex fronting multiple model families) cover the plumbing; you still own routing policy and evals.
Full worked answer with diagram
Core: one internal API (in practice, usually OpenAI-compatible plus extensions) with per-provider adapters normalizing request/response formats, streaming event shapes, tool-call conventions, and error taxonomies (whose 429 means what). Centralise credentials, per-tenant quotas, logging/cost metering, and PII redaction in the gateway - it's the one chokepoint where governance is enforceable. Build-vs-buy: LiteLLM/OpenRouter-style gateways or cloud-native (Bedrock/Vertex fronting multiple model families) cover the plumbing; you still own routing policy and evals.
Routing layers, from static to dynamic: (1) policy routing - each feature pinned to a model tier via config, changeable without deploys; (2) difficulty routing - a cheap classifier/heuristic sends easy traffic to small models, escalating hard cases (cascade with verification); (3) operational routing - cost/latency/health-aware selection among equivalent backends, honoring residency and data-handling constraints per tenant.
Fallbacks: per provider×model circuit breakers; on open, walk a fallback chain. The non-obvious rule: a fallback must be eval-gated, not just API-compatible. Prompts don't transfer 1:1 across model families - swapping silently can collapse quality while dashboards stay green. Maintain per-backend eval scores per feature, and mark responses with which model actually served them.
Pitfalls that actually bite:
- Tokenizer divergence: token counts (limits, truncation logic, cost estimates) differ per provider - never reuse one tokenizer's counts for another's budget.
- Feature disparity: structured-output guarantees, tool-call semantics, prompt-caching mechanics, streaming event types all differ; your abstraction must expose capabilities honestly rather than pretending to a false common denominator.
- Silent model updates: pin model versions; treat provider upgrades as deploys with eval runs.
- Streaming normalization: re-emit clean internal events; don't leak provider formats to clients.
- Cache fragmentation: prompt caches don't transfer across providers - failover forfeits cache discounts and TTFT gains; factor that into failover cost.
- The lowest-common-denominator trap: over-abstracting forfeits each provider's best features - the gateway should route and govern, not flatten.
Worth sketching. The request path drawn end to end shows where governance is enforced and where the fallback decision actually sits.
flowchart LR
A["App request"] --> GW["Gateway: auth, quota,<br/>redaction, cost metering"]
GW --> RT["Router: policy, difficulty,<br/>health and cost"]
RT --> P1["Primary model"]
P1 -->|"breaker open"| P2["Fallback model,<br/>eval-gated per feature"]
P1 --> N["Normalize stream events and errors"]
P2 --> N
N --> A
What a good answer covers
- Core: one internal API (in practice, usually OpenAI-compatible plus extensions) with per-provider…
- Centralise credentials, per-tenant quotas, logging/cost metering, and PII redaction in the gateway -…
- Build-vs-buy: LiteLLM/OpenRouter-style gateways or cloud-native (Bedrock/Vertex fronting multiple model…
- Routing layers, from static to dynamic
- Fallbacks: per provider×model circuit breakers; on open, walk a fallback chain
Key terms: Core · Routing · Fallbacks · Pitfalls that actually bite · Tokenizer divergence · Feature disparity · Silent model updates · Streaming normalization · Cache fragmentation · The lowest-common-denominator trap
In the glossary: Circuit breaker · TTFT · Router
Interviewer follow-ups to expect
How do you run evals continuously across backends without exploding cost?
Where does the gateway enforce prompt-injection and data-egress controls?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep