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

# Regenerate API Key

> This endpoint regenerates an API key.

## POST /api-keys/{keyId}/regenerate

This endpoint regenerates an API key. This creates a new key value while keeping all metadata (name, description, permissions). The old key is immediately invalidated.

<Warning>
  The new API key value is only shown once. The old key will stop working immediately.
</Warning>

<Note>
  You cannot regenerate the API key that is currently being used to make the request.
</Note>

### Path Parameters

<ParamField path="keyId" type="string" required>
  The ID of the API key to regenerate.
</ParamField>

### Response

<ResponseField name="success" type="boolean">
  Whether the regeneration was successful.
</ResponseField>

<ResponseField name="message" type="string">
  A status message.
</ResponseField>

<ResponseField name="apiKey" type="object">
  The regenerated API key details.

  <Expandable title="apiKey properties">
    <ResponseField name="id" type="string">
      The key identifier (unchanged).
    </ResponseField>

    <ResponseField name="name" type="string">
      The key name (unchanged).
    </ResponseField>

    <ResponseField name="key" type="string">
      The new API key value (only shown once).
    </ResponseField>

    <ResponseField name="regeneratedAt" type="string">
      ISO 8601 timestamp of regeneration.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="warning" type="string">
  A reminder that the old key is now invalid.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/api-keys/llm_1706123456_abc123def456/regenerate \
    -H "Authorization: Bearer YOUR_API_KEY"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    'https://api.llmgenerator.com/api/v1/api-keys/llm_1706123456_abc123def456/regenerate',
    {
      method: 'POST',
      headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
    }
  );

  const data = await response.json();
  // Save data.apiKey.key securely!
  ```
</RequestExample>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "success": true,
    "message": "API key regenerated successfully",
    "apiKey": {
      "id": "llm_1706123456_abc123def456",
      "name": "Production Key",
      "key": "llm_1706456789_newvalue567xyz",
      "regeneratedAt": "2026-01-27T10:00:00.000Z"
    },
    "warning": "This is the only time the new API key will be shown. Please save it securely. The old key is now invalid."
  }
  ```

  ```json Cannot Regenerate Current Key (400) theme={null}
  {
    "message": "Cannot regenerate the API key currently being used"
  }
  ```

  ```json Not Found (404) theme={null}
  {
    "message": "API key not found"
  }
  ```
</ResponseExample>
