Skip to main content

Create Identity

Create an identity to group multiple API keys under a single entity. Identities enable shared rate limits and metadata across all associated keys.

Perfect for users with multiple devices, organizations with multiple API keys, or when you need unified rate limiting across different services.

Important
Requires identity.*.create_identity permission

1 min read
post/v2/identities.createIdentity
Request example
Response
post/v2/identities.createIdentity

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
externalIdstringrequired#

Creates an identity using your system's unique identifier for a user, organization, or entity.
Must be stable and unique across your workspace - duplicate externalIds return CONFLICT errors.
This identifier links Unkey identities to your authentication system, database records, or tenant structure.

Avoid changing externalIds after creation as this breaks the link between your systems.
Use consistent identifier patterns across your application for easier management and debugging.
Accepts letters, numbers, underscores, dots, and hyphens for flexible identifier formats.
Essential for implementing proper multi-tenant isolation and user-specific rate limiting.

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

metaobject#

Stores arbitrary JSON metadata returned during key verification for contextual information.
Eliminates additional database lookups during verification, improving performance for stateless services.
Avoid storing sensitive data here as it's returned in verification responses.

Large metadata objects increase verification latency and should stay under 10KB total size.
Use this for subscription details, feature flags, user preferences, and organization information.
Metadata is returned as-is whenever keys associated with this identity are verified.

ratelimitsobject[]#

Defines shared rate limits that apply to all keys belonging to this identity.
Prevents abuse by users with multiple keys by enforcing consistent limits across their entire key portfolio.
Essential for implementing fair usage policies and tiered access levels in multi-tenant applications.

Rate limit counters are shared across all keys with this identity, regardless of how many keys the user creates.
During verification, specify which named limits to check for enforcement.
Identity rate limits supplement any key-specific rate limits that may also be configured.

  • Each named limit can have different thresholds and windows

When verifying keys, you can specify which limits you want to use and all keys attached to this identity will share the limits, regardless of which specific key is used.

Items: max 50

Show child attributes
namestringrequired#

The name of this rate limit. This name is used to identify which limit to check during key verification.

Best practices for limit names:

  • Use descriptive, semantic names like 'api_requests', 'heavy_operations', or 'downloads'
  • Be consistent with naming conventions across your application
  • Create separate limits for different resource types or operation costs
  • Consider using namespaced names for better organization (e.g., 'files.downloads', 'compute.training')

You will reference this exact name when verifying keys to check against this specific limit.

Length: 3–128

limitintegerrequired#

The maximum number of operations allowed within the specified time window.

When this limit is reached, verification requests will fail with code=RATE_LIMITED until the window resets. The limit should reflect:

  • Your infrastructure capacity and scaling limitations
  • Fair usage expectations for your service
  • Different tier levels for various user types
  • The relative cost of the operations being limited

Higher values allow more frequent access but may impact service performance.

Range: >= 1

durationintegerrequired#

The duration for each ratelimit window in milliseconds.

This controls how long the rate limit counter accumulates before resetting. Common values include:

  • 1000 (1 second): For strict per-second limits on high-frequency operations
  • 60000 (1 minute): For moderate API usage control
  • 3600000 (1 hour): For less frequent but costly operations
  • 86400000 (24 hours): For daily quotas

Shorter windows provide more frequent resets but may allow large burst usage. Longer windows provide more consistent usage patterns but take longer to reset after limit exhaustion.

Range: >= 1000

autoApplybooleanrequired#
Whether this ratelimit should be automatically applied when verifying a key.

Default: false

Responses

application/json
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
identityIdstringrequired#
The unique identifier of the created identity.