Cheatsheet 13 — Model Gateway Architecture

The components of an LLM gateway/proxy. Full: Phase 8. Lab: labs/lab-08-llm-gateway.

Why a gateway

One internal API in front of many providers/models → routing, fallback, cost control, metering, governance, observability, no client-side keys, no vendor lock-in.

Components (the building blocks)

client → [ AUTH ] → [ RATE LIMIT / QUOTA ] → [ ROUTER ] → [ PROVIDER ADAPTER ] → provider/model
                                                  │              │
                                          [ MODEL REGISTRY ]  [ FALLBACK / RETRY ]
                                                  │
              [ USAGE METERING ] ← [ STREAMING PROXY ] ← [ CACHE ] ← [ GUARDRAILS / POLICY ]
                                                  │
                                          [ OBSERVABILITY / AUDIT ]
ComponentJobPhase
Provider adaptersNormalize each provider's API to one shape8.03
Model registryCatalog of (model × provider) + metadata/price/limits8.04
Routing enginePick model/provider by cost/latency/quality/availability8.05
Fallback/retryFailover on error/timeout; circuit breakers7.07
Streaming proxyPass SSE tokens through transparently8.07
Usage meteringPer-key/team/tenant token + cost accounting8.06
CachingPrompt/prefix/response cache7.05
Guardrails/policyInput/output checks, PEP/PDP, fail-closed14.05
Auth + key custodyReal provider keys server-side; issue scoped internal keys14.03
Observability/auditTraces, p95/p99, cost, audit logs7.08 / 14.06

Routing strategies

StrategyWhen
Cost-optimized (cheapest that meets quality)Bulk/easy requests
Latency-optimizedUser-facing/interactive
Quality/difficulty-based (small↔premium)Mixed workloads (Phase 11.06)
Availability/failoverProvider outage resilience
Tenant/policy-basedResidency/compliance routing (fail-closed, 14.07)

Build vs buy

  • Buy/OSS: OpenRouter (aggregator API), LiteLLM (self-hosted proxy) — start here.
  • Build: when you need custom routing/policy/metering or it's your product (Phase 8.01–8.02).

Interview line

"A gateway gives me provider abstraction, routing/fallback for resilience, central cost metering, and key custody — so clients never hold provider keys, I can fail over on outages, and I route easy requests to cheap models to protect margin."


Next: 14 — RAG Design · Full: Phase 8