---
title: "Rotate a personal API key"
method: POST
path: "/api-keys/{key_id}/rotate"
tags: ["Billing"]
---

# Rotate a personal API key

`POST /api-keys/{key_id}/rotate`

## Request

- Base URL: `https://api.mnemom.ai/v1`
- URL: `https://api.mnemom.ai/v1/api-keys/{key_id}/rotate`
- Auth: HTTP bearer

Atomically mints a replacement key with the same `name` and `scopes` as the original, then immediately revokes the old key. The full new secret is returned in the response — this is your only chance to capture it. Old key is invalid as soon as the response is returned; if you need overlap with an in-flight deploy, **create a second key first** via `POST /api-keys`, ship your code, then `DELETE` the old key. Rotation is for the suspect/compromised-key case where overlap is the opposite of what you want. Authorization: `key_id` is matched together with the authenticated caller's user id, so a key owned by another user is invisible (404) and no one else's personal key can be rotated.

## Path parameters

- `key_id` string, required

## Response `201`

New key minted, old key revoked.

- object
  - `key_id` string
  - `key` string: Full secret. Capture now — never returned again.
  - `key_prefix` string
  - `name` string
  - `scopes` string[]
  - `rotated_from` string: key_id of the now-revoked predecessor
  - `old_key_revoked_at` string, date-time
  - `created_at` string, date-time

## Other responses

- `400`: Bad request
- `401`: Authentication required
- `403`: Forbidden
- `404`: Resource not found
- `429`: Rate-limit exceeded. The global per-IP limiter (100 requests/minute, applied to every `/v1/*` route) rejected this request. Back off until the window resets — `Retry-After` carries the cooldown in seconds and `X-RateLimit-Reset` the absolute reset time.
- `500`: Server error — request was well-formed but the server failed to fulfill it. Typically a downstream dependency (DB / RPC / external API) returned an unexpected error.

---

[API](https://skmtc.dev/mnemom/apis/mnemom-api.md) · [All operations](https://skmtc.dev/mnemom/apis/mnemom-api/llms.txt) · [OpenAPI document](https://skmtc.dev/mnemom/apis/mnemom-api/revisions/274b7a6ea182?raw)
