Rotating an API Key
Replace a key's secret without downtime using a grace window
Rotation replaces a key's secret while keeping its name, scopes, and history. During a grace window, both the old and new secrets work, so you can update your systems with no downtime.
When to rotate
- A secret may have been exposed (pasted in chat, committed to a repository, a laptop lost)
- Someone who knew the secret has left
- On a regular schedule, as good hygiene
Before you begin
- You need the Admin role.
- Know every system that uses the key, so you can update them during the grace window.
- Revoked and expired keys can't be rotated. Create a new key instead.
Steps
On the API Keys page, click Rotate on the key's row. The Rotate API Key dialog opens.
Choose a Grace window, which is how long the old secret keeps working:
| Grace window | Use when |
|---|---|
| Immediate cutover | The secret was exposed. The old secret stops working at once |
| 1 hour | One system to update, and you're ready now |
| 24 hours | Usually right. Time to update a few systems |
| 7 days | Many systems, or ones owned by other teams |
Confirm. You'll see "Key rotated", and the new secret is shown once. Copy it now.
Update every system that uses the key.
When the grace window ends, the old secret stops working automatically.
While the grace window is open, the key's Status shows Rotating. Hover over it to see when the old secret stops working ("Old secret valid until …").
Rotating again during an active grace window ends the previous secret's grace immediately. You'll be warned first.
If a secret was exposed, choose Immediate cutover, or revoke the key and create a new one.
Troubleshooting
| Message or symptom | Cause | Fix |
|---|---|---|
| Cannot rotate a revoked key | The key was revoked | Create a new key |
| Cannot rotate an expired key | The key has expired | Create a new key |
A system starts getting 401 after a few hours or days | It still uses the old secret, and the grace window has ended | Update it with the new secret |
| Rotate failed | The rotation didn't complete | Try again. The old secret keeps working until a rotation succeeds |