Skip to main content

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.

1 min read
post/v2/keys.verifyKey
Request example
Response
post/v2/keys.verifyKey

Authorization

Authorizationstringheaderrequired#

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. Legacy permissions use tuple strings like api.*.create_key; resource permissions use Unkey Resource Names plus actions, like unkey:v1:ws_123:keyspaces/*#create_key.
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

application/json
keystringrequired#

The API key to verify, exactly as provided by your user.
Include any prefix - even small changes will cause verification to fail.

Length: 1–512

tagsstring[]#

Attaches metadata tags for analytics and monitoring without affecting verification outcomes.
Enables segmentation of API usage in dashboards by endpoint, client version, region, or custom dimensions.
Use 'key=value' format for compatibility with most analytics tools and clear categorization.
Avoid including sensitive data in tags as they may appear in logs and analytics reports.

Items: max 20

permissionsstring#

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

creditsobject#

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 attributes
costintegerrequired#

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

ratelimitsobject[]#

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 attributes
namestringrequired#
References an existing ratelimit by its name. Key Ratelimits will take precedence over identifier-based limits.

Length: 3–255

costinteger#
Optionally override how expensive this operation is and how many tokens are deducted from the current limit.

Default: 1

Range: >= 0

limitinteger#
Optionally override the maximum number of requests allowed within the specified interval.

Range: >= 0

durationinteger#
Optionally override the duration of the rate limit window duration.

Range: >= 0

migrationIdstring#
Migrate keys on demand from your previous system. Reach out for migration support at support@unkey.dev

Length: max 256

Responses

application/json

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.

metaobjectrequired#
Metadata object included in every API response. This provides context about the request and is essential for debugging, audit trails, and support inquiries. The requestId is particularly important when troubleshooting issues with the Unkey support team.
Show child attributes
requestIdstringrequired#
A unique id for this request. Always include this ID when contacting support about a specific API request. This identifier allows Unkey's support team to trace the exact request through logs and diagnostic systems to provide faster assistance.
dataobjectrequired#
Show child attributes
validbooleanrequired#

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.

codeenum<string>required#

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).

Options:VALIDNOT_FOUNDFORBIDDENINSUFFICIENT_PERMISSIONSUSAGE_EXCEEDEDRATE_LIMITEDDISABLEDEXPIRED
keyIdstring#

The 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).

namestring#

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.

metaobject#

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.

expiresinteger#

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.

creditsinteger#

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.

enabledboolean#

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.

permissionsstring[]#

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.

rolesstring[]#

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.

identityobject#
Show child attributes
idstringrequired#
Identity ID
externalIdstringrequired#
External identity ID
metaobject#
Identity metadata
ratelimitsobject[]#
Identity ratelimits
Show child attributes
idstringrequired#
Unique identifier for this rate limit configuration.

Length: 8–255Pattern: ^rl_[a-zA-Z0-9_]+$

namestringrequired#
Human-readable name for this rate limit.

Length: 1–128

limitintegerrequired#
Maximum requests allowed within the time window.

Range: 1–1000000

durationintegerrequired#
Rate limit window duration in milliseconds.

Range: 1000–2592000000

autoApplybooleanrequired#
Whether this rate limit was automatically applied when verifying the key.
ratelimitsobject[]#
Show child attributes
exceededbooleanrequired#
Whether the rate limit was exceeded.
idstringrequired#
Unique identifier for this rate limit configuration.

Length: 8–255Pattern: ^rl_[a-zA-Z0-9_]+$

namestringrequired#
Human-readable name for this rate limit.

Length: 1–128

limitintegerrequired#
Maximum requests allowed within the time window.

Range: 1–1000000

durationintegerrequired#
Rate limit window duration in milliseconds.

Range: 1000–2592000000

resetintegerrequired#
Rate limit reset duration in milliseconds.

Range: 1000–2592000000

remainingintegerrequired#
Rate limit remaining requests within the time window.

Range: 0–1000000

autoApplybooleanrequired#

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.