How expiration works
- Set an expiration timestamp — Specify
expiresas a Unix timestamp in milliseconds - Key works until expiration — Verification succeeds normally until the time is reached
- Automatic invalidation — After expiration, verification returns
code: EXPIRED - 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: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
Always notify before expiration
Always notify before expiration
Send reminders at 7 days, 3 days, and 1 day before a key expires. Give users time to renew or rotate.
Use expiration for trials, not production
Use expiration for trials, not production
Production keys should be long-lived or permanent. Expiration is best for temporary access scenarios.
Offer easy renewal
Offer easy renewal
When a key is about to expire, provide a one-click renewal option. Don’t force users to manually create new keys.
Log expiration events
Log expiration events
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