Skip to content

Rotate an API key

Replace an active API key's secret and return the new secret once. The old secret works for up to 24 hours by default, bounded by the key's expiration. Use overlap 0 to revoke it immediately. An API key can rotate only itself.

Parameters

#
keystringRequired
The key's ID (see api-key view).
overlapstring
How long the old secret can still authenticate, from 0 to 7d. Defaults to 24h. Use 0 to revoke it immediately. The key's own expiration still applies.

Returns

#
dataobjectAlways present
An API key's identity, permissions and lifetime.
Show 13 attributesHide attributes
cmdsstring[] | nullAlways present
Permitted commands, subject to your permissions. * permits all commands for a sign-in key.
computer_namesmap<string, string>
Names of the Computers its scope names, by ID, those its organization still has. May be omitted.
created_atstring (date-time)Always present
When the key was created.
expires_atstring (date-time) | nullAlways present
When the key expires, or null if it has no expiry.
idstringAlways present
Key ID for editing, rotation or revocation.
labelstringAlways present
User-assigned label.
last_used_atstring (date-time) | nullAlways present
Last recorded use, or null if no use has been recorded.
organizationstring
Organization the key acts in. Sign-in keys can omit this to select an organization per request. May be omitted.
previous_secret_expires_atstring (date-time)
Expiry of the replaced secret, included while it remains accepted. May be omitted.
revoked_atstring (date-time) | nullAlways present
When the key was revoked, or null if it has not been revoked.
rotated_atstring (date-time) | nullAlways present
When its secret was last rotated, or null if it has not been rotated.
scopeobject
Resource restrictions in addition to your permissions. An absent scope adds no restriction. May be omitted.
Show 3 attributesHide attributes
computersstring[]
Computer IDs included in the key's scope. May be omitted.
poolsstring[]
Pool IDs included in the key's scope. May be omitted.
tagsstring[]
Tags selecting Computers the key can reach. May be omitted.
tokenstring
Newly issued secret, returned only on creation or rotation. May be omitted.

Errors

#
CodeStatusWhat happened
invalid400An input is missing or invalid.
unauthenticated401The credential is missing, invalid, expired or revoked.
denied403The caller lacks permission for this action.
not_found404The resource is absent or inaccessible to this caller.
conflict409The request conflicts with the current resource state or an earlier request.
over_capacity409The request exceeds a resource or credential allowance.
access_list_full409The change would exceed the access-list allowance.
payment_required402Payment or credit is required.
rate_limited429The caller's request rate exceeds its limit.
busy429Too much work is in progress to accept this request.
unknown503The outcome is unconfirmed; a change may have happened.
unavailable503The service or requested feature is unavailable.

Notes

#
  • This example uses management SSH. A key, including a CLI or MCP sign-in, can rotate only itself.
  • API key permission: api-key rotate.