Generate Rate Limit (AI)

POST /v1/firewall/rate-limits/generate

Translate a natural-language intent ("100 requests per minute per IP, return 429 with a friendly message") into a draft rate-limit rule. Returns a single rule the dashboard pre-fills into the create form, or you can POST it to /firewall/rate-limits.

Plan-gated: requires the custom_rate_limits entitlement.

Conditions on the returned rule follow the same shape as a hand-authored rate limit (type / operator / value / logical_operator), so the response is interchangeable with the form output.

Request body

description string Req
Free-form description. Naming the path, method, key scope, and limit yields the cleanest output ("1000 req/min per API key on POST /v1/api/*" beats "limit my API").

Response (200 OK)

name string
Short rule name.
requests_per_window int
Cap value (e.g. 1000).
window_size_seconds int
Sliding-window size in seconds. AI translates "per minute" → 60, "per hour" → 3600.
action string
block (returns 429) or throttle (delays subsequent requests). Defaults to block.
conditions[] array
List of {type, operator, value, logical_operator}. Same vocabulary as firewall conditions — path, method, country, header, user_agent, source_ip, etc.

Errors

200 with error body
Returns {"error":"..."} when the intent is an edit (disable/delete/rename — use the chat widget) or doesn't translate to a rate-limit rule.
400 / 401 / 403
Unreadable body / missing auth / plan doesn't include custom_rate_limits.
502 / 503
AI gateway unreachable (502) or not configured (503). Other upstream AI errors (e.g. provider rate-limit) surface with the gateway's status code and an {"error":"..."} body.
Request
curl -X POST "https://api.ngris.com/v1/firewall/rate-limits/generate" \ -H "X-API-KEY: <your_api_key>" \ -H "Content-Type: application/json" \ -d '{ "description": "100 requests per minute per IP on POST /v1/login" }'
Response — 200 OK
{ "name": "Login rate limit", "requests_per_window": 100, "window_size_seconds": 60, "action": "block", "conditions": [ {"type": "method", "operator": "equals", "value": "POST", "logical_operator": "AND"}, {"type": "path", "operator": "equals", "value": "/login", "logical_operator": "AND"} ] }
Iris