> ## 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 キーの再生成

> API キーを再発行するエンドポイントです。

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

API キーを再生成します。メタデータ（名称・説明・権限）は維持しつつキー値を新しくします。古いキーは直ちに無効になります。

<Warning>
  新しい API キー値はこのとき一度だけ表示されます。古いキーはすぐに使えなくなります。
</Warning>

<Note>
  現在のリクエストに使用している API キーは再生成できません。
</Note>

### パスパラメーター

<ParamField path="keyId" type="string" required>
  再生成する API キーの ID。
</ParamField>

### レスポンス

<ResponseField name="success" type="boolean">
  再生成が成功したかどうか。
</ResponseField>

<ResponseField name="message" type="string">
  ステータスメッセージ。
</ResponseField>

<ResponseField name="apiKey" type="object">
  再生成後の API キー詳細。

  <Expandable title="apiKey のプロパティ">
    <ResponseField name="id" type="string">
      キー識別子（変更なし）。
    </ResponseField>

    <ResponseField name="name" type="string">
      キー名（変更なし）。
    </ResponseField>

    <ResponseField name="key" type="string">
      新しい API キー値（このとき一度だけ）。
    </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 成功 (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 現在使用中のキーは再生成不可 (400) theme={null}
  {
    "message": "Cannot regenerate the API key currently being used"
  }
  ```

  ```json 見つからない (404) theme={null}
  {
    "message": "API key not found"
  }
  ```
</ResponseExample>
