An AI gateway becomes the single place that holds every model provider key and sees every prompt and response in the organisation, so rolling one out without security designed in creates the most valuable target in the AI estate. AI gateways (also called LLM gateways or model proxies) sit between applications, agents and users on one side and model providers on the other, adding authentication, routing, budgets, logging and guardrails. This playbook covers rolling one out in phases: discovery of existing model use, the identity model for callers and providers, hardening the gateway before traffic arrives, onboarding applications in waves, closing the bypass routes, and measuring whether it works. It is vendor-neutral and written for platform, security and AI engineering teams. What a gateway is and its architecture options are covered in the AI Gateway and LLM Gateway Guide, which this page does not repeat.
Key takeaways
- Discover before you route. Find existing provider keys, SDK usage and direct traffic first; a gateway that only sees the willing is a partial control.
- Every caller gets its own identity. Issue a gateway credential per application, agent or team, with its own budget and model allow list, never one shared key.
- Provider keys live only in the gateway. Move them into a secrets manager referenced by the gateway, revoke the copies in applications, and rotate them after onboarding.
- Harden the gateway first. Admin interface off the internet, no default master keys, federated admin sign-in, pinned and verified releases, logs flowing before production traffic.
- Close the bypass. Block direct egress to model provider endpoints from servers and pipelines once a wave is onboarded, or the gateway becomes optional.
The rollout at a glance
| Phase | Goal | Exit criterion |
|---|---|---|
| 0. Discovery | Know who calls which models with which keys | Inventory of callers, providers and keys with owners |
| 1. Design | Identity model, data rules, deployment and logging decisions | Approved design and data handling policy |
| 2. Build and harden | Gateway running, hardened and monitored with no production traffic | Hardening checklist passed; logs in the SIEM |
| 3. Pilot | Two or three applications routed through the gateway in observe mode | Latency, error and cost within agreed limits |
| 4. Enforce and wave | Budgets, allow lists and guardrails enforced; more applications onboarded | All in-scope callers routed |
| 5. Close bypass | Direct provider access blocked; old keys revoked | No direct provider traffic from managed networks |
Phase 0: discovery
- Keys in code and CI: scan repositories, CI variables and secrets stores for model provider keys. See How to find LLM API keys in code and CI.
- Provider consoles: list organisations, projects and keys in each provider account, with creation dates, last use and spend.
- Network evidence: proxy, DNS and firewall logs show which hosts reach provider API domains directly.
- Agents and tools: agent frameworks, coding assistants and MCP servers often carry their own keys. See the Shadow AI Discovery Guide.
- Owners and data: for each caller record the owner, the data classes sent in prompts, and the business impact of an outage.
Phase 1: design decisions
The NCSC and partner agencies' Guidelines for Secure AI System Development (November 2023) group their advice into secure design, development, deployment, and operation and maintenance; most gateway design decisions belong to the deployment and operation stages. NIST's Generative AI Profile (NIST AI 600-1, July 2024), a companion to the AI Risk Management Framework, is the reference for the risk side.
Identity model
| Direction | Credential | Good practice | Avoid |
|---|---|---|---|
| Caller to gateway (applications) | Per-application gateway key or workload identity token | Workload identity federation where the platform supports it; otherwise scoped keys with expiry, budget and model allow list | One key shared across teams |
| Caller to gateway (agents) | Per-agent credential | Separate identity per agent so actions and spend are attributable and revocable | Agents reusing the hosting application's key |
| Caller to gateway (people) | SSO session through the internal chat or tools front end | Group-based model access | Personal provider keys |
| Gateway to provider | Provider API key or cloud role | Held in a secrets manager; one key per environment; spend caps at the provider | Keys pasted into gateway configuration files |
| Administrators | Federated admin sign-in | Phishing-resistant MFA; separate roles for configuration and log access | A static master key used by people |
See the LLMjacking Guide for how stolen model keys are abused, and the AI gateway integration security guide for the gateway's connections to other systems.
Data handling and logging
The gateway sees prompts and responses that can include personal data, secrets and confidential documents (OWASP LLM02:2025 Sensitive Information Disclosure). Decide before go-live what is logged in full, what is logged as metadata only (caller, model, token counts, latency, policy verdicts), who can read prompt logs, and how long they are kept. A sensible default (our recommendation) is metadata for all traffic, full prompt logging only where a documented need exists, and prompt logs access-controlled like the most sensitive data they may contain. See the Generative AI Data Loss Prevention Guide.
Deployment choice
Decision guidance: a self-hosted gateway keeps prompts inside your environment but makes you responsible for patching, scaling and hardening. A managed gateway service reduces operations but adds a third party that sees prompts and holds provider keys, so it needs supplier assurance. A small organisation with a handful of AI features may start with provider-side controls (per-project keys, spend limits, usage dashboards) and add a gateway when the number of callers or providers grows; see How to set spend limits on LLM API keys. A large organisation with many teams and providers gains most from a central gateway, run as a platform service with an SLA.
Phase 2: build and harden the gateway
- No default credentials: replace any default or bootstrap master key before the gateway is reachable, and stop using master keys for daily administration. The live LiteLLM MCP auth bypass page shows default master keys and an authentication flaw exposing AI gateway credentials.
- Admin interface off the internet: expose only the inference endpoint to callers; put the admin UI and API on a management network behind SSO.
- Pinned and verified releases: install by version and digest from the official source and verify signatures where offered. The LiteLLM PyPI package breach shows a gateway's own distribution channel used to steal LLM API keys.
- Secrets by reference: the gateway reads provider keys from a secrets manager at run time; its configuration repository holds references, not values.
- TLS everywhere: callers to gateway and gateway to provider, with certificate validation on.
- Logs first: admin actions, key creation and deletion, policy changes, authentication failures, budget events and guardrail verdicts flow to the SIEM before any production traffic.
- Capacity and failure mode: decide whether the gateway fails open or closed for each class of caller. Safety-relevant or data-sensitive flows should fail closed; see the AI Kill Switch Act Guide for why a central stop point matters.
Phase 3 and 4: pilot, enforce and onboard in waves
- Pick pilot callers: two or three internal applications with engaged owners and moderate traffic, not the busiest customer-facing service.
- Observe mode: route through the gateway with logging, budgets and guardrails set to report only. Measure added latency, error rates and token counts against the direct baseline.
- Issue per-caller credentials: each pilot application gets its own gateway credential, budget and model allow list; the old provider key in the application is removed, then revoked.
- Enforce controls: switch budgets, rate limits and allow lists to enforcing. OWASP LLM10:2025 Unbounded Consumption lists rate limiting, resource allocation management, timeouts and throttling, and logging with anomaly detection among its mitigations against denial of wallet and model extraction through the API.
- Add guardrails carefully: input and output filters for prompt injection (LLM01:2025), sensitive data and system prompt leakage (LLM07:2025) start in report mode, are tuned against real traffic, then enforced for the classes that matter. See the AI Guardrails and AI Firewalls Guide.
- Wave by risk: customer-facing and agentic workloads next, then internal tools, then batch and experimentation. Onboarding is a checklist: owner, data classes, models allowed, budget, logging level, failure mode.
- Default path for new work: platform templates and internal SDK wrappers point at the gateway, so new applications never receive provider keys.
Rollback
- Per-caller routing switch: a caller can be returned to a known-good configuration (previous policy version or previous model route) without touching others.
- Guardrail rollback: a filter that blocks legitimate traffic returns to report mode, not off, while it is tuned.
- Emergency direct route: if the gateway itself fails, a documented, time-limited direct route with a dedicated, capped provider key is safer than teams restoring old keys on their own. Revoke it after the incident.
Agents and tool calls
Agentic workloads need more from the gateway than chat applications. An agent may call models many times per task, chain tools, and act on the results, so a stolen agent credential or a manipulated prompt has wider effects (OWASP LLM06:2025 Excessive Agency). When onboarding agents:
- Per-agent budgets and loop limits: cap tokens per task and per hour so a looping or hijacked agent stops on its own.
- Model allow lists per agent: an agent that only summarises does not need the most capable or most expensive model.
- Correlate gateway and tool logs: record a task or session identifier at the gateway so model calls can be joined with the agent's tool calls during an investigation.
- Tool traffic has its own control point: calls from agents to MCP servers and other tools are governed separately; see the MCP Gateway and MCP Server Governance Guide.
Phase 5: close the bypass
- Egress control: block direct access to model provider API domains from servers, containers and CI runners, allowing only the gateway's egress addresses. User devices are covered by the web proxy or security service edge policy for AI services.
- Revoke and rotate: revoke every provider key found in discovery that is not held by the gateway, and rotate the gateway's own provider keys once onboarding is complete, since earlier copies may persist in history.
- Provider-side restrictions: where providers support it, restrict keys to the gateway's network addresses and set spend caps at the provider as a second line.
- Keep discovering: repeat secret scanning and egress log reviews monthly; new direct callers are the earliest sign of a gap.
Detection and measurement
| Metric or signal | Why it matters | Target (our recommendation) |
|---|---|---|
| Share of model traffic through the gateway | Coverage of the control | Above 95% from managed workloads |
| Provider keys outside the gateway | Bypass and leak exposure | Zero, apart from a sealed emergency key |
| Callers sharing a gateway credential | Attribution and revocation | Zero |
| Spend or token anomalies per caller | Denial of wallet, stolen credentials (ATLAS AML.T0034 Cost Harvesting) | Alert at agreed multiples of the baseline |
| Guardrail block and false positive rates | Whether filters work and are trusted | Reviewed weekly during waves |
| Added latency at the 95th percentile | Developer acceptance | Within the agreed budget |
Alert on use of a caller credential from a new network location, on calls to models outside a caller's allow list, on high-volume or systematic querying that could indicate extraction (ATLAS AML.T0024 Exfiltration via AI Inference API), and on any admin action outside change control.
Common failure patterns
- Optional gateway: onboarding is voluntary and direct egress stays open, so the riskiest callers never move.
- One key for everyone: all applications share a gateway key, so spend, abuse and incidents cannot be attributed or contained.
- Old provider keys left alive: applications move to the gateway but their former provider keys are never revoked.
- Default master key in production: the bootstrap credential becomes the admin credential and ends up in scripts.
- Prompt logs as a new data lake: full prompts and responses are kept indefinitely with broad read access.
- Guardrails switched straight to block: legitimate traffic fails, teams demand exceptions, and filters are turned off rather than tuned.
Framework mapping
| Activity | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | OWASP and ATLAS |
|---|---|---|---|
| Per-caller identities and provider keys | IA-5, AC-6 | PR.AA-01, PR.AA-05 | ATLAS AML.T0040 AI Model Inference API Access |
| Access enforcement and model allow lists | AC-3 | PR.AA-05 | Not mapped |
| Budgets and rate limits | SC-7 | PR.IR-01 | LLM10:2025; AML.T0034 |
| Prompt and output filtering | SI-10 | Not mapped | LLM01:2025, LLM07:2025; AML.T0051 |
| Agent budgets and loop limits | AC-6 | Not mapped | LLM06:2025 |
| Sensitive data in prompts and logs | SC-8, AU-11 | PR.DS-02 | LLM02:2025; AML.T0057 LLM Data Leakage |
| Inventory of AI callers and providers | CM-8 | ID.AM-02 | Not mapped |
| Monitoring and anomaly detection | SI-4, AU-6 | DE.CM-01 | AML.T0024 |
| Gateway software supply chain | SR-3, SR-4 | GV.SC-07 | LLM03:2025 Supply Chain |
Practitioner checklist
- Inventory provider keys, direct callers, agents and data classes before routing any traffic.
- Issue one gateway credential per application, agent or team, each with budget and model allow list.
- Hold provider keys only in a secrets manager referenced by the gateway; revoke application copies.
- Replace default master keys, keep the admin interface off the internet and federate admin sign-in.
- Pin and verify gateway releases and send admin, key, policy and budget events to the SIEM before go-live.
- Decide what prompt content is logged, who can read it and for how long.
- Pilot in observe mode, then enforce budgets and allow lists, then tune guardrails before blocking.
- Block direct egress to provider APIs from managed workloads once each wave is onboarded.
- Measure coverage, keys outside the gateway, spend anomalies and guardrail accuracy monthly.
Standards and references
- OWASP: Top 10 for LLM Applications 2025
- MITRE ATLAS: Cost Harvesting
- NCSC: Guidelines for Secure AI System Development
- NIST: AI Risk Management Framework and Generative AI Profile (NIST AI 600-1)
- NIST: SP 800-53 Rev. 5, Security and Privacy Controls
- NIST: Cybersecurity Framework 2.0
- MITRE ATLAS: Exfiltration via AI Inference API
Related NHI Mgmt Group resources: AI Gateway and LLM Gateway Guide · AI Gateway Buyer's Guide · LiteLLM Proxy Security Guide · If your AI gateway is compromised · MCP Gateway and MCP Server Governance Guide