> ## 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.

# 重新生成 API Key

> 重新生成 API Key 密钥串。

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

重新生成 API Key：保留名称、描述、权限等元数据，生成新的密钥串；旧密钥立即失效。

<Warning>
  新密钥同样仅展示一次；旧密钥即刻不可用。
</Warning>

<Note>
  不能使用当前请求正在使用的 API Key 来重新生成自身。
</Note>

### 路径参数

<ParamField path="keyId" type="string" required>
  要重新生成的 API Key ID。
</ParamField>

### 响应

<ResponseField name="success" type="boolean">
  是否成功。
</ResponseField>

<ResponseField name="message" type="string">
  状态说明。
</ResponseField>

<ResponseField name="apiKey" type="object">
  重新生成后的详情。

  <Expandable title="apiKey 字段">
    <ResponseField name="id" type="string">
      Key ID（不变）。
    </ResponseField>

    <ResponseField name="name" type="string">
      名称（不变）。
    </ResponseField>

    <ResponseField name="key" type="string">
      新密钥（仅展示一次）。
    </ResponseField>

    <ResponseField name="regeneratedAt" type="string">
      重新生成时间（ISO 8601）。
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="warning" type="string">
  提示旧密钥已失效。
</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>
