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

# Regenerate API Key

> Regenerate an existing API key

Regenerates an existing API key, invalidating the old key and creating a new one.

<Warning>
  This action will immediately invalidate the old API key. Make sure to update your applications with the new key.
</Warning>

## Path Parameters

<ParamField path="key_id" type="string" required>
  The unique identifier of the API key to regenerate
</ParamField>

## Response

<ResponseField name="id" type="string">
  The unique identifier of the API key
</ResponseField>

<ResponseField name="key" type="string">
  The new API key value
</ResponseField>

<ResponseField name="name" type="string">
  The name of the API key
</ResponseField>

<ResponseField name="created_at" type="string">
  The timestamp when the key was regenerated
</ResponseField>

<ResponseField name="last_used_at" type="string">
  The timestamp when the key was last used (will be null for new keys)
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST \
    https://api.buena.ai/api/v2/keys/key_123/regenerate \
    -H "x-api-key: YOUR_API_KEY"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.buena.ai/api/v2/keys/key_123/regenerate', {
    method: 'POST',
    headers: {
      'x-api-key': 'YOUR_API_KEY'
    }
  });
  const data = await response.json();
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "key_123",
    "key": "bai_new_generated_key_here",
    "name": "Production API Key",
    "created_at": "2024-01-01T00:00:00Z",
    "last_used_at": null
  }
  ```
</ResponseExample>
