Moonborn — API · api-keys
Rotate an API key (zero-downtime)
Issues a successor key with the same scopes. The old key transitions to `rotated` status. Supply `graceSeconds` to keep the old key accepted during the switchover window (Tier-0: zero-downtime rotation).
POST/v1/api-keys/{id}/rotatescope · Bearer (API key or session JWT)
Path parameters
| Field | Type | Description |
|---|---|---|
| idreq | string | API key id (UUID). |
Request body
| Field | Type | Description |
|---|---|---|
| graceSeconds | number |
Responses
201Rotation completed. New key `plaintextKey` returned once.
Body
| Field | Type | Description |
|---|---|---|
| oldKeyIdreq | string | |
| newKeyreq | object | |
| newKey.idreq | string | |
| newKey.prefixreq | string | |
| newKey.plaintextKeyreq | string | |
| newKey.scopesreq | string · "*" | "read:personas" | "write:personas" | "read:chat" | "write:chat" | "read:marketplace" | "write:marketplace" | "read:billing" | "read:audit" | "read:webhooks" | "write:webhooks" | "read:config" | "write:config"[] | |
| newKey.createdAtreq | string | |
| newKey.expiresAtreq | string | |
| graceSecondsreq | number |
400Validation error.
Body
| Field | Type | Description |
|---|---|---|
| errorreq | object | |
| error.codereq | string | |
| error.messagereq | string | |
| error.details | object |
401Unauthenticated.
Body
| Field | Type | Description |
|---|---|---|
| errorreq | object | |
| error.codereq | string | |
| error.messagereq | string | |
| error.details | object |
403Forbidden.
Body
| Field | Type | Description |
|---|---|---|
| errorreq | object | |
| error.codereq | string | |
| error.messagereq | string | |
| error.details | object |
404Key not found.
Body
| Field | Type | Description |
|---|---|---|
| errorreq | object | |
| error.codereq | string | |
| error.messagereq | string | |
| error.details | object |
409Key is in a terminal state (already rotated/revoked/expired).
Body
| Field | Type | Description |
|---|---|---|
| errorreq | object | |
| error.codereq | string | |
| error.messagereq | string | |
| error.details | object |
Examples
cURL
curl -X POST https://api.moonborn.co/v1/api-keys/<id>/rotate \
-H "Authorization: Bearer $MOONBORN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"graceSeconds": 0
}'TypeScript
import Moonborn from '@moonborn/sdk';
const client = new Moonborn({ apiKey: process.env.MOONBORN_API_KEY });
const result = await client.api_keys.rotateApiKey({
id: '<id>',
graceSeconds: 0,
});Python
import os
from moonborn import Moonborn
client = Moonborn(api_key=os.environ["MOONBORN_API_KEY"])
result = client.api_keys.rotate_api_key(
id="<id>",
grace_seconds=0,
)