> ## Documentation Index
> Fetch the complete documentation index at: https://docs.voiceable.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Create API Key

## Create API Key

Create a new API key for the authenticated user. The key\_value will only be returned on creation.

## Request Body

<ParamField body name="api_key" type="object" required>
  API key object

  <ParamField body name="name" type="string" required>
    Descriptive name for the key
  </ParamField>

  <ParamField body name="key_type" type="string" required>
    Type of key: 'private' or 'public'
  </ParamField>

  <ParamField body name="allowed_origins" type="array" optional>
    Array of allowed CORS origins
  </ParamField>

  <ParamField body name="allowed_assistants" type="array" optional>
    Array of assistant IDs the key can access
  </ParamField>

  <ParamField body name="transient_assistant" type="boolean" optional default="false">
    Whether the key supports transient assistants
  </ParamField>
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.example.com/api/v1/api_keys" \
    -H "X-API-Key: your-api-key-here" \
    -H "Content-Type: application/json" \
    -d '{
      "api_key": {
        "name": "Production API Key",
        "key_type": "private",
        "allowed_origins": ["https://example.com"],
        "allowed_assistants": ["123"],
        "transient_assistant": false
      }
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.example.com/api/v1/api_keys', {
    method: 'POST',
    headers: {
      'X-API-Key': 'your-api-key-here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      api_key: {
        name: 'Production API Key',
        key_type: 'private',
        allowed_origins: ['https://example.com'],
        allowed_assistants: ['123'],
        transient_assistant: false
      }
    })
  });

  const data = await response.json();
  // IMPORTANT: Save the key_value from the response immediately
  console.log('API Key:', data.data.key_value);
  ```

  ```python Python theme={null}
  import requests

  headers = {
      'X-API-Key': 'your-api-key-here',
      'Content-Type': 'application/json'
  }

  payload = {
      'api_key': {
          'name': 'Production API Key',
          'key_type': 'private',
          'allowed_origins': ['https://example.com'],
          'allowed_assistants': ['123'],
          'transient_assistant': False
      }
  }

  response = requests.post(
      'https://api.example.com/api/v1/api_keys',
      headers=headers,
      json=payload
  )

  data = response.json()
  # IMPORTANT: Save the key_value from the response immediately
  api_key = data['data']['key_value']
  ```
</RequestExample>

## Response

<ResponseField name="status" type="object">
  Response status information

  <ResponseField name="code" type="integer">
    HTTP status code (201)
  </ResponseField>

  <ResponseField name="message" type="string">
    Status message
  </ResponseField>
</ResponseField>

<ResponseField name="data" type="object">
  Created API key object (includes key\_value only on creation)
</ResponseField>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "status": {
      "code": 201,
      "message": "API key created successfully"
    },
    "data": {
      "id": 1,
      "key_type": "private",
      "name": "Production API Key",
      "key_value": "sk_live_abc123xyz789",
      "allowed_origins": ["https://example.com"],
      "allowed_assistants": ["123"],
      "transient_assistant": false,
      "user_id": 1,
      "user_email": "user@example.com",
      "created_at": "2024-01-15T10:30:00Z",
      "updated_at": "2024-01-15T10:30:00Z"
    }
  }
  ```
</ResponseExample>

<Warning>
  The `key_value` is only returned when creating a new API key. Store it securely immediately as it cannot be retrieved later.
</Warning>

## Error Responses

<ResponseField name="401" type="object">
  Unauthorized - Invalid or missing authentication
</ResponseField>

<ResponseField name="422" type="object">
  Validation error - Invalid request body
</ResponseField>
