Ana içeriğe geç

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​

FieldTypeRequiredDefaultDescription
windowSecondsintegerNo60Sliding-window size, in seconds, over which repeats are counted. Must be positive.
maxRepeatsintegerNo5Repeat threshold within the window. Must be positive.
actionstringNoFLAGFLAG lets the request pass and records a guardrail hit for reporting. BLOCK rejects the request once the threshold is exceeded.
failOpenOnCacheErrorbooleanNotrueWhen the counter cache is unreachable: true lets the request pass unchecked; false rejects it.
anonymousHandlingstringNoSKIPBehaviour 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.
countingModestringNoALL_REQUESTSWhether 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.
limitChangeActionstringNoNONEWhat 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: MASK is not meaningful here

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​

HeaderValue
AuthorizationBearer {token}
Content-Typeapplication/json

Path Parameters​

ParameterTypeRequiredDescription
projectNamestringYesProject name
apiProxyNamestringYesAPI 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​

HeaderValue
AuthorizationBearer {token}
Content-Typeapplication/json

Path Parameters​

ParameterTypeRequiredDescription
projectNamestringYesProject name
apiProxyNamestringYesAPI Proxy name
policyNamestringYesPolicy 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​

CodeReason
400Blank name; windowSeconds not positive; maxRepeats not positive; proxy not found.
401Missing or invalid token.
403The 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​

HeaderValue
AuthorizationBearer {token}

Path Parameters​

ParameterTypeRequiredDescription
projectNamestringYesProject name
apiProxyNamestringYesAPI Proxy name
policyNamestringYesPolicy 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​

  • FLAG is the default action. A new policy only records guardrail hits for reporting until action is explicitly set to BLOCK.
  • 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_REQUESTS is the historical default. It counts rejected requests too, which slows down an abusive caller but can leave the counter sitting above the limit. Switch to ACCEPTED_ONLY when the count should reflect only traffic that actually reached the backend.
  • limitChangeAction only matters at the moment maxRepeats changes, 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: true lets traffic through when the counter cache is unreachable; set it to false for 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.