# Rotate an API Key

POST /api/v1/connect-keys/ {key_id} /rotate

Mint a replacement key that inherits the old key's settings and start the old key's grace period.

The response carries the new key, including its one-time secret value.

Body shape — all fields optional::

{ "grace_period_hours": 24 # how long the old key keeps working; default 24 }

The new key inherits `name`, `permissions`, `workspace_id`, `rate_limit_per_minute`, `description` from the old key. `permissions` come from the old key's mirror row (`archie_connect.keys.permissions`; the WorkOS list does not hold Archie's list), falling back to the WorkOS list only when the mirror list is empty or the row is missing. The new row also inherits the old row's `expires_at` (as it was before the grace stamp below) and `created_by_user_id`, so rotating never turns a restricted or time-limited key into an unrestricted, permanent one and never makes the person rotating its creator. `rotated_from_key_id` on the new row points back to the old key_id (lets the reaper cron walk the chain).

Old key gets `expires_at` stamped on its mirror row as the earlier of `now() + grace_period_hours` and its own current `expires_at`, so the overlap never runs past the old key's own expiry (a key with no `expires_at` gets the full overlap); a separate reaper job is expected to revoke once `expires_at` passes.

Response: same shape as POST / (full merged shape + one-time sk_… value for the new key).

Path parameters

key_id string Required

Identifier of the API key, as returned in the `id` field when it was created.

Returns

Successful Response

Errors

Status When

422 Validation Error

[Previous ← Create a New API Key](https://heyarchie.com/en-gb/developers/api-reference/connect-keys/create-a-new-api-key/)[Next Update API Key Metadata →](https://heyarchie.com/en-gb/developers/api-reference/connect-keys/update-api-key-metadata/)

```
curl https://uk.heyarchie.com/api/v1/connect-keys/<key_id>/rotate \
  -X POST \
  -H "Authorization: Bearer sk_..."
```

```
import requests

headers = {"Authorization": "Bearer sk_..."}

r = requests.post("https://uk.heyarchie.com/api/v1/connect-keys/<key_id>/rotate", headers=headers)
print(r.json())
```

```
const r = await fetch("https://uk.heyarchie.com/api/v1/connect-keys/<key_id>/rotate", {
  method: "POST",
  headers: { "Authorization": "Bearer sk_..." },
});
const data = await r.json();
console.log(data);
```

Response

```
{
  "detail": [
    {
      "loc": [
        null
      ],
      "msg": "<string>",
      "type": "<string>"
    }
  ]
}
```

Every response also carries X-Request-ID. Quote it if you write to us about a call.
