AI Loop Guard Policy
General Information
Policy Type
ai-loop-guard
Endpoints
List Policies
GET /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/
Add Policy
POST /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
Update Policy
PUT /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
Delete Policy
DELETE /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
How Detection Works
The policy builds an isolation key from the model, the API proxy, the caller's identity and the exact request body, and atomically increments a sliding-window counter for that key. If the same request is seen more than maxRepeats times within windowSeconds, the configured action applies.
This is distinct from the Semantic Cache Policy (which serves cached answers for cost, and never blocks) and from content-based guardrails (which inspect what the request says, not how often it repeats).
Fields
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| windowSeconds | integer | No | 60 | Sliding-window size, in seconds, over which repeats are counted. Must be positive. |
| maxRepeats | integer | No | 5 | Repeat threshold within the window. Must be positive. |
| action | string | No | FLAG | FLAG lets the request pass and records a guardrail hit for reporting. BLOCK rejects the request once the threshold is exceeded. |
| failOpenOnCacheError | boolean | No | true | When the counter cache is unreachable: true lets the request pass unchecked; false rejects it. |
| anonymousHandling | string | No | SKIP | Behaviour when the caller's identity cannot be resolved. SKIP bypasses the guard for that request. SHARED_POOL counts anonymous traffic in one shared counter (no per-caller isolation). DENY rejects the request with HTTP 401. |
| countingMode | string | No | ALL_REQUESTS | Whether a request that was itself rejected by this guard still counts toward the window. ALL_REQUESTS counts every request, including rejected ones — the historical, backward-compatible behaviour, useful for slowing down an abusive caller. ACCEPTED_ONLY counts only requests that were let through, which keeps the counter from overshooting the limit once it is already at capacity. |
| limitChangeAction | string | No | NONE | What happens to an already-open window's counter when maxRepeats changes on a redeploy. NONE leaves the counter untouched — the new limit takes effect only once the current window ends. CLAMP caps the counter to the previous limit, preserving real consumption without resetting it. RESET zeroes the counter, and only ever applies when the limit was raised. |
action accepts the same three values as other AI guardrails, but MASK has nothing to redact in a traffic-shape check — any non-BLOCK value is treated as FLAG.
List Policies
Endpoint
GET /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/
Request
Headers
| Header | Value |
|---|---|
| Authorization | Bearer {token} |
| Content-Type | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name |
| apiProxyName | string | Yes | API Proxy name |
Response
Success Response (200 OK)
{
"status": "SUCCESS",
"resultList": [
{
"apiProxy": {
"name": "MyAiProxy",
"requestPolicyList": [
{
"type": "ai-loop-guard",
"name": "agent-retry-guard",
"description": "Stop a stuck agent from replaying the same tool call",
"active": true,
"windowSeconds": 60,
"maxRepeats": 5,
"action": "BLOCK",
"failOpenOnCacheError": true,
"anonymousHandling": "SKIP",
"countingMode": "ALL_REQUESTS",
"limitChangeAction": "NONE"
}
],
"responsePolicyList": [],
"errorPolicyList": []
}
}
],
"resultCount": 1
}
cURL Example
curl -X GET \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAiProxy/policies/" \
-H "Authorization: Bearer YOUR_TOKEN"
Add Policy
Endpoint
POST /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
Request
Headers
| Header | Value |
|---|---|
| Authorization | Bearer {token} |
| Content-Type | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name |
| apiProxyName | string | Yes | API Proxy name |
| policyName | string | Yes | Policy name |
Request Body
Full JSON Body Example
{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "ai-loop-guard",
"description": "Stop a stuck agent from replaying the same tool call",
"active": true,
"windowSeconds": 60,
"maxRepeats": 5,
"action": "BLOCK",
"failOpenOnCacheError": true,
"anonymousHandling": "SKIP",
"countingMode": "ACCEPTED_ONLY",
"limitChangeAction": "CLAMP"
}
}
Request Body Fields
See Fields above. type (ai-loop-guard), description and active follow the common policy contract; name comes from the path parameter.
Response
Success Response (200 OK)
{
"status": "SUCCESS",
"deploymentResult": {
"success": true,
"deploymentResults": [
{
"environmentName": "production",
"success": true,
"message": "Deployment successful"
}
]
}
}
Error Responses
| Code | Reason |
|---|---|
| 400 | Blank name; windowSeconds not positive; maxRepeats not positive; proxy not found. |
| 401 | Missing or invalid token. |
| 403 | The token's account lacks permission on the project. |
cURL Example
curl -X POST \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAiProxy/policies/agent-retry-guard/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "ai-loop-guard",
"description": "Stop a stuck agent from replaying the same tool call",
"active": true,
"windowSeconds": 60,
"maxRepeats": 5,
"action": "BLOCK"
}
}'
Update Policy
Endpoint
PUT /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
Request
The body is the same shape as Add Policy. The update replaces the policy, so send the fields you want to keep.
Full JSON Body Example — Tightening the Threshold
{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "ai-loop-guard",
"description": "Stop a stuck agent from replaying the same tool call",
"active": true,
"windowSeconds": 30,
"maxRepeats": 3,
"action": "BLOCK",
"limitChangeAction": "CLAMP"
}
}
Response
Success Response (200 OK)
{
"status": "SUCCESS",
"deploymentResult": {
"success": true,
"deploymentResults": [
{
"environmentName": "production",
"success": true,
"message": "Deployment successful"
}
]
}
}
cURL Example
curl -X PUT \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAiProxy/policies/agent-retry-guard/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"]
},
"policy": {
"type": "ai-loop-guard",
"active": true,
"windowSeconds": 30,
"maxRepeats": 3,
"action": "BLOCK"
}
}'
Delete Policy
Endpoint
DELETE /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
Request
Headers
| Header | Value |
|---|---|
| Authorization | Bearer {token} |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name |
| apiProxyName | string | Yes | API Proxy name |
| policyName | string | Yes | Policy name |
Response
Success Response (200 OK)
{
"status": "SUCCESS"
}
cURL Example
curl -X DELETE \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAiProxy/policies/agent-retry-guard/" \
-H "Authorization: Bearer YOUR_TOKEN"
Notes and Warnings
FLAGis the default action. A new policy only records guardrail hits for reporting untilactionis explicitly set toBLOCK.- Runs at the model decision in routing. The loop guard runs once in the routing stage, after the provider and model are resolved and the model access list has let the caller through, in the order of the policy chain. It never runs with a guessed model. In the request pipeline and in the timing view it appears as skipped with the reason
Deferred to the model decision in routing; the real execution is a second record in routing. MCP and A2A proxies are not affected. countingMode: ALL_REQUESTSis the historical default. It counts rejected requests too, which slows down an abusive caller but can leave the counter sitting above the limit. Switch toACCEPTED_ONLYwhen the count should reflect only traffic that actually reached the backend.limitChangeActiononly matters at the momentmaxRepeatschanges, and only for a window that is already open — it has no effect on every request, only on the redeploy that changes the limit.- Fail-open by default.
failOpenOnCacheError: truelets traffic through when the counter cache is unreachable; set it tofalsefor a fail-closed posture where an unverifiable request is rejected instead. - Anonymous traffic is skipped by default. With
anonymousHandling: SKIP, requests whose identity cannot be resolved bypass the guard silently. The policy runs at the model decision in routing, after authentication, so it always sees the caller that the authentication policy resolved.