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

# Create API Key

> This endpoint creates a new API key.

## POST /api-keys

This endpoint creates a new API key for the authenticated user. The full API key value is only shown once at creation time - make sure to save it securely.

<Warning>
  The full API key is only returned once during creation. Store it securely as it cannot be retrieved later.
</Warning>

### Request Body

<ParamField body="name" type="string" required>
  A descriptive name for the API key (1-100 characters).
</ParamField>

<ParamField body="description" type="string">
  A description of what the key will be used for (max 500 characters).
</ParamField>

<ParamField body="permissions" type="array">
  A list of permissions to grant to the key. Defaults to all permissions.
</ParamField>

<ParamField body="expiresAt" type="string">
  Optional expiration date in ISO 8601 format.
</ParamField>

### Response

<ResponseField name="success" type="boolean">
  Whether the key was created successfully.
</ResponseField>

<ResponseField name="message" type="string">
  A status message.
</ResponseField>

<ResponseField name="apiKey" type="object">
  The created API key details.

  <Expandable title="apiKey properties">
    <ResponseField name="id" type="string">
      The unique identifier for the API key.
    </ResponseField>

    <ResponseField name="name" type="string">
      The key name.
    </ResponseField>

    <ResponseField name="key" type="string">
      The full API key value (only shown once).
    </ResponseField>

    <ResponseField name="isActive" type="boolean">
      Whether the key is active.
    </ResponseField>

    <ResponseField name="createdAt" type="string">
      ISO 8601 timestamp of creation.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="warning" type="string">
  A reminder to save the key securely.
</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>
