AI Gateway Security: Risks, Best Practices, and Protection
Learn what AI gateway security is, explore key risks such as prompt injection and data leakage, and discover best practices to secure AI gateways.

Rushali
2026 State of Agentic AI Security
How ready is your organization to secure AI agents?
3 quick questions. See how you compare to other security leaders.
AI gateway security refers to the suite of security measures that an AI gateway applies to all communications made between your applications, agents, and model providers: Caller authentication, Model access control, Prompt and response inspection, Data loss prevention, Token-aware rate limits, and Audit logging. It transforms random LLM calls into a controlled, visible, and protectable flow.
Fewer than 36 hours after the advisory was made public, attackers started exploiting CVE-2026-42208, which is a pre-authentication SQL injection in the LiteLLM proxy. They were observed by Sysdig to be going directly for three tables: virtual API keys, stored provider credentials, and the proxy's environment configuration. That's the fundamental conflict in the security of AI gateways. The gateway is where you focus model keys, prompts, and policy to control them, which is also where they're the most plentiful in your AI stack. This guide explains: What an AI gateway is and what security controls it should be able to implement on LLM / agent traffic; The differences between an AI gateway and an API gateway and an AI firewall; How it aligns with compliance frameworks; How to select and harden one so it is not the weak link.
What is an AI Gateway?
An AI gateway is a middle-layer proxy that exists between all of the applications, copilots, agents, and batch pipelines that consume AI and everything that serves it – hosted model providers, self-hosted models, and even more importantly, MCP servers and tools. The gateway converts the request to the provider's format based on the policy and sends the resulting request to an application that typically implements a provider-compatible endpoint. The lifecycle of a request as it passes through enterprise AI gateway products, whether open-source or commercial, such as LiteLLM or Kong, Portkey, TrueFoundry, and Palo Alto Networks, will follow the same general pattern:
Request in. The caller logs in to the gateway using its own credentials, not the provider's.
Input checks. The gateway checks the prompt for sensitive data, policy breaches, and injections.
Routing. Model alias is translated to a concrete provider, model, and location based on policy, cost, and health.
Provider call. The gateway binds the provider credential it carries and passes on the request.
Output checks. The response is only validated before it comes back to the caller.
Logs: Tokens, cost, latency, caller, and all policy decisions.
The integration from the developer's side is as simple as changing the base URL:
That key in the header defines the calling application's name to the gateway and will NOT be used directly with OpenAI or Anthropic; the key of the calling application is never visible to the developer. The earlier "LLM gateways" did not go as far as routing and caching. As agents now act on systems, and not just create text, current AI API gateway products also dictate their tool invocations and MCP connections.
What Is AI Gateway Security?
There are two distinct aspects of AI gateway security: AI gateway security can be divided into two parts that can get confused together. The first is security enforced by the gateway: it enforces the policy for each model call, who can call which model, what data can be sent, what can be returned, and what can be logged. The latter is the security of the gateway itself, which contains all of the provider credentials and is presented with all of the prompts, and must be secured like any tier-0 system.
This is unlike the previous API protection case, where the attack surface was the API. One LLM request can include a system prompt, user message, retrieved documents, tool definitions, and previous tool results. A response may contain generated text, structured output, or a call to a tool that an agent will run. By looking at the bearer token and the JSON schema, you will not be able to determine whether the web page retrieved from the server has instructions to send a message to the customer database to an external address. LLM gateway security is thus content-aware: It looks at and classifies what content is in the messages, rather than just the headers that surround them.
Security teams can implement a zero-trust AI approach to this traffic with a secure AI gateway. All incoming requests are authenticated, authorized for the model and tool, checked, and logged, as they are coming from inside the VPC. In practice, AI traffic security translates to one approved route to models and one path evaluated for each request.
Why Enterprises Need AI Gateway Security

