Governing Enterprise AI Traffic at Scale: Design and Operation of a Policy-Driven, Multi-Vendor LLM Gateway on Envoy
Organizations: PayPal Inc.
Abstract
Large organizations consume large language models (LLMs) from several vendors at once, each with its own API dialect, credential model, streaming protocol and pricing. Integrated directly, this heterogeneity yields credential sprawl, format lock-in, unbounded spend and inconsistent governance. We present the design and production operation of the Cosmos LLM Gateway, the governed entry point for enterprise LLM traffic at PayPal. Built on Envoy, it splits work by latency profile: I/O-bound control decisions (authentication, credential brokering, policy and budget evaluation) run in an out-of-process external-processing service, while wire-format translation, token metering and prompt-cache shaping run in-proxy as a Rust WebAssembly filter, so that, by default, streamed response body chunks never wait on an out-of-process call. Models, providers and prices are largely validated data rather than code. Governance is declarative policy evaluated by Open Policy Agent and managed through a control plane with role-scoped authoring, approvals, pilots, shadow-mode rollout, usage notifications and versioned policy bundles. For use cases that require it, a data-loss-prevention layer can block, redact or pseudonymize detected sensitive content before it reaches a provider. Spend scopes are views over per-model usage counters, so a new budget applies to spend already recorded in its window without migration. As of September 2026, the gateway serves more than 12,000 developers and hundreds of business use cases, handling roughly 200 billion tokens per day across more than 100 models at 99.999% availability to business. In a benchmark of the core request path against a synthetic upstream, it adds a median of 4 ms and a p99 of 11 ms of overhead at more than 2,200 requests per second on two 4-vCPU instances. We report the architecture, policy model, evaluation and lessons learned.
Figures & tables
| Setting | control ext_proc | metrics ext_proc |
|---|---|---|
| Failure mode | fail closed | fail open |
| Request headers | send | send |
| Request body | buffered | streamed (mirrored) |
| Response headers | skip | send |
| Response body | none | streamed (mirrored) |
| Response trailers | send | send |
| Failure | Behavior |
|---|---|
| Control service unavailable | Request rejected (fail closed) |
| Access-policy evaluation error | Deny |
| Spend-policy evaluation error | Deny when enforcing; logged in shadow mode |
| Data-protection check cannot complete | Request not sent (fail closed) |
| Invalid registry / policy at boot | Process refuses to start |
| Policy bundle reload fails | Keep last-known-good revision |
| Upstream format | ||||
|---|---|---|---|---|
| Entry format | OAI Chat | OAI Resp. | Anth.@Vertex | Gemini |
| Anthropic Messages | T | T | R | T |
| OpenAI Chat | T ∗ | T | T | T |
| OpenAI Responses | – | I | – | – |
| Gemini generateContent | – | – | – | I |
| Layer | Set by | Effect |
|---|---|---|
| Catalog admission | platform (registry) | unknown model 404 |
| Model restriction | platform admin | leader allow/deny lists and exemptions 404 (same as unknown) |
| BU allow/block list | platform admin | a model is open to, or closed to, named business units |
| BU model toggle | BU admin | switch a model off for one’s own BU; cannot override a platform lock |
| Limited access | platform admin | bounded named roster with its own spend controls and expiry |
| Pilot cohort | platform admin | date-bounded allow/restrict lists per cohort |
| Overhead (ms) | |||||
|---|---|---|---|---|---|
| Instances | RPS | p50 | p95 | p99 | Failed |
| 2 | 1,137 | 4 | 10 | 11 | 0 |
| 2 | 2,257 | 4 | 10 | 11 | 0 |
| 4 | 1,138 | 4 | 10 | 11 | 0 |
| 4 | 2,262 | 4 | 9 | 10 | 0 |
| Measure | Value |
|---|---|
| Developers using the gateway | 12,000+ |
| Production use cases | hundreds |
| Requests per day | millions |
| Tokens per day (all traffic) | 200 billion |
| Models / model families / providers | 100+ / multiple / multiple |
| Peak throughput from a single workload | 60,000 req/min |
LLM Routing
Large language model routing selects models, tools, experts, or inference strategies to balance answer quality, cost, latency, and deployment constraints.
See all 355 papers