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

# Rotate API Key

> Rotate an API key, generating new key material while preserving name and permissions

## Overview

Rotates an existing API key by generating new key material. The old key is immediately invalidated and a new plaintext key is returned. The key's name and permissions are preserved.

**Auth:** Requires JWT (dashboard operation only).

**Important:** The new plaintext key is shown only once in this response. Store it securely.

## Path Parameters

<ParamField path="key_id" type="string" required>
  The API key UUID to rotate
</ParamField>

## Response

<ResponseField name="id" type="string">
  API key UUID (unchanged)
</ResponseField>

<ResponseField name="key" type="string">
  New plaintext API key (shown once only — store it securely)
</ResponseField>

<ResponseField name="key_prefix" type="string">
  First 8 characters of the new key (for identification)
</ResponseField>

<ResponseField name="name" type="string">
  Key name (preserved from original)
</ResponseField>

<ResponseField name="created_at" type="string">
  Original creation timestamp
</ResponseField>

<ResponseField name="last_used" type="string">
  Last usage timestamp (reset on rotation)
</ResponseField>

<ResponseField name="permissions" type="object">
  Resource permissions (preserved from original). `null` means unrestricted.

  <Expandable title="Permissions object">
    <ResponseField name="allowed_services" type="array">
      Service UUIDs this key can access (null = all)
    </ResponseField>

    <ResponseField name="allowed_tools" type="array">
      Tool UUIDs this key can access (null = all)
    </ResponseField>
  </Expandable>
</ResponseField>

## Example

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.danubeai.com/v1/api-keys/key_abc123/rotate" \
    -H "Authorization: Bearer YOUR_JWT_TOKEN"
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "id": "key_abc123",
    "key": "dk_new_rotated_key_value",
    "key_prefix": "dk_new_r",
    "name": "My Production Key",
    "created_at": "2026-01-15T10:00:00Z",
    "last_used": null,
    "permissions": {
      "allowed_services": ["service_uuid_1"],
      "allowed_tools": null
    }
  }
  ```
</ResponseExample>
