Skip to main content

verify-key

Verify an API key's validity and check permissions using the Unkey CLI. Test key verification locally before deploying authentication logic.
3 min read

Verify an API key's validity and permissions for request authentication.

Use this command 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.

Required permissions:

Your root key needs one of:

  • api.*.verify_key (verify keys in any API)
  • api.<api_id>.verify_key (verify keys in specific API)

Note: If your root key has no verify permissions at all, you will receive a 403 Forbidden error. If your root key has verify permissions for a different API than the key you're verifying, you will receive a 200 response with code: NOT_FOUND to avoid leaking key existence.

Note

See the API reference for the full HTTP endpoint documentation.

Usage#

Flags#

--keystringrequired#

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

--tagsstring[]#

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

--permissionsstring#

Permission query to check, supports AND/OR operators and parentheses for grouping. Examples: "documents.read", "documents.read AND documents.write", "(documents.read OR documents.write) AND users.view". Verification fails if the key lacks the required permissions through direct assignment or role inheritance.

--creditsJSON string#

JSON object for credit consumption configuration. Controls credit deduction for usage-based billing and quota enforcement. Omitting this field uses the default cost of 1 credit per verification.

Show credits fields
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. Min: 0, max: 1000000000.

--ratelimitsJSON string#

JSON array of rate limit checks to enforce during verification. 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.

Show ratelimits array item fields
namestringrequired#

References an existing rate limit by its name. Key rate limits take precedence over identifier-based limits.

costinteger#

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

Default: 1

limitinteger#

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

durationinteger#

Optionally override the duration of the rate limit window in milliseconds.

--migration-idstring#

Migration provider ID for on-demand key migration from your previous system. Reach out for migration support at support@unkey.com.

Global Flags#

FlagTypeDescription
--root-keystringOverride root key ($UNKEY_ROOT_KEY)
--api-urlstringOverride API base URL (default: https://api.unkey.com)
--configstringPath to config file (default: ~/.unkey/config.toml)
--outputstringOutput format. Use json for raw JSON
--bodystringSend this JSON string as the request body. You cannot combine it with request-building flags.

Examples#

Output#

Default output shows the request ID, followed by the verification result:

With --output=json, the full response envelope is returned:

When verification fails, the valid field is false and code indicates the reason:

Possible code values: VALID, NOT_FOUND, FORBIDDEN, INSUFFICIENT_PERMISSIONS, USAGE_EXCEEDED, RATE_LIMITED, DISABLED, EXPIRED.