Apply rate limiting
Check and enforce a rate limit for any identifier (user ID, IP address, API client, etc.).
Usage decays continuously instead of resetting at window edges: after one duration, about 37% of it still counts. Durations must be at least 10000 milliseconds (10 seconds) and at most 86400000 milliseconds (24 hours).
Response Codes: Rate limit checks return HTTP 200 regardless of whether the limit is exceeded. Check the allowed field in the response to determine if the request should proceed. A 429 may be returned if the workspace exceeds its API rate limit. Other 4xx responses indicate auth, namespace deletion, or validation errors (e.g., 410 Gone for deleted namespaces). 5xx responses indicate server errors.
Required Permissions
Your root key must have unkey:v1:<workspace_id>:projects/<project_id>/ratelimits/namespaces/<namespace_id>#limit. Use * for the namespace ID to cover all namespaces in a project.
To create a missing namespace automatically, your root key must also have unkey:v1:<workspace_id>:projects/<project_id>/ratelimits/namespaces/*#write for the workspace’s default project.
Authorizations
Unkey uses bearer tokens for authentication. Public integrations use root keys, while the dashboard proxy uses short-lived JWTs. To authenticate, include the token in the Authorization header of each request:
Root keys have specific permissions attached to them, controlling what operations they can perform. Resource permissions use Unkey Resource Names plus actions, like unkey:v1:ws_123:projects/*/keyspaces/*/keys/*#write.
Security best practices:
- Keep root keys secure and never expose them in client-side code
- Use different root keys for different environments
- Rotate keys periodically, especially after team member departures
- Create keys with minimal necessary permissions following least privilege principle
- Monitor key usage with audit logs.
Body
Sets the rate limit duration in milliseconds. It must be at least 10000 (10 seconds) and at most 86400000 (24 hours). Common values include 10000 (10 seconds), 60000 (1 minute), 3600000 (1 hour), and 86400000 (24 hours).
10000 <= x <= 8640000060000
Defines the scope of rate limiting by identifying the entity being limited. Use user IDs for per-user limits, IP addresses for anonymous limiting, or API key IDs for per-key limits. The same identifier can be used across different namespaces to apply multiple rate limit types. Choose identifiers that provide appropriate granularity for your rate limiting strategy.
1 - 512"user_12345"
Sets how much of the rate limit quota this request consumes, enabling weighted rate limiting.
Use higher values for resource-intensive operations and 0 for tracking without limiting.
A cost greater than the limit that applies, including the limit of a matching override, never fits: the check is denied and retryAfter is one duration.
0 <= x <= 90071992547409915
Configure when this check persists its cost.
IF_ALLOWED: counts the cost only if it fits.ALWAYS: counts the cost even if it does not fit, such as for usage that already happened.NEVER: counts nothing and only reports whether the cost fits. This is the same behavior as setting a cost of 0.
IF_ALLOWED, ALWAYS, NEVER "IF_ALLOWED"
Response
Rate limit check completed successfully. Check the allowed field to determine if the request may proceed.