AgentCop

Guide · AI agents and their model traffic · Sources read on 2 December 2026

AI gateway, and what it can check on an agent.

Short answer. An AI gateway is a service between your apps or agents and the model providers they call. Everything goes through one endpoint, where the gateway routes each request, keeps the provider keys, counts tokens and cost, and logs the exchange. On an AI agent it can do one more thing: every tool list, every tool result and every tool call the model asks for passes through it, so it is the last point where a risky call can be held before the agent runs it. Pointing an agent at a gateway takes two settings, a base URL and a key.

What is an AI gateway?

An AI gateway is a reverse proxy for model traffic. Your app or agent sends its request to the gateway's URL instead of the provider's. The gateway forwards it to the provider, receives the answer, and passes it back, streaming included. Because every call crosses it, the gateway is where you put the things you want once for all your apps: keys, limits, logs and checks.

"AI gateway", "LLM gateway" and "LLM proxy" name the same position in the request path. Some vendors use "AI gateway" for a wider scope that also covers tools and MCP servers. Search interest moved fast in 2026: US searches for "what is an ai gateway" went from about 50 a month to about 720 between November 2025 and October 2026, as agents moved from demos to production.

What does an AI gateway do?

Most gateways combine some of these six jobs. The first four are about operations; the last two are about what the model reads and what the agent does.

JobWhat the gateway doesWhen it matters
One endpoint, many modelsApps call one URL; the gateway routes each request to the right provider and model, and fails over when one is down.Teams with several providers or a model switch planned.
Keys kept in one placeApps get a gateway key; the real provider keys stay with the gateway and can be rotated without touching the apps.Any agent that runs on a laptop, a CI runner or a customer machine.
Token limits and budgetsLimits counted in tokens and money per app, team or agent, not only in requests per second.Loops and runaway agents: OWASP LLM10 calls the bill shock "Denial of Wallet".
Logs and auditEvery request and response recorded with who sent it, which model answered, tokens and latency.Incident review, compliance, cost attribution.
Content checksInputs and outputs scanned for prompt injection, secrets, personal data or banned topics.Chat apps and agents that read outside text.
Tool call checksEach tool call the model asks for is judged before the agent runs it: allowed, flagged, or held.Agents with tools that write, send, pay or delete.

Two OWASP risks line up with these jobs. LLM10:2025, Unbounded Consumption, lists rate limiting, user quotas, timeouts and monitoring among its mitigations, all of which a gateway can enforce in one place. LLM06:2025, Excessive Agency, covers damaging actions taken on "unexpected, ambiguous or manipulated outputs"; its mitigations include requiring user approval and complete mediation, which on an agent means a check on each tool call.

How is an AI gateway different from an API gateway or an MCP gateway?

The four sit in different places, count different things and read different parts of the traffic.

ControlWhere it sitsWhat it countsWhat it seesWhat it can stop
API gatewayIn front of your own APIsRequestsHTTP paths, headers, payload sizeUnauthenticated calls, request floods
AI gateway (LLM gateway, LLM proxy)Between apps or agents and model providersTokens and costPrompts, tool lists, tool results, model answers, tool callsLeaked keys, runaway spend, unsafe tool calls before they run
MCP gatewayBetween an agent and its MCP serversTool invocationsTool lists and tool calls on the MCP sideUnapproved servers or tools, calls outside policy
Network firewallAt the network edgeConnectionsAddresses and ports, not the promptTraffic to destinations you never allowed

An AI gateway and an MCP gateway overlap on tool calls but see them from opposite sides. The AI gateway sees the call when the model asks for it, along with the conversation that led to it. The MCP gateway sees the call when the agent sends it to a server, without the prompt or the tool result that triggered it. An agent that uses local tools, a shell or plain HTTP calls never goes through an MCP gateway at all; its tool calls still come back through the model response.

What does an AI gateway see when an agent calls tools?

