Availability: API key rotation is available on all plans (Free, Growth, and Enterprise) on Portkey Cloud.For self-hosted deployments:
- Airgapped: Backend
v1.14.0+ - Hybrid: Gateway Enterprise
v2.5.0+
Overview
API Key Rotation enables you to replace API key secrets without causing service disruption. When a key is rotated:- A new secret is generated immediately.
- The previous secret remains valid for a configurable transition period, allowing time to update existing integrations.
- After the transition period ends, the old secret is automatically revoked.
- Manually, on demand
- Automatically, using a defined schedule
- The API key ID remains unchanged during rotation.
- Only the secret value is updated.
- Existing usage data, such as budget tracking, cost attribution, and analytics - continues to be associated with the same key.
Key Concepts
How Rotation Works
- A new API key secret is generated.
- The current secret is retained as a previous version, with a
key_transition_expires_attimestamp. - The API key is updated with the new secret, and
last_rotated_atis recorded. - The new secret becomes immediately valid for authentication.
- If a
rotation_periodis configured,next_rotation_atis recalculated for the next cycle.
- Both the previous and current secrets are accepted.
- Requests authenticated with either secret resolve to the same API key.
Transition Window Lifecycle
Rotation Modes
Manual Rotation
Triggered via API call. The caller receives the new key in the response. Endpoint:POST /v2/api-keys/:apiKeyId/rotate
Request body (optional):
key_transition_period_ms— overrides the policy/default transition period for this rotation. Minimum:1800000(30 min).
- Cannot rotate if a previous version is still in transition. Wait for the transition to expire first.
- If a rotation policy with
rotation_periodexists, the transition period must be shorter than the rotation period.
*.rotate (e.g., organisation-service-api-keys.rotate, workspace-user-api-keys.rotate)
Automatic Rotation
Automatic rotation is handled by a background worker that runs on a recurring schedule. On each run, the worker executes the following phases in order:Rotation Policy Configuration
A rotation policy can be attached to any API key at creation or via update.key_transition_period_msmust be strictly less than the rotation period duration.- If both
rotation_periodandnext_rotation_atare provided,next_rotation_attakes precedence for the upcoming rotation. - Subsequent rotations follow the
rotation_period.
rotation_policy to null in the update request.
Organisation-Enforced Rotation Period
Organisation owners/admins can enforce a rotation cadence on workspace-user API keys via theuser_api_key_rotation_period setting (with optional per-workspace override). The setting accepts an integer between 1 and 365 (days). (Backend v1.17.0+ stores and returns days only; weekly/monthly input is normalized to 7/30.)
When set, newly-created workspace-user keys without a rotation policy automatically get the enforced cadence, and any explicit rotation_period / rotation_period_days that differs from the enforced value is rejected at create/update time. next_rotation_at cannot be manually changed on API key update while enforcement is active.
Email Notifications
These notifications are triggered during automatic rotation runs.:
Recipients: Organisation admins and owners, the key’s owning user (for workspace-user keys), and any custom addresses in
alert_emails.
Reading Rotation State
GET /v2/api-keys/:apiKeyId returns the rotation policy alongside the key details:
Permissions & Authorization
Admins (org admin/owner, workspace admin/manager) can rotate any key within their scope. Non-admins can only rotate their own keys.
Constraints & Limits
-
A maximum of two active secrets can exist per API key at any time:
- The current secret
- One previous secret within its transition window
- Rotation is blocked while a transition is active (i.e., until the previous secret expires)
-
key_transition_period_ms:- Minimum: 30 minutes (
1800000ms) - Must be strictly less than the configured rotation period
- Minimum: 30 minutes (
-
Supported
rotation_periodvalues:weeklymonthly
-
rotation_period_days(Backendv1.16.0+) accepts an integer between1and365. Mutually exclusive withrotation_period. -
next_rotation_atis always normalized to UTC midnight for consistency across schedules
Audit Logging
Every rotation (manual and automatic) produces an audit log entry containing:Notes
- Automatic rotation phases are executed sequentially within a single run.
- A single run may process multiple keys across different phases.
- Notifications are advisory and do not affect key validity.

