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

为当前认证用户创建新的 API Key。完整密钥仅在创建时返回一次，请务必安全保存。

<Warning>
  完整 API Key 仅在创建时展示一次，之后无法再次获取，请妥善保管。
</Warning>

### 请求体

<ParamField body="name" type="string" required>
  便于识别的名称（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">
  创建结果详情。

  <Expandable title="apiKey 字段">
    <ResponseField name="id" type="string">
      API Key 唯一标识。
    </ResponseField>

    <ResponseField name="name" type="string">
      密钥名称。
    </ResponseField>

    <ResponseField name="key" type="string">
      完整密钥（仅展示一次）。
    </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 Success (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 Validation Error (400) theme={null}
  {
    "message": "Validation error: Name is required"
  }
  ```
</ResponseExample>
