keys.verifyKey with no extra call, and users on a higher plan get a higher limit without a code change.
Create a root key with the permissions listed on this page under Root Keys in the dashboard sidebar. CLI commands can instead use a session from unkey login with the required permissions. See Permission reference for every permission.
Put the limit on the identity
A limit on a key applies to that key alone. A limit on an identity is shared by all the user’s keys. Create the identity with the limit, then create keys with the sameexternalId, and they’re linked automatically. autoApply: true checks the limit on every verification.
For the first call, your root key needs unkey:v1:<workspaceId>:projects/<projectId>/identities/*#write for the workspace’s default project. For the second call, it needs unkey:v1:<workspace_id>:projects/<project_id>/keyspaces/<keyspace_id>/keys/*#write. Use the keyspace’s project ID for the second call.
create the identity
create a key for that user
keys.verifyKey returns code: RATE_LIMITED when the shared limit is used up, and data.ratelimits has remaining and reset so you can send X-RateLimit-* headers.
verify and forward limit headers
identities.updateIdentity with a new ratelimits array (needs unkey:v1:{workspaceId}:projects/{projectId}/identities/{identityId}#write for the identity). It replaces the whole list, so send every limit the user should keep. All their keys pick up the change within about 10 seconds.
Alternative: the standalone ratelimit API
If you’re limiting something other than a key holder (a logged-in session, an IP address, a tenant), useratelimit.limit. The namespace names what you’re limiting, the identifier is the user, and you send the limit with each request. The response is always HTTP 200, so read data.success.
data.overrideId in the response shows when an override applied. The root key needs ratelimit.*.limit to check limits and unkey:v1:<workspace_id>:projects/<project_id>/ratelimits/namespaces/<namespace_id>/overrides/*#write to create overrides.
give one user a higher limit
Related
- Creating keys for the
externalIdandratelimitsfields. - Verifying keys for the
ratelimitsresponse entries. - Identities, standalone rate limiting, and overrides are documented under API Management.