Check and enforce rate limits for any identifier (user ID, IP address, API client, etc.).
Use this for rate limiting beyond API keys - limit users by ID, IPs by address, or any custom identifier. Supports namespace organization, variable costs, and custom overrides.
Response Codes: Rate limit checks return HTTP 200 regardless of whether the limit is exceeded - check the success field in the response to determine if the request should be allowed. 4xx responses indicate auth, namespace existence/deletion, or validation errors (e.g., 410 Gone for deleted namespaces). 5xx responses indicate server errors.
Required Permissions
Your root key must have one of the following permissions:
ratelimit.*.limit (to check limits in any namespace)ratelimit.<namespace_id>.limit (to check limits in a specific namespace)Unkey uses API keys (root keys) for authentication. These keys authorize access to management operations in the API. To authenticate, include your root key in the Authorization header of each request:
Authorization: Bearer unkey_123Root keys have specific permissions attached to them, controlling what operations they can perform. Key permissions follow a hierarchical structure with patterns like resource.resource_id.action (e.g., apis.*.create_key, apis.*.read_api).
Security best practices:
The id or name of the namespace.
1 - 255"sms.sign_up"
Sets the rate limit window duration in milliseconds after which the counter resets. Shorter durations enable faster recovery but may be less effective against sustained abuse. Common values include 60000 (1 minute), 3600000 (1 hour), and 86400000 (24 hours). Balance user experience with protection needs when choosing window sizes.
1000 <= x <= 259200000060000
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. Accepts letters, numbers, underscores, dots, colons, slashes, and hyphens for flexible identifier formats. 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 - 255"user_12345"
Sets the maximum operations allowed within the duration window before requests are rejected.
When this limit is reached, subsequent requests fail with RATE_LIMITED until the window resets.
Balance user experience with resource protection when setting limits for different user tiers.
Consider system capacity, business requirements, and fair usage policies in limit determination.
1 <= x <= 10000001000
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. When accumulated cost exceeds the limit within the duration window, subsequent requests are rejected. Essential for implementing fair usage policies and preventing resource abuse through expensive operations.
0 <= x <= 10005
Rate limit check completed successfully. Check the success field to determine if the request is allowed.