# Set Anthropic API key

> Source: https://docs.clonepartner.com/api-reference/server/put-server-ai-config/

`PUT /api/server/ai-config`

Validates the key with Anthropic, then stores it encrypted as a Settings override (takes precedence over yaml).

**Operation ID:** `putServerAiConfig`

## Authentication

### Option 1

- **BearerAuth** (`http bearer`)
  API key token. Create via POST /api/api-keys. Format: `envoy_<hex>`

### Option 2

- **CookieAuth** (`apiKey`)
  Session cookie set after login + TOTP verification

## Request body

The request body is required.

### `application/json`

- Type: `object`
- Properties:
  - `api_key` (`string`, `required`)

## Success responses

### 200

Key saved

**Content type:** `application/json`

- Type: `object`
- Properties:
  - `configured` (`boolean`)
  - `source` (`string`)
    - Allowed values: `settings`, `yaml`
  - `default_model` (`string`)

## Error responses

### 400

Missing api_key (VALIDATION_ERROR) or key rejected by Anthropic (INVALID_KEY)


### 403

Requires admin or superadmin


### 502

Anthropic unreachable — key not validated or persisted (ANTHROPIC_UNREACHABLE)


## Examples

### cURL

```bash
curl --request PUT \
  --url 'https://your-envoy.example.com/api/server/ai-config' \
  --header 'Authorization: Bearer $API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "api_key": "string"
}'
```

### JavaScript (fetch)

```javascript
const response = await fetch('https://your-envoy.example.com/api/server/ai-config', {
  method: 'PUT',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "api_key": "string"
  }),
});

if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = response.status === 204 ? null : await response.json();
console.log(data);
```