An agent works in a loop: it sends the conversation and its tool list to the model, the model answers with one or more tool calls, the agent runs them, and sends the results back with the next request. Every turn of that loop crosses the gateway.

Part of the exchangeIn theWhy a check there matters
System prompt and user messageRequestThe agent's mission, which later calls can be compared against.
Tool list, with each description and schemaRequestWhere tool poisoning hides: orders inside a description the user never reads.
Earlier tool results (emails, pages, files, tickets)RequestWhere indirect prompt injection arrives: orders inside the data the agent fetched.
Tool calls the model asks for, with argumentsResponseThe last point where a send, a delete or a payment can be held before the agent runs it.
Text the model writes backResponseSecrets or personal data on their way to a user, a log or a URL.

The MCP specification shows the same path: the client calls the tool, then the result goes to the model to be processed, and clients should "validate tool results before passing to LLM". The spec also says clients must treat tool annotations as untrusted unless the server is trusted, so a tool marked read-only still needs its calls checked.

Three things stay outside a gateway's view. It does not see what a tool does on its own side, such as a request an MCP server makes without the model. It does not see commands the agent runs without a model asking for them. And it sees a tool call before it runs, not its effect, until the result comes back in the next request. That is why a gateway works alongside a sandbox and narrow tool permissions, not in place of them.

Our 13 prompt injection examples show what this looks like in practice: the orders arrive inside emails, pages and tool descriptions, and the damage happens in the tool call that follows. Both pass through the gateway.

How do you point an AI agent at a gateway?

Two settings change: the base URL the SDK or agent calls, and the key it sends. The agent's code stays as it is. The values below are placeholders; your gateway gives you the real ones.

Any app on the OpenAI SDK. The Python client takes a base_url argument or reads the OPENAI_BASE_URL environment variable.

shellOpenAI SDK, Python or Node
export OPENAI_BASE_URL="https://gateway.example.com/v1"
export OPENAI_API_KEY="<gateway key>"

Claude Code. Set ANTHROPIC_BASE_URL, and pass the gateway credential with ANTHROPIC_AUTH_TOKEN (sent as a Bearer token) or ANTHROPIC_API_KEY (sent as x-api-key). Setting the base URL alone, without a gateway credential, does not replace a subscription login. The same variables can go in the env block of a user settings file, where they win over shell exports; Claude Code's docs say to keep the credential out of a project's .claude/settings.json. /status shows which base URL is in use. The desktop app reads its own third-party inference configuration instead.

shellClaude Code CLI
export ANTHROPIC_BASE_URL="https://gateway.example.com"
export ANTHROPIC_AUTH_TOKEN="<gateway key>"

n8n. In the OpenAI credential used by the AI Agent's chat model, set Base URL to the gateway and the API key to the gateway key, and turn off "Use Responses API" if the gateway only handles Chat Completions. Steps and a test are in n8n security.

Codex. Declare a model provider in config.toml with its base_url and the environment variable that holds the key, then select it.

~/.codex/config.tomlcustom model provider
model_provider = "gateway"

[model_providers.gateway]
name = "Gateway"
base_url = "https://gateway.example.com/v1"
env_key = "GATEWAY_API_KEY"

Then send one real task, with a tool call, and confirm in the gateway's log that the request arrived, the stream came back whole, and the tool call was recorded. A hello-world request proves the URL works, not that tools and streaming do. For locking down Claude Code itself, see Claude Code security; for Codex, the Codex sandbox guide.

What should you check before choosing an AI gateway?

Feature lists look alike. These eight checks separate a gateway that fits agents from one built for chat traffic.

