POST
/
v2
/
keys.verifyKey
Go (SDK)
package main

import(
	"context"
	"os"
	unkey "github.com/unkeyed/sdks/api/go/v2"
	"github.com/unkeyed/sdks/api/go/v2/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := unkey.New(
        unkey.WithSecurity(os.Getenv("UNKEY_ROOT_KEY")),
    )

    res, err := s.Keys.VerifyKey(ctx, components.V2KeysVerifyKeyRequestBody{
        Key: "sk_1234abcdef",
        Tags: []string{
            "endpoint=/users/profile",
            "method=GET",
            "region=us-east-1",
            "clientVersion=2.3.0",
            "feature=premium",
        },
        Permissions: unkey.String("documents.read AND users.view"),
        Credits: &components.KeysVerifyKeyCredits{
            Cost: 5,
        },
        Ratelimits: []components.KeysVerifyKeyRatelimit{
            components.KeysVerifyKeyRatelimit{
                Name: "tokens",
                Cost: unkey.Int64(2),
                Limit: unkey.Int64(50),
                Duration: unkey.Int64(600000),
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.V2KeysVerifyKeyResponseBody != nil {
        // handle response
    }
}
{
  "meta": {
    "requestId": "req_123"
  },
  "data": {
    "valid": true,
    "code": "VALID",
    "keyId": "<string>",
    "name": "<string>",
    "meta": {},
    "expires": 123,
    "credits": 123,
    "enabled": true,
    "permissions": [
      "<string>"
    ],
    "roles": [
      "<string>"
    ],
    "identity": {
      "id": "<string>",
      "externalId": "<string>",
      "meta": {},
      "ratelimits": [
        {
          "id": "rl_1234567890abcdef",
          "name": "api_requests",
          "limit": 1000,
          "duration": 3600000,
          "autoApply": true
        }
      ]
    },
    "ratelimits": [
      {
        "exceeded": true,
        "id": "rl_1234567890abcdef",
        "name": "api_requests",
        "limit": 1000,
        "duration": 3600000,
        "reset": 3600000,
        "remaining": 999,
        "autoApply": true
      }
    ]
  }
}

Authorizations

Authorization
string
header
required

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_123

Root 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:

  • 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
key
string
required

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

Required string length: 1 - 512
Example:

"sk_1234abcdef"

tags
string[]

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.

Maximum length: 20
Example:
[
"endpoint=/users/profile",
"method=GET",
"region=us-east-1",
"clientVersion=2.3.0",
"feature=premium"
]
permissions
string

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.
Required string length: 1 - 1000
Example:

"documents.read AND users.view"

credits
object

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.

ratelimits
object[]

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.

Response

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.

meta
object
required

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.

data
object
required