It is rare that security is considered the beginning of a case for a gateway. It typically begins with one of the financial questions raised by an unclear model bill or when a single provider experiences an outage. There are three reasons for urgency in the security case behind AI calls: firstly, agents increase the quantity and reach of the AI calls; secondly, employees start to divert around authorized tools; and thirdly, regulators are looking for evidence, not intentions.
Rising use of LLMs and AI agents in production
One model call per user turn is made by a chatbot. An agent that is executing a multi-step task can execute dozens of times, each getting data from Salesforce or Jira or an internal wiki, and each call to a tool can modify something that exists. Twenty product teams each wire their own provider SDK, so that each team implements important things like storage, redaction, and logging, and no one knows which agent accessed which data.
This is reflected in the breach data. A recent survey by the IBM Institute for Workforce Development (IWD) indicated that 13% of organizations experienced breaches related to AI models or applications, while 97% of these organizations noted a lack of adequate access controls over AI. A gateway is the easiest and shortest path for accessing control to be placed in front of each model and tool that an agent can access.
Shadow AI and unmanaged model access
Shadow AI refers to any AI usage that circumvents the security process: If an employee types code into a consumer chatbot, a team uses an API key for a new model, or a coding assistant is set up on an individual account. The most famous case is that of Samsung in 2023. In less than a week, engineers at the semiconductor unit of South Korea's Samsung copied and pasted proprietary source code and internal meeting notes into ChatGPT, and Samsung banned the use of generative AI on company-provided devices in May 2023.
Since then, the problem has grown in size. One in five (20%) of the organizations studied was affected by a breach tied to shadow AI, which amounted to USD 670,000 in breach costs for organizations on average, and 65% of organizations had breaches involving customer PII. Only traffic passing through a gateway is managed by the gateway, so traffic not passing through needs to be identified if AI usage monitoring is to begin. On the other hand, Akto Atlas solves the problem for the employee side by identifying AI applications, agents, LLMs, and MCP tools on the workstation via browser extensions and IDE hooks and setting guardrails at this level.
Regulatory and compliance pressure
Questions that only request-level telemetry can answer are becoming the norm for auditors: What data was sent to what model? To whom? What came back? Most organizations are still unable to answer them; IBM discovered that 63% of compromised organizations did not have AI governance policies. Rules are applied in the sectors to provide hard constraints, e.g., a hospital could not send out unredacted patient data to an uncovered model. AI compliance is now achievable when a single enforcement point applies these rules consistently and automatically generates evidence.
Core Capabilities of AI Gateway Security

