Markdown Editor

LLM Gateway System Design Template

LLM gateway and router design: unified API, provider adapters, token quotas, routing and fallback, caching, PII redaction, guardrail hooks, metering

SystemdesignVollständigOpenTelemetry GenAI semconv (Development); OWASP LLM Top 10 2026; RFC 9457designllmgateway

Anleitung: Use it when you put one gateway in front of several model providers and self-hosted models. Fill the data classes, tenants and token forecasts (2.1, 3.1) first, then the fallback chains per alias. The main pitfall is fallback that silently changes model quality or data handling: keep every chain pre-approved and visible in responses and metering.

Vorschau

System Design: [LLM gateway name]

Reference design for an LLM gateway and model router: one internal API in front of several model providers and self-hosted models. It covers the unified API, provider adapters, keys and quotas per tenant, routing and fallback, exact and semantic caching, PII redaction, guardrail hooks, token streaming, cost metering, telemetry with the OpenTelemetry semantic conventions for generative AI (Development status at the time of writing) and the audit trail. Model serving itself is covered by the LLM Inference Serving and Vector Search Platform Design Template (system-design/design-llm-inference-serving). It follows the 12-section structure of the System Design Document Template (system-design/system-design-document) and is pre-filled with a worked design to adapt. Replace every [bracketed] value and every row marked Example; all numbers are illustrative, not benchmarks or vendor prices.

Document control

FieldValue
Document ID[SDD-LGW-001]
System / feature[LLM gateway and model router]
Version[0.1]
Status[Draft / In review / Approved / Implemented / Superseded]
Owner[@owner]
Approvers / reviewers[@reviewer-1], [@reviewer-2]
Last updatedYYYY-MM-DD
Classification[Internal]
Providers in scope[External providers, self-hosted pools, regions]
Data classes allowed in prompts[Public / Internal / Confidential / Personal data with redaction]
Telemetry convention[OpenTelemetry GenAI semantic conventions, version pinned: x.y]
Related[API gateway design], [LLM observability spec], [Guardrails spec], [Threat model]

Approvals

RoleNameDecisionDate
Tech lead, AI platform[@name][Approved / Changes requested]YYYY-MM-DD
Staff / principal engineer[@name][Decision]YYYY-MM-DD
Security and privacy[@name][Decision]YYYY-MM-DD
SRE / operations[@name][Decision]YYYY-MM-DD
FinOps / budget owner[@name][Decision]YYYY-MM-DD

Revision history

VersionDateAuthorChange summary
0.1YYYY-MM-DD[@name]First draft for design review
0.2YYYY-MM-DD[@name]Example: Added semantic cache, off by default, opt-in per route
0.3YYYY-MM-DD[@name]Example: Moved PII redaction before the cache lookup
1.0YYYY-MM-DD[@name]Example: Approved

Contents

1. Overview

1.1 Problem statement

[Example: Forty product teams call three external model providers and two self-hosted model pools directly. Each team stores its own provider keys, several of them in application configuration. Nobody can answer how much the company spent on model calls last week, per team, until the invoices arrive. Two incidents in the last quarter came from customer personal data sent to a provider that is not approved for it. When one provider had a regional outage, every team improvised its own fallback, and two of them silently switched to a cheaper model with lower answer quality.]

1.2 Proposed solution

