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

# Update API Key

## Update API Key

Update an existing API key. Users can only update their own API keys.

<ParamField path="path" name="id" type="integer" required>
  API key ID
</ParamField>

## Request Body

<ParamField body name="api_key" type="object" required>
  API key object with fields to update

  <ParamField body name="name" type="string" optional>
    Descriptive name for the key
  </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>

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

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

  const data = await response.json();
  ```

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

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

  payload = {
      'api_key': {
          'name': 'Updated Production Key',
          'allowed_origins': ['https://example.com', 'https://app.example.com'],
          'allowed_assistants': ['123', '456']
      }
  }

  response = requests.put(
      f'https://api.example.com/api/v1/api_keys/{api_key_id}',
      headers=headers,
      json=payload
  )

  data = response.json()
  ```
</RequestExample>

## Response

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

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

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

<ResponseField name="data" type="object">
  Updated API key object
</ResponseField>

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

## Error Responses

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

<ResponseField name="404" type="object">
  API key not found
</ResponseField>

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