Auth API reference

Auth API · Api-Keys

post/v1/apps/{app_id}/api-keys/{key_id}/rotateAuth

Mint 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*string

Id of the app.

key_id*string

Id of the key.

Headers

Idempotency-Keystring

The 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_hoursnumber

How 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*string

API key row UUID.

name*string

Display name.

Example: "CI deploy bot"

key*string

Raw API key. Returned exactly once — store it now.

Example: "hdk_live_aZxYbpKL..."

key_prefix*string

First 16 chars of the key — safe to display in lists.

Example: "hdk_live_aZxYbpKL"

permissions*array

Permission scope.

Example: ["user.read","user.list"]

expires_at*string · date-time

When this key stops authenticating. `null` means it never expires.

created_at*string · date-time

When the API key was created (ISO 8601).

rotated_from*string

Id of the key this one replaces.

previous_key_expires_at*string · date-time

When 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
}

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"
}