CheckWhy it matters on agents
What happens when it is downA gateway that fails closed stops your agents; one that fails open lets them run unchecked. Pick per agent, and know which one you have.
Streaming passes through untouchedClaude Code's gateway protocol says a gateway that buffers a response until it is complete stalls it, and stripped ping events trip its idle timeout.
Headers and error bodies forwarded as they areClaude Code asks gateways to forward anthropic-beta and anthropic-version verbatim and to return upstream errors unmodified, since retries match on their wording.
The API formats your agents speakChat Completions, the Responses API and Anthropic Messages are three different wire formats. A gateway that translates between them can drop fields a new model needs, and one that passes an unknown format through unchecked leaves a hole.
Tool calls judged wholeIn a stream, a tool call arrives in fragments. A check that reads fragments sees half an argument; the gateway has to hold the call until it is complete.
Limits per agent, not per addressTen agents behind one office NAT share an IP. A per-address limit throttles all of them for the one that loops.
Where logs live and what they keepA gateway stores every prompt and tool result. Ask for the region, the retention, and whether secrets are masked before storage.
Latency added per callMeasure it on your own traffic, streaming and tool calls included, not on a hello-world request.

The limit check comes from our own traffic. Until 2 December 2026 Cop online limited requests per IP address, so an office of agents behind one NAT shared a single counter. It now counts per agent key, 20 requests a second with bursts of 120; two agents on one address sending 100 calls each at once now pass 200 out of 200.

Where does Cop fit?

Cop is an AI gateway built for one job: keeping an agent on its mission. Your agent's base URL and key point at Cop, which forwards OpenAI Chat Completions and Anthropic Messages to the provider as they are, streaming included, without translating formats. A model endpoint Cop does not check yet, such as the Responses API, is refused with a clear error instead of passing unchecked. It works with OpenAI, Anthropic, OpenRouter, Azure OpenAI and other OpenAI-compatible endpoints. The agent receives a cop- key that only works through Cop; the real provider key is stored encrypted.

On each exchange, 139 rules mapped to MITRE ATLAS techniques and OWASP IDs read the tool list, the tool results and the tool calls, each call held until it is complete. Behavior analysis learns each agent's usual tools and destinations and flags drift. In Audit mode every call passes and findings are logged and emailed; in Blocking mode a high or critical call waits until you release it. Pointed straight at Cop online, an agent has no model while Cop is unreachable (fail-closed). Through the open-source relay on GitHub, the agent keeps its provider key, keeps running if our API does not answer, and the console says so (fail-open). In our tests of 30 November and 1 December 2026, calls were judged in 61 to 430 milliseconds.

AI gateway questions.

What is an AI gateway?

An AI gateway is a service that sits between applications or AI agents and the model providers they call. Every request goes through one endpoint, where the gateway routes it to a model, keeps the provider keys, counts tokens and cost, logs the exchange and can check what goes in and out, including the tool calls an agent asks for.

What is the difference between an AI gateway and an API gateway?

An API gateway protects your own APIs and counts requests. An AI gateway sits in front of model providers and counts tokens and cost, the unit providers bill on. It also reads the content of each exchange: prompts, tool lists, tool results and the tool calls the model returns, which an API gateway treats as opaque payload.

Is an LLM gateway the same as an AI gateway?

In practice, yes. "AI gateway", "LLM gateway" and "LLM proxy" all name a service between an app and its model providers. Some vendors reserve "LLM gateway" for routing language models and use "AI gateway" for a wider scope that includes tools and MCP servers, but the request path is the same.

Do I need an AI gateway?

One app calling one provider with a key on a server can do without. A gateway pays off when you run several agents or providers, when keys sit on laptops or customer machines, when you need one log of every model call, or when an agent has tools that write, send, pay or delete and you want each call checked before it runs.

Can an AI gateway stop prompt injection?

It can catch a large part of it, because the tool results and tool descriptions where injected orders hide pass through the gateway, and so do the tool calls that follow. It cannot see what a tool does on its own side, so it works with narrow tool permissions and a sandbox, not instead of them.

Does an AI gateway add latency?

Yes, by one extra network hop plus any checks it runs. Routing alone adds little; content and tool call checks add more. In our own tests in late 2026, Cop judged calls in 61 to 430 milliseconds. Measure on your own traffic, with streaming and tool calls.

Sources