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

# Criar chave de API

> Este endpoint cria uma nova chave de API.

## POST /api-keys

Este endpoint cria uma nova chave de API para o usuário autenticado. O valor integral da chave só é exibido uma vez na criação — guarde-o com segurança.

<Warning>
  O valor completo da chave só é retornado na criação. Armazene-o com segurança; não é possível recuperá-lo depois.
</Warning>

### Corpo da requisição

<ParamField body="name" type="string" required>
  Nome descritivo da chave (1–100 caracteres).
</ParamField>

<ParamField body="description" type="string">
  Descrição do uso da chave (máximo 500 caracteres).
</ParamField>

<ParamField body="permissions" type="array">
  Lista de permissões concedidas à chave. Por padrão, todas as permissões.
</ParamField>

<ParamField body="expiresAt" type="string">
  Data opcional de expiração em formato ISO 8601.
</ParamField>

### Resposta

<ResponseField name="success" type="boolean">
  Se a chave foi criada com sucesso.
</ResponseField>

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

<ResponseField name="apiKey" type="object">
  Detalhes da chave criada.

  <Expandable title="Propriedades de apiKey">
    <ResponseField name="id" type="string">
      Identificador único da chave de API.
    </ResponseField>

    <ResponseField name="name" type="string">
      Nome da chave.
    </ResponseField>

    <ResponseField name="key" type="string">
      Valor completo da chave (exibido apenas uma vez).
    </ResponseField>

    <ResponseField name="isActive" type="boolean">
      Se a chave está ativa.
    </ResponseField>

    <ResponseField name="createdAt" type="string">
      Data de criação em ISO 8601.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="warning" type="string">
  Lembrete para salvar a chave com segurança.
</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 Sucesso (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 Erro de validação (400) theme={null}
  {
    "message": "Validation error: Name is required"
  }
  ```
</ResponseExample>