[Example: A single LLM gateway exposes one OpenAI-compatible chat and embedding API to internal callers. Callers authenticate with a gateway key bound to a tenant and a use case; the gateway holds all provider credentials. For each request it checks quotas in tokens and requests, applies the tenant's data policy (redaction, allowed providers, allowed regions), looks up the exact cache, picks a route from an alias such as chat-large to a concrete provider and model, streams the answer back, and emits one usage record and one trace per call. Guardrail hooks run before and after the model call. Fallback to another provider or model happens only along routes the tenant has approved, and is visible in the response and in metering.]

1.3 Decisions requested from reviewers

IDQuestionRecommended optionSection
Q-01Example: Unified API shape?OpenAI-compatible chat and embeddings, with gateway extensions in headers4
Q-02Example: Where does redaction run?In the gateway, before cache lookup and before any external provider7.4
Q-03Example: Semantic cache?Off by default; opt-in per route with a similarity threshold and tenant scoping7.5
Q-04Example: Fallback across providers?Pre-approved fallback chains per alias, never across data-policy boundaries7.3
Q-05Example: Quota unit?Tokens per minute and a monthly budget in currency, with requests per minute as a secondary guard7.2
[Q-nn][Question][Option][Section]

1.4 45-minute interview path

MinutesTopicWhat to show
0 to 5ScopeCallers, providers, the four jobs of the gateway (identity, policy, routing, metering); state that model serving is out of scope
5 to 10RequirementsCore list from 2.1, two or three numbers from 2.2, the below-the-line list from 2.3
10 to 15EstimatesConcurrent streams, peak tokens per second and daily spend (3.2 to 3.5), each with its consequence
15 to 22API and dataOne request example (4.2), the error contract and the usage record (5.1)
22 to 30High-level designThe diagram in 6, the request sequence in 7.1
30 to 40One deep diveRouting and fallback (7.3) for reliability questions, or redaction (7.4) for privacy questions, or quotas (7.2) for multi-tenancy questions
40 to 45Wrap-upFailure modes (9.1), the 10x row of the trade-off table (10)

2. Requirements

2.1 Core functional requirements

IDRequirementPriority
FR-01Example: One chat completion endpoint with streaming, and one embedding endpoint, compatible with the OpenAI request shapeMust
FR-02Example: Provider adapters translate the unified request to each provider's API and back, including streaming events, tool calls and errorsMust
FR-03Example: Gateway keys per tenant and use case; provider credentials held only by the gatewayMust
FR-04Example: Quotas per tenant and alias in tokens per minute, requests per minute and a monthly currency budgetMust
FR-05Example: Model aliases mapped to routes with weights, health checks and approved fallback chainsMust
FR-06Example: PII detection and redaction before external providers, with restoration in the response where the policy allowsMust
FR-07Example: Guardrail hooks before and after the model call, synchronous or asynchronous per policyMust
FR-08Example: Usage metering per request: tenant, alias, route, input, output and cached tokens, costMust
FR-09Example: Exact-match response cache for deterministic requestsShould
FR-10Example: Semantic cache, opt-in per routeCould
FR-11Example: Audit log of configuration changes and of access to stored promptsMust
[FR-nn][Requirement][Must / Should / Could]

2.2 Non-functional requirements

IDQualityTargetMeasured as
NFR-01Added latencyExample: p95 gateway overhead at or below 30 ms before the first streamed byte, excluding provider timeSpan timing: gateway start to provider request sent
NFR-02AvailabilityExample: 99.95% monthly for the gateway itselfSuccessful admissions over valid requests
NFR-03End-to-end availabilityExample: 99.9% for aliases with an approved fallback chainCompleted responses over admitted requests
NFR-04Quota accuracyExample: Overshoot at or below 2% of a tenant's tokens per minuteReconciliation of counters against usage records
NFR-05Metering completenessExample: 100% of admitted requests produce a usage record within 5 minutesDaily reconciliation against provider invoices
NFR-06PrivacyExample: No unredacted personal data reaches a provider not approved for itRedaction test corpus; sampled audits
NFR-07Data retentionExample: Prompts and outputs not stored by default; opt-in logging with 30-day retentionConfiguration audit
[NFR-nn][Quality][Target][Measurement]

2.3 Below the line (out of scope)

  • [Example: Running model servers and GPUs (see LLM Inference Serving and Vector Search Platform Design Template (system-design/design-llm-inference-serving))]
  • [Example: Prompt design, retrieval and agent loops inside applications (see RAG System Design Template (ai-data/rag-system-design))]
  • [Example: General API management for non-LLM traffic (see API Gateway System Design Template (system-design/design-api-gateway))]
  • [Example: Content policy decisions themselves; the gateway runs the classifiers defined in Guardrails and Safety Filter Specification Template (ai-data/guardrails-spec)]
  • [Example: Fine-tuning jobs and batch inference windows longer than 24 hours]
  • [Item deferred, with the release that will take it]

3. Capacity estimation

3.1 Assumptions

All values are Example planning inputs.

InputValueSource
Peak requests per second1,000Tenant forecasts
Average requests per second200Last 30 days of provider bills, converted
Mean input tokens per request1,200Sampled traffic
Mean output tokens per request300Sampled traffic
Mean stream duration6 sSampled traffic
Streams per gateway instance1,000Load test with redaction enabled
Usage record size (metadata only)1 KBSchema in 5.1
Logged payload size, when opted in8 KBPrompt plus output plus envelope
Share of traffic with payload logging20%Tenant opt-ins
Blended price, inputUSD 2.50 per million tokensExample contract
Blended price, outputUSD 10 per million tokensExample contract

3.2 Concurrent streams and instances

Little's law gives concurrent streams = arrival rate x duration = 1,000 x 6 s = 6,000 open streams at peak. At 1,000 streams per instance the gateway needs 6 instances at full load. Spread across three zones with four instances each (12 in total), losing one zone leaves 8 instances with 8,000 stream capacity, so peak load runs at 75%. Consequence: the gateway must use non-blocking I/O, and autoscaling must count open streams, not CPU, since a waiting stream costs memory and a socket but almost no CPU.

3.3 Token rates

Peak input is 1,000 x 1,200 = 1.2 million tokens per second; peak output is 1,000 x 300 = 300,000 tokens per second. Consequence: request counts alone cannot protect providers or budgets. Quotas must be in tokens, and the gateway must reserve input + max_tokens at admission and settle the actual count at the end (7.2).

3.4 Counter store load

Each request performs one reservation and one settlement, so the counter store sees about 2,000 atomic operations per second at peak. Consequence: one in-memory counter cluster per region is enough; key counters by tenant and alias so a hot tenant lands on one shard and does not slow others.

3.5 Daily volume, storage and spend

QuantityCalculationResultConsequence
Requests per day200 x 86,40017.28 millionUsage events go to a stream, never written synchronously to a relational database
Usage records per day17.28 million x 1 KB17.28 GBColumnar store partitioned by day and tenant
Usage records, 400-day retention17.28 GB x 400about 6.9 TBRetain 13 months for year-on-year chargeback, then aggregate
Logged payloads per day17.28 million x 0.2 x 8 KBabout 27.6 GBSeparate encrypted store, per-tenant keys
Logged payloads, 30 days27.6 GB x 30about 829 GBRetention job is a release blocker, not a later task
Input tokens per day17.28 million x 1,20020.736 billion
Output tokens per day17.28 million x 3005.184 billion
Input spend per day20,736 x USD 2.50USD 51,840
Output spend per day5,184 x USD 10USD 51,840Output tokens cost as much as input at a quarter of the volume, so max_tokens caps matter
Spend per 30 days(51,840 + 51,840) x 30about USD 3.11 millionBudgets and alerts per tenant are a core requirement, not a report
Saving from a 10% cache hit rate10% of USD 103,680 per dayabout USD 10,368 per dayExact cache is worth building first; semantic cache must prove quality before it is enabled

3.6 Summary

QuantityEstimateDesign consequence
Open streams at peak6,000Non-blocking proxy; scale on open streams
Instances12 across 3 zonesSurvives one zone loss at 75% load
Peak tokens per second1.2 million in, 300,000 outToken-based quotas with reservation
Counter operationsabout 2,000 per secondOne counter cluster per region, keyed by tenant
Usage dataabout 6.9 TB over 13 monthsStream plus columnar store
Spendabout USD 3.1 million per monthBudgets, alerts and chargeback from day one

4. API design

4.1 Endpoints

Method and pathPurpose
POST /v1/chat/completionsChat completion; stream: true returns server-sent events
POST /v1/embeddingsEmbed a batch of texts
GET /v1/modelsAliases the caller may use, with limits and data-policy labels
GET /v1/usage?from=&to=&group_by=Tokens and cost per alias, route and day
POST /admin/v1/routesCreate or change a route (audited, change-managed)
POST /admin/v1/tenants/{id}/quotasSet quotas and budgets (audited)

4.2 Request example

The caller names an alias, never a provider. Gateway extensions travel in headers so standard client libraries keep working.

POST /v1/chat/completions
Authorization: Bearer [gateway key]
X-Use-Case: support-summary
X-Request-Id: 4f1c2e7a-0b9d-4c1e-9a55-2d7e8f0c6b11
X-Data-Class: personal
Content-Type: application/json

{"model": "chat-large", "stream": true, "max_tokens": 400, "messages": [{"role": "system", "content": "[system prompt]"}, {"role": "user", "content": "[ticket text]"}]}

Response headers report what actually happened:

HeaderMeaning
X-RouteConcrete route used, for example provider-a/model-x@2026-08
X-Fallbacktrue when a fallback route served the request
X-Cachehit-exact, hit-semantic or miss
X-RedactedCount of entities redacted before the provider call

4.3 Errors

StatusProblem typeMeaning
400context-too-longInput plus max_tokens exceeds the route's context window
403data-policy-deniedData class not allowed on any route of this alias
422guardrail-blockedInput or output blocked by a guardrail; category returned, content not echoed
429token-rate-exceeded / budget-exhaustedQuota or monthly budget exhausted; Retry-After set for rate limits
502provider-errorProvider failed and no fallback is approved
503capacity-unavailableAll routes saturated or open-circuited
504deadline-exceededDeadline passed before the first token

Retries by callers carry the same X-Request-Id. The gateway deduplicates non-streaming requests by this ID for 10 minutes (Example), so a retried call after a network error is not billed twice. Streaming responses are not replayed: a retried stream is a new, separately metered request, so clients retry a stream only when no chunk was received.

5. Data model

5.1 Entities

Configuration is small and audited; usage records are high-volume and append-only. No entity stores prompt content unless the tenant opted in.

5.2 Access patterns

IDQueryKey or index that serves itPartition key and rationale
AP-01 (Example)Authenticate a key on every requestkey_hash lookup, cached in gateway memory for 60 sSmall table, replicated to every instance
AP-02 (Example)Read and update a tenant's token counterCounter key tenant:alias:minute in the counter storeTenant plus alias: spreads load, keeps one tenant's checks on one shard
AP-03 (Example)Resolve an alias to eligible routesIn-memory routing table, pushed on changeWhole table fits in memory; versioned
AP-04 (Example)Exact cache lookupHash of tenant, route, normalised request and parametersTenant in the key prevents cross-tenant hits
AP-05 (Example)Monthly spend per tenantColumnar table partitioned by day, clustered by tenantDay partitions make retention a partition drop
AP-06 (Example)Find all calls of one request ID in an incidentTrace store by trace ID; usage table by request_idRequest ID propagated as an attribute
AP-07 (Example)Who changed a route and whenAppend-only audit log by object and timeWrite once, never updated

5.3 Storage choices

DataStoreNotes
Tenants, keys, quotas, routes, policiesRelational database, cached in each instanceChanges propagate within 30 s; every change audited
Token countersIn-memory store with atomic scriptsSame pattern as Rate Limiter System Design Template (system-design/design-rate-limiter)
Exact cacheIn-memory store with TTLValues encrypted per tenant
Semantic cacheVector index per tenant and routeOpt-in only
Usage recordsEvent stream to a columnar warehouseNever on the request path
Logged payloadsEncrypted object storage with per-tenant keysOff by default, 30-day retention
Audit eventsAppend-only log with immutable retention13 months

6. High-level design

ComponentResponsibilityScales by
Gateway edgeTLS, key authentication, request ID, deadlineOpen streams
PolicyQuotas, budgets, data-class checks, route eligibilityWith the edge (same process)
PII redactionDetect and replace entities; keep a per-request mappingCPU; model-based detectors on a side pool
Guardrail hooksCall input and output classifiers per policySeparate classifier pool
CacheExact and opt-in semantic lookupCounter-store style cluster; vector index
RouterChoose a route by weight, health, region and policy; run fallbackIn process, table pushed from config
Provider adaptersTranslate requests, streams, tool calls and errorsIn process; one module per provider
MeteringEmit usage and audit events; reconcile with invoicesEvent stream

7. Detailed design

7.1 Request flow

The reservation happens before any provider call, so a tenant over quota never consumes provider capacity. Settlement uses the provider's reported usage when present and the gateway's own count otherwise; both are kept in the usage record so reconciliation can spot adapters that miscount.

7.2 Deep dive 1: quotas and budgets across tenants

OptionStrengthsWeaknesses
A. Requests per minute onlySimple, cheapOne long prompt costs a hundred short ones; budgets drift
B. Tokens per minute with reservation of input + max_tokens, settled at the endProtects providers and budgets; fair across prompt sizesLarge max_tokens holds quota during the stream; needs a tokenizer per model family
C. Post-hoc billing only, no admission controlNo latency costOverspend discovered after the fact

Choice: B, with requests per minute as a secondary guard and a monthly currency budget checked at admission against spend so far.

Reason: spend scales with tokens (3.5), and providers enforce their own token limits per account; mirroring them per tenant stops one tenant from exhausting the shared provider account. Input tokens are counted with the route's tokenizer at admission; when the route is unknown until fallback, the gateway reserves using the largest tokenizer ratio of the eligible routes and settles later.

RuleExample value
Counter windowSliding window of 60 s in 10-s buckets
Overshoot allowedUp to one in-flight reservation per tenant beyond the limit
Budget checkSpend so far plus reservation cost must stay under 100% of the monthly budget; alert at 80%
BurstThe whole per-minute quota may be used inside one 10-s bucket; no carry-over between windows

7.3 Deep dive 2: routing and fallback

OptionStrengthsWeaknesses
A. Static alias to one routePredictable qualityAny provider outage is an outage for the alias
B. Weighted routes plus health-based failover inside one approved chainSurvives provider incidents; quality reviewed in advanceNeeds evaluation of each route on the alias's tasks
C. Dynamic cost or latency optimiser across all modelsLowest costQuality changes without anyone deciding; can break data-policy rules

Choice: B. Each alias has an ordered fallback chain whose routes all passed the alias's evaluation suite and all satisfy the alias's data policy.

Reason: the 2 incidents in 1.1 came from fallback that changed quality or data handling without approval. Fallback is a product decision, not a networking one.

RuleConditionAction
RT-01 (Example)Alias chat-large, data class internal90% provider A, 10% provider B (live comparison)
RT-02 (Example)Route error rate above 20% over 30 s, or 5 timeouts in a rowOpen the circuit for 60 s; send traffic to the next route in the chain
RT-03 (Example)Provider returns rate-limit errorsBack off with jitter; shift share to the next route; do not retry the same route more than once
RT-04 (Example)Data class personalOnly routes with a data processing agreement and an approved region
RT-05 (Example)First token not received before 50% of the deadlineCancel and try the next route once; never after the first token was streamed

A request is never retried on another route after the first token reached the caller: the caller would see two different answers spliced together. Retry rules and circuit breakers follow the Resilience and Load Shedding Design Template (system-design/resilience-load-shedding-design).

7.4 Deep dive 3: PII redaction and restoration

OptionStrengthsWeaknesses
A. Pattern rules only (emails, phone numbers, card numbers)Fast, deterministicMisses names and addresses
B. Rules plus a named-entity model, replacement with typed placeholders, mapping kept in memory for the requestBetter recall; the answer can be restored for the callerAdds latency; placeholders can confuse the model
C. Block requests with personal dataSimple guaranteeBlocks legitimate use cases

Choice: B for routes to external providers; A for self-hosted routes in the approved region; C only for data classes that no route may receive.

Reason: most use cases need names in the answer (a support summary must name the customer), so redaction must be reversible inside the gateway while the provider sees placeholders. The mapping lives only in request memory and is never logged.

Rules:

  • Redact before the cache lookup, so cache keys and cached values never contain raw personal data.
  • Use typed, numbered placeholders ([PERSON_1], [EMAIL_1]); keep the numbering stable within one request so the model can refer back.
  • Restore on the streamed output; buffer partial placeholders that split across chunks before writing to the caller.
  • Measure recall on a labelled corpus per language; NFR-06 depends on it.

How real systems do it: Uber's GenAI Gateway (paraphrased)

Uber's engineering blog describes a gateway, written in Go, that gives internal teams one interface to third-party and in-house models and mirrors the OpenAI API so existing client libraries work. Before a request leaves for an external vendor, a redaction step swaps detected personal data for numbered placeholders and keeps the mapping, which the gateway then uses to put the original values back into the vendor's answer. Audit logs support cost attribution, security audits and quality evaluation, and each use case passes a security review against the company's data handling standard before it gets access. Source: Wang and Bansal, "Navigating the LLM Landscape: Uber's Innovation with GenAI Gateway", Uber Engineering blog, July 2024. Read the original for details; this box is a summary.

7.5 Deep dive 4: exact and semantic caching

OptionStrengthsWeaknesses
A. No cacheNo staleness, no leakage riskPays for every repeated call
B. Exact cache on normalised request plus parameters, only when temperature is 0 or a seed is fixedSafe, cheapLow hit rate on free-text traffic
C. Semantic cache: embed the last user turn, return a cached answer above a similarity thresholdHigher hit rateCan return an answer to a different question; needs per-route evaluation
D. Provider-side prompt caching of long shared prefixesCuts input cost and time to first tokenProvider-specific; counts must be metered separately

Choice: B on by default for eligible requests; D passed through and metered as cached tokens; C opt-in per route after an evaluation shows the wrong-answer rate below the route's threshold.

Reason: a semantic hit that answers a different question is a quality incident, not a cost saving. Cache entries are scoped to the tenant and the route version and expire when the route's model version changes.

7.6 Streaming and provider adapters

  • The gateway streams to callers with server-sent events (text/event-stream, WHATWG HTML Living Standard section 9.2) in one unified chunk format, and converts each provider's streaming events to it, including tool-call deltas and the final usage chunk.
  • Adapters normalise finish reasons, error codes and token counts into the gateway's vocabulary, and keep a test suite of recorded provider responses so a provider API change is caught in CI.
  • Client disconnect cancels the provider request and settles the tokens generated so far.

7.7 Guardrail hooks

HookPositionModeExample checks
HK-01Before cache and providerSynchronousPrompt injection classifier on untrusted content, blocked topics
HK-02On streamed output, every N tokensSynchronous, bufferedSensitive data leakage, policy categories
HK-03After completionAsynchronousQuality and safety sampling for evaluation

Hook definitions and thresholds live in the Guardrails and Safety Filter Specification Template (ai-data/guardrails-spec); the gateway only runs them and records the decision.

7.8 Telemetry and audit

Emit one span per model call using the OpenTelemetry semantic conventions for generative AI, which have Development status and are now maintained in the open-telemetry/semantic-conventions-genai repository. Pin the convention version you implement and record it in Document control.

AttributeUse
gen_ai.operation.namechat or embeddings
gen_ai.provider.nameProvider of the chosen route
gen_ai.request.model, gen_ai.response.modelRequested and served model
gen_ai.usage.input_tokens, gen_ai.usage.output_tokensToken counts for metering cross-checks
error.typeNormalised error class (stable attribute)
Gateway-specific (namespaced)Tenant, alias, route, fallback flag, cache result, redaction count

Prompt and output content are not recorded on spans by default. Full instrumentation rules are in the LLM and Agent Observability Specification Template (ai-data/llm-observability-spec).

8. Scalability and performance

ConcernApproachLimit before redesign
Open streamsNon-blocking proxy, scale on open streamsMemory per stream (buffers for restoration)
Counter storeShard by tenant and alias; local pre-aggregation for very hot tenantsSingle hot key above about 50,000 operations per second (Example)
Redaction latencyRules in process; entity model on a side pool with a 15 ms budgetLong prompts: redact in chunks in parallel
Routing table sizeIn memory, pushed on changeTens of thousands of routes
Provider limitsPer-account limits mirrored as global quotasContracted provider limits

Latency budget for gateway overhead (target p95 30 ms):

StepBudget
Authentication and policy (cached)2 ms
Counter reservation3 ms
Redaction (rules plus model)15 ms
Pre-call hook (fast classifier)8 ms
Cache lookup and routing2 ms
Headroom0 ms: the steps run in sequence, so the redaction model is the first step to cut when the budget is missed

9. Reliability, security and operations

9.1 Failure modes

IDComponentFailureDetectionBlast radiusMitigationRTO
FM-01Provider ARegional outage or error stormRoute error rate, circuit stateAliases routed to AFallback chain (7.3); status page for tenantsUnder 1 min (automatic)
FM-02Counter storeUnavailableReservation errorsAll tenants' quota checksFail open with a local per-instance cap for 5 min, then fail closed5 min
FM-03Redaction model poolSlow or downHook latency, errorsRequests with personal data to external routesFail closed for personal data; rules-only for internal routes10 min
FM-04Routing config pushBad route publishedCanary error rate, schema validationOne alias or allVersioned table, staged rollout, one-click rollback5 min
FM-05Metering streamBacklog or lossLag metric, reconciliation gapChargeback accuracy, not trafficDurable stream with replay; local spool on instances1 h
FM-06Gateway regionRegion lossHealth checksAll callers in regionActive-active regions; DNS or anycast failover15 min
[FM-nn][Component][Failure][Signal][Scope][Mitigation][Time]

9.2 Security

Mapping to the OWASP Top 10 for LLM Applications (2026 edition) and related controls; confirm entry numbering against the current list at genai.owasp.org.

IDThreatControl
SEC-01Leaked gateway key used by an outsiderKeys bound to use case and network zone; hashed at rest; rotation and anomaly alerts
SEC-02Provider credential exposureCredentials only in the gateway's secret store; never returned or logged
SEC-03Sensitive Information Disclosure (LLM02) through prompts sent to providersData-class policy, redaction, approved regions
SEC-04Unbounded Consumption (LLM06), denial of walletToken reservation, budgets, max_tokens caps per alias
SEC-05Prompt Injection (LLM01) in untrusted contentPre-call hook HK-01; application controls remain the primary defence
SEC-06Cache leakage across tenantsTenant in every cache key; per-tenant encryption
SEC-07Insider reads logged promptsOpt-in logging, access audited, break-glass approval
[SEC-nn][Threat][Control]

Run a full threat model with the Threat Model Template (security/threat-model).

9.3 Observability

SignalMetricAlert threshold
Gateway overheadp95 per stepAbove 30 ms for 10 min
Time to first tokenp95 per alias and routeAbove the alias SLO for 10 min
Route healthError rate, circuit stateCircuit open for more than 5 min
Fallback sharePercentage of requests per aliasAbove 10% for 15 min
Quota denials429 per tenantSudden rise per tenant
BudgetSpend versus budget80% and 100% of monthly budget
Metering reconciliationGateway tokens versus provider invoiceGap above 1% per month

9.4 Cost estimate

ItemUnit costQuantityMonthly cost
Provider tokensContract pricesFrom 3.5[USD]
Gateway instances[USD per instance-month]12[USD]
Counter and cache clusters[USD per node-month][Nodes][USD]
Redaction and classifier pools[USD per node-month][Nodes][USD]
Warehouse and logs[USD per TB-month]about 7.7 TB[USD]
Total[USD]

Track spend with the Cloud Cost Review Template (FinOps) (ops/finops-cost-review).

10. Trade-offs and alternatives

DecisionOptionsChosenWhyWhat we give up
Build or buyOpen-source gateway; managed gateway; in-house[In-house on an open-source proxy]Data policy and metering are company-specificMaintenance of adapters
API shapeOwn schema; OpenAI-compatibleOpenAI-compatibleExisting libraries work unchangedProvider-specific features need extensions
Quota unitRequests; tokens; currencyTokens plus currency budgetMatches cost and provider limitsTokenizer per model family
FallbackNone; approved chains; optimiserApproved chainsQuality and data policy stay decidedSome cost savings
Redaction placeApplication; gatewayGatewayOne control, one test corpusGateway latency and CPU
Semantic cacheOff; onOff by default, opt-inWrong-answer riskHit rate
What changes at 10x (10,000 requests per second at peak)Shard counters by tenant hash; regional gateways with local quotas and periodic global reconciliation; dedicated redaction fleetOne counter cluster and shared redaction pool become the bottleneckQuota accuracy across regions becomes eventual
What changes at 0.1x (100 requests per second at peak)Single regional deployment of 3 instances; managed counter store; rules-only redaction for internal routesFixed cost of a multi-region fleet is not justifiedLower availability and redaction recall on internal routes
[Decision][Options][Chosen][Why][Cost]

11. Delivery plan and risks

11.1 Milestones

MilestoneScopeExit criterionTarget date
M1Edge, keys, one provider adapter, meteringTwo tenants migrated; usage reconciles within 1% of the invoiceYYYY-MM-DD
M2Token quotas, budgets, second provider, fallback chainsFailover drill meets NFR-03YYYY-MM-DD
M3Redaction and restoration, guardrail hooksRedaction recall target met per language; NFR-06 audit passedYYYY-MM-DD
M4Exact cache, self-hosted routeHit rate and saving reported per aliasYYYY-MM-DD
M5Provider keys removed from all applicationsSecret scan shows no provider keys outside the gatewayYYYY-MM-DD

11.2 Rollout and rollback

[Example: Tenants move one use case at a time by changing their base URL; direct provider access remains for 30 days and is then revoked. Route changes roll out to 5% of an alias's traffic first and roll back automatically on error-rate breach.]

11.3 Risks

IDRiskLikelihoodImpactMitigationOwner
R-01Example: Gateway becomes a single point of failureMediumHighMulti-zone, multi-region, fail-open rules for counters[@name]
R-02Example: Adapters lag behind new provider featuresHighMediumPassthrough extension field; adapter test suite[@name]
R-03Example: Redaction misses entities in some languagesMediumHighPer-language corpus; block personal data where recall is unproven[@name]
R-04Example: Teams bypass the gatewayMediumMediumEgress rules block provider endpoints from application networks[@name]
[R-nn][Risk][L / M / H][L / M / H][Mitigation][@name]

12. Appendices

12.1 Traceability

RequirementDesign elementVerification
FR-04, NFR-047.2 quotas and budgetsLoad test with mixed prompt sizes; reconciliation
FR-05, NFR-037.3 routing and fallbackProvider outage drill
FR-06, NFR-067.4 redactionLabelled corpus per language; sampled audit
FR-08, NFR-057.1 settlement, 5.3 meteringMonthly invoice reconciliation
NFR-018 latency budgetSpan timing in production
[ID][Element][Test]

12.2 Open questions

IDQuestionOwnerDue
OQ-01Example: Do batch APIs of providers go through the gateway or a separate path?[@name]YYYY-MM-DD
OQ-02Example: Which telemetry convention version do we pin while the GenAI conventions are in Development?[@name]YYYY-MM-DD
[OQ-nn][Question][@name]YYYY-MM-DD

12.3 Glossary

TermMeaning
AliasStable model name used by callers, mapped by the gateway to routes
RouteConcrete provider, model version and region that can serve an alias
Fallback chainOrdered list of approved routes tried when the preferred route fails
RedactionReplacing detected personal data with placeholders before a provider call
Semantic cacheCache that returns a stored answer for a similar, not identical, request
Denial of walletAttack or bug that drives model spend instead of taking a service down

12.4 References

ReferenceUse
OpenTelemetry semantic conventions for generative AI (Development status), https://github.com/open-telemetry/semantic-conventions-genaiSpan and metric names in 7.8
OWASP Top 10 for LLM Applications, 2026 edition, OWASP GenAI Security Project, https://genai.owasp.org/ (CC BY-SA 4.0)Threat names in 9.2
WHATWG HTML Living Standard, section 9.2 Server-sent eventsStreaming format in 7.6
RFC 9457, Problem Details for HTTP APIs (2023)Error format in 4.3
Wang and Bansal, "Navigating the LLM Landscape: Uber's Innovation with GenAI Gateway", Uber Engineering blog, 11 July 2024Box in 7.4 (paraphrased)
LLM Inference Serving and Vector Search Platform Design Template (system-design/design-llm-inference-serving)Self-hosted routes
API Gateway System Design Template (system-design/design-api-gateway)General API management
Rate Limiter System Design Template (system-design/design-rate-limiter)Counter algorithms
LLM and Agent Observability Specification Template (ai-data/llm-observability-spec)Instrumentation rules
Guardrails and Safety Filter Specification Template (ai-data/guardrails-spec)Hook definitions
Agentic AI Threat Model Template (ai-data/agentic-threat-model)Threats when agents call the gateway

Standard and licence note

Based on the OpenTelemetry semantic conventions for generative AI (Development status, Apache-2.0), the WHATWG HTML Living Standard section on server-sent events, RFC 9457, and the OWASP Top 10 for LLM Applications 2026 by the OWASP GenAI Security Project (CC BY-SA 4.0; OWASP entry names are attributed to OWASP, and any adapted OWASP material you redistribute must carry the same licence under its ShareAlike term). The engineering write-up in 7.4 is paraphrased and cited as inspiration only. The text is original; provider behaviour, prices and convention names change often, so check the current official version of each source before approval. Template licence: MIT.

Ähnliche Vorlagen