Per-profile access control for AI agents at the API gateway layer
How to configure AI agent access control at the API gateway: dedicated clients, scoped collections, method restrictions, and per-agent rate limits in Zerq.
- ai-agents
- mcp
- access-control
- security
- governance
AI agent access control at the API gateway layer is the gap most teams discover after the fact. An autonomous agent ships to production using the same API key the developer used for testing. The key was never scoped to specific collections, never restricted to read-only methods, and never given a dedicated rate limit. Six weeks later, the agent calls a payment endpoint it was never intended to reach — not because it was compromised, but because its credential permitted it.
The problem is architectural. When your access control model does not distinguish agent identity from application or human identity, the agent inherits whatever permissions the credential carried. That is usually too much. Agents make many more calls than humans and follow patterns their operators did not anticipate. A broad credential gives a broad blast radius.
This guide covers how Zerq handles AI agent access control at the gateway layer: the client and profile model, collection scoping, method restrictions, per-client rate limits, and the request log entries that let compliance teams see exactly what the agent called and when. There is a full step-by-step setup sequence and a go-live checklist you can apply to any agent rollout.
Why existing approaches fail
The most common improvised solution is a shared API key — one credential used by the mobile app, the CI pipeline, and the AI agent because it was already working and convenient. Revocation becomes impossible without breaking all three consumers simultaneously. Rate limits apply to the key, not to the agent specifically. The request logs carry the key ID but not an identity that distinguishes the agent from the human developer using the same key. A compliance question like "what did the order-processing agent call last quarter?" becomes unanswerable because the logs cannot make that distinction.
A second approach is to add a dedicated proxy or MCP server alongside the existing API gateway, specifically for agent traffic. This doubles the operational surface, creates two audit trails that need to be reconciled during an incident, and means agents bypass the rate limits and access controls already in place on the main gateway. Kong, Apigee, AWS API Gateway, and Azure API Management can all log gateway traffic — but none of them have a first-class model for AI agent identity. The log entry identifies a credential or an IP, not an agent type and deployment environment.
The underlying issue is not tooling. Agent identity, collection scope, method restrictions, and rate limits need to be first-class concepts in the access model from the start.
The client and profile model for AI agents
Zerq's security model is built on two concepts that apply identically to apps, services, and AI agents: a client (who is calling) and a profile (how they are allowed to call). Every request to the gateway carries X-Client-ID and X-Profile-ID headers. There is no anonymous traffic and no way to use the gateway without an identity that can be scoped and audited.
For AI agents, the model works like this:
- One client per agent type and environment. A claims-processing agent in production is a different client than the same agent in staging. Different client IDs, different profiles, different rate limit policies.
- Collections assigned per client. The client can only call endpoints within its assigned collections. When the agent calls
list_collectionsvia MCP, it receives exactly the collections it was assigned — nothing else is visible. - Method restrictions per profile and per endpoint. A profile for an agent that calls REST directly can be restricted to
GETonly, blocking all writes at the gateway before the request reaches any backend. An agent on Gateway MCP keepsPOSTon its profile, because the MCP transport isPOST, and gets read-only access from collections whose endpoints publish onlyGET. - Rate limit policies per client. A dedicated policy with a tighter request budget than human traffic, applied specifically to the agent's client.
The practical result is that the agent's blast radius is defined at configuration time, not discovered after an incident.
Setting up a least-privilege agent client
The following setup creates a production AI agent client with read-only access to two collections and a 100 req/min rate limit.
Step 1: create the agent client
- Go to Clients in the management UI sidebar.
- Click New Client.
- Set Name to a descriptive identity — for example,
claims-processing-agent-prod. - Under Collections, select only the collections the agent needs. In this example:
claims-api-v2anddocument-store-v1. Leave all other collections unchecked. - Under Policy, select a policy with stricter limits than your human traffic. If one does not exist, create it first: go to Policies, click New Policy, and set Rate limit to
100max requests per1minterval and Quota to50000max requests per30d. Agents typically need tighter burst limits than humans because they retry aggressively. - Leave Developer Portal access disabled.
- Click Create.
Step 2: configure the profile
- Open the new client and go to Profiles.
- Click the default profile.
- Set Allowed Methods to
GETandPOST(the MCP transport isPOST; addDELETEonly if your client closes sessions). Read-only comes from assigning only read collections whose proxies publishGET. Start read-only; add write endpoints only after reviewing which ones the agent explicitly needs to modify. - If the agent runs in a fixed network location, enforce its egress range — for example,
10.8.0.0/24— at your ingress. Leave the profile's IP Restrictions empty, or include the backend address used to reachGATEWAY_BASE_URL. - Click Save.
- Copy the
X-Client-ID,X-Profile-ID, andAuthorization: Bearertoken values from the profile detail page and store them in a secrets manager. Viewer reads return credential metadata only; a user with the modifier role can reveal the stored token later, and that reveal is written to the audit log.
Step 3: set agent credentials
In the agent's environment or configuration:
# Environment variables passed to the agent process
ZERQ_GATEWAY_URL=https://gateway.example.com
ZERQ_MCP_PATH=/mcp
ZERQ_CLIENT_ID=66f1c2a9e4b0a1d2c3f40a11
ZERQ_PROFILE_ID=66f1c2b4e4b0a1d2c3f40a12
ZERQ_TOKEN=zerq_tok_xxxxxxxxxxxxxxxx
For MCP-compatible clients such as Claude or Cursor, the MCP server configuration block looks like this:
{
"mcpServers": {
"claims-gateway": {
"url": "https://gateway.example.com/mcp",
"headers": {
"X-Client-ID": "66f1c2a9e4b0a1d2c3f40a11",
"X-Profile-ID": "66f1c2b4e4b0a1d2c3f40a12",
"Authorization": "Bearer zerq_tok_xxxxxxxxxxxxxxxx"
}
}
}
}
Step 4: run a go-live verification
Before sending production traffic, run one allowed call and one expected-deny call:
# Initialize an MCP session
curl -s -X POST https://gateway.example.com/mcp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ZERQ_TOKEN" \
-H "X-Client-ID: $ZERQ_CLIENT_ID" \
-H "X-Profile-ID: $ZERQ_PROFILE_ID" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claims-agent","version":"1.0"}}}'
# Response header: Mcp-Session-Id: 7c41e09a2f6b4d83b5e1a0c9d47f2e68
# Allowed: list available tools (scoped to assigned collections)
curl -i https://gateway.example.com/mcp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ZERQ_TOKEN" \
-H "X-Client-ID: $ZERQ_CLIENT_ID" \
-H "X-Profile-ID: $ZERQ_PROFILE_ID" \
-H "Mcp-Session-Id: 7c41e09a2f6b4d83b5e1a0c9d47f2e68" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'
# Expect: 200 — returns list_collections, list_endpoints, endpoint_details, execute_endpoint
# Expected deny (REST check): POST to an endpoint that publishes only GET
curl -i -X POST https://gateway.example.com/claims/v2/claims \
-H "Authorization: Bearer $ZERQ_TOKEN" \
-H "X-Client-ID: $ZERQ_CLIENT_ID" \
-H "X-Profile-ID: $ZERQ_PROFILE_ID"
# Expect: 405 Method Not Allowed
Confirm the denied call appears in the request logs with the agent's client_id and profile_id on the entry before going to production. The request log records the gateway API calls, including every execute_endpoint call the agent makes once it is live.
What MCP discovery looks like with scoped access
The Gateway MCP exposes four tools: list_collections, list_endpoints, endpoint_details, and execute_endpoint. The collections and endpoints returned by the first two are scoped to what the client's profile can access. An agent assigned to claims-api-v2 and document-store-v1 cannot discover or call endpoints in payments-api-v3, because that collection is not assigned to its client. The discovery layer is access-controlled, not just execution.
The execute_endpoint tool runs through the same checks as any direct REST call, including the profile's allowed methods and each endpoint's own method list. An execute_endpoint call with POST against a GET-only endpoint returns 405 from the endpoint's method list. The MCP transport does not bypass gateway policy — it runs through the same enforcement path as a direct REST request. This is the practical benefit of running MCP on the same gateway as your REST traffic: access controls are defined once and enforced consistently, regardless of how the request arrives.
When the agent authenticates for an MCP session, the same headers apply as for any gateway client:
curl -X POST https://gateway.example.com/mcp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ZERQ_TOKEN" \
-H "X-Client-ID: 66f1c2a9e4b0a1d2c3f40a11" \
-H "X-Profile-ID: 66f1c2b4e4b0a1d2c3f40a12" \
-d '{
"jsonrpc": "2.0",
"method": "initialize",
"id": 1,
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": { "name": "claims-processing-agent", "version": "1.0" }
}
}'
The response includes an Mcp-Session-Id header. All subsequent tools/list and tools/call requests include that header alongside the same X-Client-ID and X-Profile-ID.
What the request log contains for every agent call
At the default log level, every API call the agent makes produces a structured request log entry in the same log store as all other gateway traffic. For a GET /claims/v2/claims?status=pending call from the agent, the log entry contains:
| Field | Value |
|---|---|
request_id | 4b8e2d61-9a3c-4f57-8e0b-1c6d5a72f394 |
created_at | 2026-06-22T09:14:23.441Z |
method | GET |
path | /claims/v2/claims |
status | 200 |
latency | 84 (milliseconds) |
client_id | 66f1c2a9e4b0a1d2c3f40a11 |
profile_id | 66f1c2b4e4b0a1d2c3f40a12 |
collection | 66f1a0c3e4b0a1d2c3f40a17 (the claims collection's ID) |
client_ip | 10.20.0.7 (the gateway's own address: execute_endpoint calls the gateway internally) |
Filter by client_id in the observability logs view to retrieve every request the agent made in a given window, across all endpoints. Set the status filter to 404, 405 and 403 in turn to see every blocked attempt: 404 for a path outside the agent's collections, 405 for a method its profile or the endpoint does not allow, and 403 for a REST call from outside a profile IP allowlist. A rising deny-rate on an agent client ID is the signal that the agent is attempting calls outside its defined scope — either a code change that needs review or an attempted scope expansion.
Denied calls are logged with the same identity fields as successful ones. The 404 or 405 entry carries the agent's client_id and profile_id, the path it attempted, and the timestamp. This is the record a compliance auditor needs when asking "did the agent ever try to reach endpoints it was not permitted to call?"
A checklist for AI agent access control
Before any AI agent goes to production:
- Dedicated client per agent type and environment (dev/staging/prod are separate clients, not separate profiles on the same client)
- Collections assigned: only the collections the agent needs, verified by reviewing the
list_collectionsresponse scoped to that client - Method restrictions set:
GETandPOSTon the profile for a Gateway MCP agent (GETonly for an agent that calls REST directly), with read-only enforced by assigning only collections whose endpoints publishGET; write endpoints added only after explicit review of which ones the agent requires - Rate limit policy attached: 100 req/min and 50,000 req per 30 days is a reasonable baseline for a read-heavy agent; adjust based on measured call frequency in staging
- Source range enforced if the agent runs in a fixed network location: at your ingress for a Gateway MCP agent, or in the profile's IP allowlist for an agent that calls REST directly
- Token rotation schedule documented: short-lived tokens preferred; rotation should not require the agent to be redeployed
- At least one deny test logged before rollout: a
404or405confirmed in the request logs with the agent's client ID on the entry - First-week request logs reviewed: confirm the actual access pattern matches the intended scope
Revisit this checklist whenever the agent gets a code update that could change which endpoints it calls.
What this looks like in practice
Illustrative scenario, not a specific customer deployment.
A financial services team running a policy-evaluation agent had the classic access creep problem. The agent had been given a credential matching their internal services, which meant it had write access to every endpoint those services used. The agent was read-only by design, but nothing enforced that at the gateway layer.
After creating a dedicated Zerq client with collection access limited to two read-only API collections whose endpoints publish only GET, and a profile allowing GET and POST for the MCP transport, the team ran a week of production traffic. The observability dashboard showed GET requests to four endpoints, consistent volume, no denies. When a code change in the agent accidentally added an execute_endpoint call with POST to /policies/v1/approvals, an endpoint the collection publishes for GET only, it returned 405 at the gateway, was logged with the agent's client_id, and was caught before it reached any backend. The runbook now includes the checklist above, verified before every production deployment.
Closing
Zerq's client and profile model gives AI agents the same access governance as every other consumer: scoped collection discovery, method restrictions, per-client rate limits, and a request log entry with agent identity on every call. See the full capabilities overview for additional controls available at the profile layer, including mTLS authentication and token rotation with an enforced expiry. For a public-sector example, see how agentic AI in UAE government applies this model to maker and checker boundaries and central agent monitoring. The access model is the same whether the consumer is a mobile app, a human operator, or an autonomous agent running overnight.
Zerq is an enterprise API gateway built for regulated industries — one platform for API management, AI agent access, compliance audit, and developer portal, running entirely in your own infrastructure. See how it works or request a demo to walk through your specific requirements.