
## Delete a key's model

`DELETE /v1/ai/credentials/:credId/models/:modelRowId`

Deletes one model bound to a BYOK key. After deletion the model disappears from [`GET /v1/models`](/docs/ai/models/list), and requests to it via [`/v1/chat/completions`](/docs/ai/chat/completions) return `404 ai_model_not_found`. The call history in `AiUsageLog` is preserved.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|----------|
| `credId` (path) | string | yes | Key ID from [`GET /v1/ai/credentials`](./list.md) |
| `modelRowId` (path) | string | yes | Model record ID (`data[].id`) from [`GET /v1/ai/credentials/:id/models`](./models-list.md) — this is **not** the `modelId`, but the primary key of the `AiModel` record |

## Examples

### curl — personal key

```bash
curl -X DELETE https://vibecode.bitrix24.com/v1/ai/credentials/cred_custom_xyz/models/aimodel_xyz789 \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X DELETE https://vibecode.bitrix24.com/v1/ai/credentials/cred_custom_xyz/models/aimodel_xyz789 \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const credId = 'cred_custom_xyz'
const modelRowId = 'aimodel_xyz789'
const res = await fetch(
  `https://vibecode.bitrix24.com/v1/ai/credentials/${credId}/models/${modelRowId}`,
  { method: 'DELETE', headers: { 'X-Api-Key': 'YOUR_API_KEY' } },
)

const { success } = await res.json()
if (success) console.log('Model removed from the key catalog')
```

### JavaScript — OAuth application

```javascript
const credId = 'cred_custom_xyz'
const modelRowId = 'aimodel_xyz789'
const res = await fetch(
  `https://vibecode.bitrix24.com/v1/ai/credentials/${credId}/models/${modelRowId}`,
  {
    method: 'DELETE',
    headers: {
      'X-Api-Key': 'YOUR_APP_KEY',
      'Authorization': 'Bearer USER_SESSION_TOKEN',
    },
  },
)

if ((await res.json()).success) console.log('OK')
```

## Response fields

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | Always `true` on success |

## Response example

HTTP status `200 OK`:

```json
{
  "success": true
}
```

## Error response example

`404 not_found` — the key or model was not found, or the key belongs to another user:

```json
{
  "success": false,
  "error": {
    "code": "not_found",
    "message": "Credential not found"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 404 | `not_found` | A key with this `credId` was not found / does not belong to you, or a model with this `modelRowId` is not bound to the key |
| 403 | `scope_missing` | The API key lacks the `vibe:ai` scope |

Full list of common API errors — [Errors](/docs/errors).

Model deletion limit: 30 requests per minute.

## Known specifics

**`modelRowId` is the record's primary key, not `modelId`.** The same `modelId` can occur across different keys (the identical `gpt-4o` model on two BYOKs), so deletion is keyed by the unique `id` of the `AiModel` record. Get it from [`GET /v1/ai/credentials/:id/models`](./models-list.md), the `data[].id` field.

**Call history is preserved.** `AiUsageLog` records are not deleted — statistics for this model over past periods remain in [`GET /v1/ai/usage`](/docs/ai/consumption/usage). The `modelId` and `providerId` fields in the logs are stored as strings, without an `FK` relation to the `AiModel` table.

**Don't confuse it with `DEPRECATED`.** A model in the `DEPRECATED` status still works — it is simply not recommended for use. A deleted model disappears entirely: requests to its `modelId` return `404 ai_model_not_found`. To mark a model as deprecated instead of deleting it, contact the Bitrix24 account administrator.

**Cascade deletion with the key.** If you delete the key itself via [`DELETE /v1/ai/credentials/:id`](./delete.md) — all bound models are deleted along with it. This endpoint is for removing one model while keeping the rest.

## See also

- [List a key's models](./models-list.md)
- [Delete a key](./delete.md)
- [Fetch the model catalog](./fetch-models.md)