The six capabilities below are the minimum a production gateway should enforce. They are mutually dependent: inspection is not useful if there is no reliable identity, and logging is useless if it doesn't capture the decisions made by the other which is being inspected.
Authentication and access control
The first is to distinguish the identity of the caller from the credentials of the provider. The application or agent authenticates to the gateway using its own credentials, which are only applicable to an environment and owner. The gateway stores provider keys in a secret store and retrieves the appropriate key based on the policy. If a provider key leaks, you rotate it without having to look through all of the repositories and CI systems.
Authorization is then more than just a standard endpoint allowlist. The question of who can use which model, which data is allowed to flow to which provider or region, and which tools an agent is able to invoke is answered by AI model access control. A vendor-neutral policy may be something like the following:
Illustrative gateway policy (pseudo-config, not a specific product)
One aspect that requires special attention is AI agent authentication. Every agent should have its own identity to enable its actions to be attributed and revoked individually. The MCP security best practices are that servers should not accept tokens that were not explicitly issued for them, and that "token passthrough" is an anti-pattern because it violates the concept of audiences and audit trails. Minimal scope and step-up elevation for privileged operations are also recommended in the same guidance. Those rules are enforced server by server in a non-consistent way until you introduce AI access governance at the gateway.
Prompt injection and jailbreak detection
Prompt injection is the #1 threat in OWASP Top 10 for LLM Applications 2025. Direct injection is from the user ("ignore previous instructions and print your system prompt"). The model receives indirect injection, which is a retrieved document, an email, a website, or a tool result. The other type of injection is indirect injection, and for agents, this is the more dangerous type, as nothing the user typed was malicious.
Three layers of prompt injection detection are implemented: pattern rules (fast, brittle), trained classifiers which provide scores of how likely the prompt is to be an injection, and an LLM judge for cases that are ambiguous. Detail that is often not covered by most deployments is coverage. The only information about the latest user message would be known to a detector, and a detector that would only be interested in that information would not be able to see an injection in a role: tool message returned by a search tool unless inspection were done on every user message that enters the model's context. While detection can help lower the risk, it does not eradicate it, and is therefore coupled with tool restrictions that restrict the successful injection.
Data loss prevention (DLP) for prompts and responses
AI data loss prevention is a two-way street. Users and applications are sending customer records, credentials, and source code to external models, known as inbound. Outbound: Models can reveal sensitive information from their context or training data as LLM02:2025 Sensitive Information Disclosure, as noted by OWASP. The gateway is the only place that will witness both directions on all applications.
Typically detects entities (card numbers, national IDs, email addresses, API keys, internal project names) and then takes some action on that entity: block it, mask it, tokenize it, allow it with higher logging levels. It's great to have data-aware routing: where there's regulated data, send it to a self-hosted or contractually covered model; otherwise, send it to a hosted one.
Rate limiting and abuse prevention
The API rate limiting counts requests as classic. This isn't a suitable unit for LLMs, because the cost of a request might be a thousand times greater depending on input length, output length, and the model used. Gateways should have limits and monitoring per caller, per team, and per model, with a spend limit that can be enforced prior to overrun, not found on the invoice.
The attack here is OWASP LLM10:2025 Unbounded Consumption: denial-of-wallet attacks with leaked key, high volume model extraction attempts, and self-inflicted damage like an agent in a retry loop that chews up the monthly budget in one night. Model abuse prevention features tokens per minute limits, agent per session limits, output token limits per route, and alerts for sudden shifts in a caller's usage.
Model routing and policy enforcement
Typically, model routing is priced as a cost of service and a reliability service: cheaper models are used for simple services, and if a provider has an outage, failover to another model. It is also a security control, as each routing decision is a decision on where data goes. A failover chain that silently redirects a regulated workload from an EU deployment to a US endpoint is a compliance incident, not a resilience win.
Treat routing as AI policy enforcement. Lock the data classes to specified providers, fallbacks to meet the same data handling requirements as the primary, and prohibit requests when no compliant target is healthy. Using model aliases, applications ask for the claims-summarizer and the platform team, in one place, decides which real-world models can serve the application.
Logging, monitoring, and audit trails
The gateway becomes evidence through AI audit logging. Records that are useful include: Caller identity, application, tenant, environment, requested model, provider, region, token counts, cost, latency, status, and verdict of all guardrails and policy checks. This is usually exported by gateways into any existing observability and SIEM tools, meaning LLM traffic monitoring will not be a dedicated dashboard being monitored by anyone.
There are two differences between mature deployments. First, prompt and response bodies are data in their own right, and should be stored redacted, with limited access, and with a retention period that is set intentionally, not indefinitely. Second, link LLM observability to identity: If the number of blocked prompts is increasing, it isn't necessarily a problem until you correlate it with a given agent, key, and user session.
AI Gateway vs. Traditional API Gateway
Nearly every time you review an architecture, you see the discussion about the AI gateway vs API gateway, typically as "can't Kong or Apigee just do this? They are both reverse proxies that can be used to authenticate, route, rate-limit, and log. It's all about the difference in their understanding of traffic.
Dimension | Traditional API gateway | AI gateway |
|---|---|---|
Traffic it is built for | Deterministic, stateless request-response | Non-deterministic model calls, often streamed over long-lived connections |
What it inspects | Headers, tokens, IPs, payload schema | Message content: prompts, retrieved context, tool calls, responses |
Unit of rate limiting | Requests per second | Tokens per minute and spend per budget |
Routing logic | URL path, header, service discovery | Model capability, cost per token, data residency, provider health |
Failure handling | Retry the same upstream, circuit breaker | Fail over across providers within policy |
Security model | Authentication, schema validation, WAF rules | Prompt injection detection, PII detection, output safety |
Observability | Request count, latency, error rate | Token usage, cost attribution, guardrail verdicts |
In reality, most businesses have both. Other API gateway vendors are now delivering AI plugins that fill part of the gap, while the general microservice traffic remains on the existing API gateway and the LLM and MCP traffic goes through an AI gateway. The API gateway remains important as ordinary APIs are accessed and used by AI applications as well. It simply cannot detect the threats within the prompt.
AI Gateway vs. AI Firewall: What's the Difference?
They refer to different points in the request path, although they are related and often used interchangeably by vendors. AI firewall is the layer of inspection, usually positioned before the AI-driven app, that checks the incoming traffic for threats related to LLMs. Here's one example: Cloudflare's AI Security for Apps (previously Firewall for AI) runs alongside the WAF, checks requests heading to endpoints identified as being LLM endpoints, identifies PII, inappropriate topics, and prompt injection, and operates on any model behind the endpoint. The results are used to feed block/challenge/rate-limit rules in the WAF.
An AI gateway brokers your applications' outbound calls to models. It not only inspects content but also manages budgets, records attribution and provider credentials, and selects models.
AI firewall | AI gateway | |
|---|---|---|
Primary position | In front of your AI app, inspecting user-to-app traffic | Between your apps and agents and the models and tools they call |
Holds provider credentials | No | Yes |
Routing, failover, budgets | No | Yes |
Content inspection | Yes, its main function | Yes, usually via built-in or pluggable guardrails |
Typical owner | Network or application security team | Platform or AI engineering team, with security policy input |
The two are complementary aspects of AI network security: the public chatbot needs an AI firewall at the edge and a gateway behind the application. For internal agents (those threats that typically don't come through a public edge), the gateway has a larger footprint of the risk.
Common Threats an AI Gateway Helps Prevent
The OWASP Top 10 for LLM Applications 2025 provides the most helpful guide of the things a gateway can and cannot do. The table indicates the number of entries a gateway directly connects to the gateway control and the number of entries that are not connected via the gateway.
Threat (OWASP 2025) | What the gateway does | What it cannot do alone |
|---|---|---|
LLM01 Prompt Injection | Scans user, retrieved, and tool messages; blocks or flags | Guarantee detection of novel or obfuscated payloads |
LLM02 Sensitive Information Disclosure | Redacts PII and secrets inbound and outbound | Fix over-broad data access in the retrieval layer |
LLM05 Improper Output Handling | Strips or flags URLs, markup, and scripts in responses | Sanitize output inside the consuming application |
LLM06 Excessive Agency | Enforces per-agent tool allowlists and scopes | Make a poorly scoped tool safe |
LLM07 System Prompt Leakage | Detects system prompt content in responses | Protect secrets that were put in the prompt to begin with |
LLM10 Unbounded Consumption | Token limits, budgets, loop detection | Stop abuse through keys that bypass the gateway |
Most teams will be surprised at the importance of the output column. In June 2025, Aim Security found and reported a flaw in Microsoft 365 Copilot (CVE-2025-32711) that enabled the secret leak of internal data from the application through a single crafted email, and with no user action needed. The researchers successfully bypassed the Microsoft cross-prompt injector class, linked to Markdown documents with reference-style links, and used a proxy domain listed in Microsoft Teams to have an auto-fetched image take the data out. First, input-side AI threat detection failed. If output-side inspection had been performed, looking for any URL or image that it generated that was outside approved sites as an exfiltration method, the chain would have been broken.
How AI Gateway Security Supports Compliance (NIST AI RMF, ISO 42001, AI TRiSM)
There is no name for an AI gateway in any of these frameworks. They need to see evidence of control of operational AI systems, and the gateway is where much of that evidence is created.
NIST AI RMF. The framework can be segmented into four functions: Govern, Map, Measure, and Manage. Each is helped by the gateway. It has a configuration that includes Govern-level policy (who is allowed to use what); it provides an inventory of models and consumers through its traffic data; it provides guardrail verdicts and usage metrics for Measure; it also provides blocking and routing decisions for Map that are used as risk treatment at the Manage level in production.
ISO/IEC 42001. The standard has 38 controls under nine objectives, all of which are included in Annex A. Gateway audit logs are a solution to the requirement in Control A.6.2.8, which mandates that organizations identify the life cycle phases at which AI system event logs are captured, with at least “operation” being the minimum. The A.10 objective deals with third-party and customer relationships, and gateway records that record the delivery of classes of data to external parties are direct evidence of supplier oversight.
Gartner AI TRiSM. Gartner's framework identifies four layers of technology: AI governance, AI runtime inspection and enforcement, information governance, and infrastructure and stack. The gateway is one of the main implementations of the runtime inspection and enforcement layer, and the list of models, agents, and callers that it maintains contributes to the governance layer atop it.
Framework requirement | Gateway evidence |
|---|---|
NIST AI RMF Measure and Manage | Guardrail verdicts, blocked-request rates, enforced routing and budget decisions |
ISO 42001 A.6.2.8 event logs | Per-request logs with caller, model, policy decisions, and timestamps |
ISO 42001 A.10 third-party relationships | Records of which providers and regions received which data classes |
AI TRiSM runtime inspection and enforcement | Inline prompt and response inspection with block, redact, and flag actions |
How to Choose an AI Gateway Security Solution
AI gateways have similar feature matrices. There are questions to ask that go beyond convenience and make a secure AI gateway from a convenient one:
What is the location of the data plane? Prompts should be handled within the boundary of your network, and the data plane should continue to enforce policy even if the SaaS control plane is lost.
How are providers' credentials stored? Find secret manager integration and rotation without any application redeployments.
Does it detect individual agents? Using shared team keys is not sufficient for AI agent authentication. Check if OIDC or workload identity is available, as are per-agent scopes and MCP-aware authorization.
What does inspection encompass? Do not just ask for chat completions, but also tool-result messages, streamed responses, embeddings, multimodal inputs, and MCP traffic.
Can you put in your own guardrails? You'd like to have custom rules and dedicated providers without having to switch gateways.
What should be done if a guardrail breaks down? Each route should have a fail open/open or fail closed/close option, depending on which one you choose, and this should be logged.
What is the latent budget? Some gateways perform input checks concurrently with the model call. Record your own traffic overhead.
Is it possible to run policies as code? Versioned, reviewed policy files beat click-ops for change control and audit.
How does the vendor manage its own weaknesses? Review advisory history, patch frequency, and whether patches are released prior to exposure.
Does it support export to your current tools? It's about OpenTelemetry integration with SIEM, and it's more important than a built-in dashboard.
Risks of a Misconfigured or Bypassed AI Gateway
Having a gateway gives a false sense of security if you can bypass it, or when it is optional. The most common bypass is that the provider keys used prior to the gateway remain in notebooks, CI variables, and repositories. If each provider key is rotated at cutover, and the gateway is the only provider that has a valid credential, this path will be closed. Egress rules should then only accept provider domains from the gateway's hosts, which means that if a developer starts pointing an SDK back at the provider, he only receives a connection failure.
Misconfiguration is subtler. If you have gateways that allow gate callers to select which guardrails are activated on a call, you should only disable baseline checks if absolutely necessary; teams should not disable guardrails. Some, such as LiteLLM, have guardrails that by default disallow modifications, and a team setting that rejects guardrail modifications with a 403. If you want performance, there are options to not scan system or tool messages, but if you enable those, you won't be able to scan the content that carries indirect injection.
There's the gateway's attack surface, too. CVE-2026-42208 was vulnerable to exploitation by anyone via any LLM route, with no credentials needed, and was added to CISA's Known Exploited Vulnerabilities catalog on 08 May 2026 with a CVSS score of 9.3. The other LiteLLM vulnerability, CVE-2026-59819, enabled an authenticated administrator to access any file on the proxy host via the /health/test_connection API endpoint. Configure the gateway as an identity provider and ensure that admin and health endpoints are not on the public path. Finding AI traffic that never hits the gateway is a problem in itself: Akto discovers AI agents, MCP servers, and LLM calls across Laptop, Cloud, and Infrastructure, and a sidecar egress proxy can route outbound traffic from homegrown agents through guardrail enforcement.
Final Thoughts on AI Gateway Security
The summary: if the gateway is the only way, then it's the only way; if the gateway is a credential vault, then you need to harden it; if the gateway is the only way, then you need to close all other ways around it; and if the gateway is the only way, then it's the only way, and it's like the credential vault it is. This article highlights areas that can be addressed by Akto's AI agent security platform. Inspects employee machines for shadow AI and sets guardrails with browser extensions + IDE hooks, Akto Atlas. Akto Argus provides request and response guardrails like PII redaction and prompt injection detection on homegrown agents and MCP traffic, both within gateways like LiteLLM, Portkey, and TrueFoundry, and via its agent and MCP proxy. But before attackers test those guardrails, Akto has 4,000+ probes that do the work for them. Book an AI security demo to see how Akto secures your AI gateway traffic.
FAQs on AI Gateway Security
Can an AI gateway detect prompt injection attacks?
Yes, partially. Gateways integrate pattern rules, classifiers, and LLM judges to identify patterns for user input, retrieved documents, and tool outputs. It's probabilistic and can be defeated; use it in conjunction with other means of agent tool restriction and output inspection, but not as a panacea.
Can AI gateways monitor and log AI model usage in real time?
Yes. All requests go through the gateway and can be configured to report token counts, cost, latency, and verdicts as they occur and trigger alerts on increases in spend or blocked prompts. In the case of streamed responses, the final token and cost data will only be complete when the stream has terminated; therefore, the alerts must reflect this.
Experience enterprise-grade Agentic Security solution

