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

認証済みユーザー用に新しい API キーを作成します。キー値の全文は作成時のみ表示されます。安全に保管してください。

<Warning>
  API キー値の全文は作成時のみ返されます。後から再取得できないため、必ず安全に保管してください。
</Warning>

### リクエストボディ

<ParamField body="name" type="string" required>
  API キーの説明用名称（1〜100 文字）。
</ParamField>

<ParamField body="description" type="string">
  キーの用途の説明（最大 500 文字）。
</ParamField>

<ParamField body="permissions" type="array">
  キーに付与する権限の一覧。未指定時はすべての権限。
</ParamField>

<ParamField body="expiresAt" type="string">
  省略可能な有効期限（ISO 8601 形式）。
</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">
      API キーの一意な識別子。
    </ResponseField>

    <ResponseField name="name" type="string">
      キーの名称。
    </ResponseField>

    <ResponseField name="key" type="string">
      API キー値の全文（このとき一度だけ）。
    </ResponseField>

    <ResponseField name="isActive" type="boolean">
      キーが有効かどうか。
    </ResponseField>

    <ResponseField name="createdAt" 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 \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Production API Key",
      "description": "For the main application"
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    'https://api.llmgenerator.com/api/v1/api-keys',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        name: 'Production API Key',
        description: 'For the main application'
      })
    }
  );

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

<ResponseExample>
  ```json 成功 (201) theme={null}
  {
    "success": true,
    "message": "API key created successfully",
    "apiKey": {
      "id": "llm_1706345678_newkey123abc",
      "name": "Production API Key",
      "description": "For the main application",
      "key": "llm_1706345678_newkey123abc",
      "permissions": [],
      "expiresAt": null,
      "createdAt": "2026-01-27T10:00:00.000Z",
      "isActive": true
    },
    "warning": "This is the only time the full API key will be shown. Please save it securely."
  }
  ```

  ```json バリデーションエラー (400) theme={null}
  {
    "message": "Validation error: Name is required"
  }
  ```
</ResponseExample>
