Update policy
Update a single policy in place without resending the environment's full
policy list. The policy keeps its id and its position in the evaluation
order, and all other policies are untouched.
Omitted fields keep their stored values; at least one updatable field
must be provided. Setting match to null removes all match expressions
so the policy applies to every request. Providing one of keyauth,
ratelimit, firewall or openapi replaces the policy's rule
entirely, including switching its type; at most one may be set.
Policy ids are regenerated whenever gateway.setPolicies replaces the
list, so fetch current ids via gateway.listPolicies first.
Required Permissions
Your root key must have one of the following permissions:
environment.*.update_policy(for any environment)environment.<environment_id>.update_policy(for a specific environment)
Authorization
Body
application/jsonIdentifies a resource by either its unique ID or its slug.
Accepts a prefixed ID (such as 'proj_' or 'app_') or a slug.
Length: 3–255Pattern: ^[a-zA-Z0-9_-]+$
Identifies a resource by either its unique ID or its slug.
Accepts a prefixed ID (such as 'proj_' or 'app_') or a slug.
Length: 3–255Pattern: ^[a-zA-Z0-9_-]+$
Identifies a resource by either its unique ID or its slug.
Accepts a prefixed ID (such as 'proj_' or 'app_') or a slug.
Length: 3–255Pattern: ^[a-zA-Z0-9_-]+$
Id of the policy to update, as returned by gateway.listPolicies.
Ids are regenerated whenever gateway.setPolicies replaces the list,
so list the policies first if you are unsure the id is current.
Length: 1–512
Enable or disable the policy. Disabled policies are stored but skipped
during evaluation. Omit to keep the current setting.
Replaces all match expressions. Set null to remove them so the policy
applies to every request. Omit to keep the current expressions.
Items: max 10
Show child attributesHide child attributes
Show child attributesHide child attributes
exact, prefix or regex must be set.Show child attributesHide child attributes
Matches when the input satisfies this RE2 regular expression. Invalid
patterns are rejected when the policy is created.
Length: 1–1024
Show child attributesHide child attributes
Items: min 1
Matches a named request field (header or query parameter). Exactly one of
present or value must be set.
Show child attributesHide child attributes
Length: 1–256
exact, prefix or regex must be set.Show child attributesHide child attributes
Matches when the input satisfies this RE2 regular expression. Invalid
patterns are rejected when the policy is created.
Length: 1–1024
Matches a named request field (header or query parameter). Exactly one of
present or value must be set.
Show child attributesHide child attributes
Length: 1–256
exact, prefix or regex must be set.Show child attributesHide child attributes
Matches when the input satisfies this RE2 regular expression. Invalid
patterns are rejected when the policy is created.
Length: 1–1024
Show child attributesHide child attributes
Keyspaces to verify keys against, referenced by id. All keyspaces must
belong to your workspace.
Items: 1–5
Where to look for the key on incoming requests, tried in order. Defaults
to the Authorization Bearer header when omitted.
Show child attributesHide child attributes
Authorization Bearer header.Optional permission query the verified key must satisfy, e.g.
documents.read AND documents.write.
Length: max 1000
Items: max 10
Show child attributesHide child attributes
Name of a rate limit configured on the key or its identity, or the name
of the inline override defined by limit and duration.
Length: 1–256
Inline override: maximum number of operations per window. Must be set
together with duration.
Range: >= 1
Inline override: window duration in milliseconds. Must be set together
with limit.
Range: >= 1
Usage credits a matching request deducts from the verified key. Defaults
to 1. Set to 0 to verify the key without spending credits, or to a higher
value to charge more per request. Keys with unlimited usage are
unaffected.
Range: >= 0
Rate limits matching requests. Set identifiers with 1 to 5 sources.
The deprecated identifier field is accepted in place of a one-entry
identifiers list; set exactly one of the two.
Show child attributesHide child attributes
How requests are grouped for rate limiting. Exactly one of remoteIp,
header, authenticatedSubject, path or principalField must be set.
Show child attributesHide child attributes
Show child attributesHide child attributes
Length: 1–256
Ordered list of sources that form a compound rate limit key. The
gateway resolves each source for each request. Each unique
combination of resolved values has its own counter. All counters use
the same limit and window. Example: [authenticatedSubject, path]
limits each subject separately on each path.
Items: 1–5
Show child attributesHide child attributes
Show child attributesHide child attributes
Length: 1–256
Show child attributesHide child attributes
Validates matching requests against the app's uploaded OpenAPI spec. Has no
configuration of its own. If no spec has been uploaded for the deployment,
the policy is a no-op and requests pass through unvalidated.
Adds request data to the log entries of matching requests. The gateway
always records a basic log entry for every request: method, host, path,
status, and latency. Each capture setting is a separate opt-in: request
headers, response headers, request body, response body, and query data.
The policy's match expressions select the requests. A policy without
match expressions matches every request. If more than one enabled
logging policy matches a request, the gateway combines their settings.
The gateway always redacts the Authorization header and configured key
locations before it stores headers or query data.
Show child attributesHide child attributes
Capture request headers, the user agent, and the client IP. The user
agent and client IP are included because they identify the client.
Default: false
Capture the query string and query parameters. Query data is a
separate opt-in because URLs can contain secrets, for example
?api_key=....
Default: false
Responses
requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).Show child attributesHide child attributes
JSON path indicating exactly where in the request the error occurred. This helps pinpoint the problematic field or parameter. Examples include:
- 'body.name' (field in request body)
- 'body.items[3].tags' (nested array element)
- 'path.apiId' (path parameter)
- 'query.limit' (query parameter)
Use this location to identify exactly which part of your request needs correction.
requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).