Skip to main content
Temporary keys automatically become invalid after a specified time. Unkey handles expiration and cleanup for you, making it easy to implement trial access, time-limited integrations, and security rotation policies.

How expiration works

  1. Set an expiration timestamp — Specify expires as a Unix timestamp in milliseconds
  2. Key works until expiration — Verification succeeds normally until the time is reached
  3. Automatic invalidation — After expiration, verification returns code: EXPIRED
  4. Automatic cleanup — Unkey periodically removes expired keys from the system
Keys without an expires field are permanent and never expire unless manually revoked.

Use cases

Trial access

Give new users a 7-day trial key. It stops working automatically, no manual cleanup needed.

Session-based access

Generate keys that last for a user session (e.g., 24 hours). Perfect for temporary integrations.

Time-limited partnerships

Partner needs API access for a 3-month project. Key expires when the contract ends.

Security rotation

Force key rotation by issuing keys that expire after 90 days.

Creating temporary keys

Basic expiration

Common expiration durations

Specific date expiration

Verification response

Expired keys return a specific error code:
Handle expiration in your application:

Managing expiration

Extend expiration

Grant more time to an existing key:

Remove expiration

Make a temporary key permanent:

Check time remaining

Calculate how much time a key has left:

Expiration strategies

Trial-to-paid conversion

Grant trial access with automatic expiration, then issue a permanent key on upgrade:

Rotating credentials

Force regular key rotation for security:

Session-based keys

Generate short-lived keys for authenticated sessions:

Partner integrations

Time-limited access for external partners:

Combining expiration with other limits

Temporary keys work with all other features:
Use both for robust trials: “7 days OR 1000 requests, whichever comes first.” This prevents abuse while giving flexibility.

Notification strategies

Alert users before keys expire:

Best practices

Send reminders at 7 days, 3 days, and 1 day before a key expires. Give users time to renew or rotate.
Production keys should be long-lived or permanent. Expiration is best for temporary access scenarios.
When a key is about to expire, provide a one-click renewal option. Don’t force users to manually create new keys.
Track when keys expire and why. This helps you understand trial conversion rates and rotation compliance.

Next steps

Usage limits

Combine time limits with request quotas

Multi-tenant applications

Manage keys across multiple organizations