# Update an AI provider credential.

`PUT /api/ai-chat/credentials/{id}`

Authentication: no security requirement declared for this operation.

Parameters:

- `id` (path, string, required)
  Type: string

Request body: application/json (required)

Type: object

Schema: [UpdateAiProviderCredentialDTO](https://sourcey-gauzy.pages.dev/api-reference/models/updateaiprovidercredentialdto/index.md)

- `tenant` (optional)
  Type: object

- `tenantId` (optional)
  Type: string

- `organization` (optional)
  Type: object

- `organizationId` (optional)
  Type: string

- `sentTo` (optional)
  Type: string

- `providerId` (optional)
  Type: string
  
  AI provider identifier (e.g. anthropic, openai)

- `apiKey` (optional)
  Type: string
  
  Secret API key (write-only; stored encrypted). Required unless the provider runs without one (local servers).

- `baseUrl` (optional)
  Type: string
  
  Custom base URL for the provider API

- `enabled` (optional)
  Type: boolean
  
  Whether this credential is active
  
  default: true

- `isDefault` (optional)
  Type: boolean
  
  Whether this provider is the tenant's default for chat
  
  default: false

- `defaultModel` (optional)
  Type: string; nullable
  
  Preferred default model id (e.g. claude-sonnet-5); null clears the stored model

- `isVoiceDefault` (optional)
  Type: boolean
  
  Whether this provider is the tenant's default voice (dictation) provider
  
  default: false

- `speechModel` (optional)
  Type: string; nullable
  
  Preferred speech-to-text model id (e.g. whisper-1); null clears the stored model

Responses:

- 200: The credential has been successfully updated. The API key is returned masked.

- 404: Record not found

## Examples

### cURL

```bash
curl -X PUT 'http://localhost:3000/api/ai-chat/credentials/string' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "tenant": {},
  "tenantId": "string",
  "organization": {},
  "organizationId": "string",
  "sentTo": "string",
  "providerId": "string",
  "apiKey": "string",
  "baseUrl": "string",
  "enabled": true,
  "isDefault": false,
  "defaultModel": "string",
  "isVoiceDefault": false,
  "speechModel": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "tenant": {},
  "tenantId": "string",
  "organization": {},
  "organizationId": "string",
  "sentTo": "string",
  "providerId": "string",
  "apiKey": "string",
  "baseUrl": "string",
  "enabled": true,
  "isDefault": false,
  "defaultModel": "string",
  "isVoiceDefault": false,
  "speechModel": "string"
}`;

const response = await fetch('http://localhost:3000/api/ai-chat/credentials/string', {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "tenant": {},
  "tenantId": "string",
  "organization": {},
  "organizationId": "string",
  "sentTo": "string",
  "providerId": "string",
  "apiKey": "string",
  "baseUrl": "string",
  "enabled": true,
  "isDefault": false,
  "defaultModel": "string",
  "isVoiceDefault": false,
  "speechModel": "string"
}'''

response = requests.put(
    'http://localhost:3000/api/ai-chat/credentials/string',
    data=body.encode('utf-8'),
    headers={
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
