/v1/apps/{app_id}/api-keys/{key_id}/rotateAuthMint a replacement for an existing key, carrying its name and permissions over. The outgoing key keeps working for `grace_hours` (24 by default) so a fleet can roll over without downtime. The raw key is returned ONCE.
Path parameters
app_id*stringId of the app.
key_id*stringId of the key.
Headers
Idempotency-KeystringThe replacement key is returned exactly once. A retry without this header mints a SECOND replacement whose plaintext the caller may never see, and shortens the outgoing key twice. 24h TTL.
Request body
grace_hoursnumberHow long the OUTGOING key keeps working, in hours. `0` kills it immediately. Capped at 168 (7 days) — a rotation answers "this key may be compromised", so an unbounded overlap would defeat the point. Rotation can only ever shorten a key: if the old key was already due to expire sooner, that earlier instant stands.
Example: 24
Response · 201 Replacement key with raw secret, plus when the old one dies.
id*stringAPI key row UUID.
name*stringDisplay name.
Example: "CI deploy bot"
key*stringRaw API key. Returned exactly once — store it now.
Example: "hdk_live_aZxYbpKL..."
key_prefix*stringFirst 16 chars of the key — safe to display in lists.
Example: "hdk_live_aZxYbpKL"
permissions*arrayPermission scope.
Example: ["user.read","user.list"]
expires_at*string · date-timeWhen this key stops authenticating. `null` means it never expires.
created_at*string · date-timeWhen the API key was created (ISO 8601).
rotated_from*stringId of the key this one replaces.
previous_key_expires_at*string · date-timeWhen the replaced key stops authenticating. Until then BOTH keys work, so a fleet can roll over without downtime.
Example
Request
POST https://api.auth.productcraft.co/v1/apps/{app_id}/api-keys/{key_id}/rotate
Authorization: Bearer YOUR_TOKEN
Content-Type: application/json
{
"grace_hours": 24
}import { Auth } from "@productcraft/auth";
// Admin routes read PRODUCTCRAFT_API_KEY; consumer routes need no key
const auth = new Auth();
const rotateApiKey = await auth.admin.app("3f0c3c1e-8a2b-4c55-9d3f-0a1b2c3d4e5f").apiKeys.rotate("3f0c3c1e-8a2b-4c55-9d3f-0a1b2c3d4e5f", { grace_hours: 24 });auth.admin.app(…).apiKeys.rotate(keyId, params?, options?): Auth.RotateApiKey
Response
{
"id": "string",
"name": "CI deploy bot",
"key": "hdk_live_aZxYbpKL...",
"key_prefix": "hdk_live_aZxYbpKL",
"permissions": [
"user.read",
"user.list"
],
"expires_at": "2026-01-01T00:00:00.000Z",
"created_at": "2026-01-01T00:00:00.000Z",
"rotated_from": "string",
"previous_key_expires_at": "2026-01-01T00:00:00.000Z"
}