Verify API key
Verify an API key's validity and permissions for request authentication.
Use this endpoint on every incoming request to your protected resources. It checks key validity, permissions, rate limits, and usage quotas in a single call.
Important: Returns HTTP 200 for all verification outcomes — check the valid field in response data to determine if the key is authorized. A 429 may be returned if the workspace exceeds its API rate limit.
Common use cases:
- Authenticate API requests before processing
- Enforce permission-based access control
- Track usage and apply rate limits
Required Permissions
Your credential needs one of:
api.*.verify_key(verify keys in any API)api.<api_id>.verify_key(verify keys in specific API)unkey:v1:<workspace_id>:keyspaces/*/keys/*#verify_key(verify keys in any keyspace)unkey:v1:<workspace_id>:keyspaces/<keyspace_id>/keys/*#verify_key(verify keys in a specific keyspace)unkey:v1:<workspace_id>:keyspaces/<keyspace_id>/keys/<key_id>#verify_key(verify a specific key)
Note: If your credential has no verify permissions at all, you will receive a 403 Forbidden error. If your credential has verify permissions for a different API or keyspace than the key you're verifying, you will receive a 200 response with code: NOT_FOUND to avoid leaking key existence.
Authorization
Body
application/jsonThe API key to verify, exactly as provided by your user.
Include any prefix - even small changes will cause verification to fail.
Length: 1–512
Checks if the key has the specified permission(s) using a query syntax.
Supports single permissions, logical operators (AND, OR), and parentheses for grouping.
Examples:
- Single permission: "documents.read"
- Multiple permissions: "documents.read AND documents.write"
- Complex queries: "(documents.read OR documents.write) AND users.view"
Verification fails if the key lacks the required permissions through direct assignment or role inheritance.
Length: 1–1000
Controls credit consumption for usage-based billing and quota enforcement.
Omitting this field uses the default cost of 1 credit per verification.
Credits provide globally consistent usage tracking, essential for paid APIs with strict quotas.
Show child attributesHide child attributes
Sets how many credits to deduct for this verification request.
Use 0 for read-only operations or free tier access, higher values for premium features.
Credits are deducted after all security checks pass.
Essential for implementing usage-based pricing with different operation costs.
Range: 0–1000000000000
Enforces time-based rate limiting during verification to prevent abuse and ensure fair usage.
Omitting this field skips rate limit checks entirely, relying only on configured key rate limits.
Multiple rate limits can be checked simultaneously, each with different costs and temporary overrides.
Rate limit checks are optimized for performance but may allow brief bursts during high concurrency.
Show child attributesHide child attributes
Length: 3–255
Default: 1
Range: >= 0
Range: >= 0
Length: max 256
Responses
Key verification process completed. This endpoint always returns HTTP 200 regardless of whether the key passed or failed verification. You must check the valid field in the response data to determine the actual verification result.
When verification succeeds, the response includes comprehensive information about the key including its current status, remaining credits, expiration time, associated permissions and roles, metadata, and any rate limiting information. This data enables your application to make informed authorization decisions and provide appropriate user experiences.
When verification fails, the response indicates the specific reason through the code field while setting valid to false. The failure codes help you handle different scenarios appropriately, such as directing users to renew expired keys, upgrade for more credits, or contact support for disabled keys.
The response also includes identity information when the key is associated with an identity, providing additional context about the key holder and any identity-specific rate limits or metadata that may apply to the verification.
requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
The primary verification result. If true, the key is valid
and can be used. If false, check the 'code' field to understand why verification
failed. Your application should always check this field first before proceeding.
A machine-readable code indicating the verification status
or failure reason. Values: VALID (key is valid and passed all checks), NOT_FOUND (key doesn't
exist or belongs to wrong API), FORBIDDEN (key lacks required permissions), INSUFFICIENT_PERMISSIONS
(key lacks specific required permissions for this request), USAGE_EXCEEDED (key has no remaining credits), RATE_LIMITED (key exceeded rate limits), DISABLED (key was explicitly disabled),
EXPIRED (key has passed its expiration date).
VALIDNOT_FOUNDFORBIDDENINSUFFICIENT_PERMISSIONSUSAGE_EXCEEDEDRATE_LIMITEDDISABLEDEXPIREDThe unique identifier of the verified key in Unkey's system.
Use this ID for operations like updating or revoking the key. This field
is returned for both valid and invalid keys (except when code=NOT_FOUND).
The human-readable name assigned to this key during creation.
This is useful for displaying in logs or admin interfaces to identify
the key's purpose.
Custom metadata associated with the key. This can include any
JSON-serializable data you stored with the key during creation or updates,
such as plan information, feature flags, or user details. Use this to
avoid additional database lookups for contextual information needed during
API calls.
Unix timestamp (in milliseconds) when the key will expire.
If omitted, the key has no expiration. You can use this to
warn users about upcoming expirations or to understand the validity period.
The number of requests/credits remaining for this key. If omitted,
the key has unlimited usage. This value decreases with
each verification (based on the 'cost' parameter) unless explicit credit
refills are configured.
Indicates if the key is currently enabled. Disabled keys will
always fail verification with code=DISABLED. This is useful for implementing
temporary suspensions without deleting the key.
A list of all permission names assigned to this key, either
directly or through roles. These permissions determine what actions the
key can perform. Only returned when permissions were checked during verification
or when the key fails with code=FORBIDDEN.
A list of all role names assigned to this key. Roles are collections
of permissions that grant access to specific functionality. Only returned
when permissions were checked during verification.
Show child attributesHide child attributes
Show child attributesHide child attributes
Length: 8–255Pattern: ^rl_[a-zA-Z0-9_]+$
Show child attributesHide child attributes
Length: 8–255Pattern: ^rl_[a-zA-Z0-9_]+$
Whether this rate limit should be automatically applied when verifying keys.
When true, we will automatically apply this limit during verification without it being explicitly listed.
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).