> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memorylake.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Rotate API Key

> Replaces the key material and returns the new value once

```
POST /openapi/memorylake/admin/v1/api-keys/{id}/rotate
```

Replaces the key material and returns the new value once. The previous value stops working immediately.

<Warning>
  Rotation is not naturally idempotent: every call mints a new key and stops the previous one. When retrying over an unreliable network, always send an `Idempotency-Key` — a blind retry would invalidate the key you just received.
</Warning>

<Note>
  **Permission required:** `service_account:update` (your own keys only) or `service_account:update` (all keys)
</Note>

### Path Parameters

<ParamField path="id" type="string" required>
  Identifier of the API key
</ParamField>

### Headers

<ParamField header="Idempotency-Key" type="string">
  Optional. Retrying with the same value replays the first result — it does NOT mint a second key.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://app.memorylake.ai/openapi/memorylake/admin/v1/api-keys/9d971b8b5813eb1ecceec31354c101b4/rotate' \
    -H 'Authorization: Bearer sk_xxxxxx' \
    -H 'Idempotency-Key: 7c1d2e3f-0a9b-4c8d-b7e6-f5a4d3c2b1a0'
  ```
</RequestExample>

### Response

<ResponseField name="data" type="object">
  <Expandable title="API Key Created object">
    <ResponseField name="id" type="string">Stable identifier of this API key</ResponseField>
    <ResponseField name="key" type="string">The full API key, including the sk- prefix. Save it now — read endpoints never return it.</ResponseField>
    <ResponseField name="key_prefix" type="string">First 8 characters of the key body</ResponseField>
    <ResponseField name="name" type="string">Display name</ResponseField>
    <ResponseField name="key_suffix" type="string">Last 4 characters of the key</ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "success": true,
    "message": "Operation completed successfully",
    "data": {
      "id": "b62967384a5222f7709e7ee5220e565f",
      "key": "sk-f6e5d4c3...redacted...b2a1",
      "key_prefix": "f6e5d4c3",
      "name": "Example name",
      "key_suffix": "b2a1"
    }
  }
  ```
</ResponseExample>

### Errors

Errors answer with `success: false`, a `message` and an `error_code`. See [Error Codes](/features/memorylake/api-reference/errors) for every code.

| Status | Meaning |
| - | - |
| `401` | The API key is missing, invalid, disabled or expired |
| `403` | The key is not allowed to do this |
| `404` | The resource does not exist |
| `409` | The request conflicts with the current state, e.g. a duplicate or a limit reached |
| `422` | The body or a parameter failed validation |
| `429` | Too many requests. Wait for the time in `Retry-After` |
| `500` | Server-side error |
| `503` | Temporarily unavailable. Retry later |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.