---
type: api
title: Delete an AI Index
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/operation/operation-delete-context-engine-ai-index-aiindexid
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/operation/operation-delete-context-engine-ai-index-aiindexid
products:
  - Kibana
---

# Delete an AI Index

Availability:

- Server: `https://{kibana_url}`

## Paths

- `DELETE` `/api/context_engine/ai_index/{aiIndexId}`
- `DELETE` `/s/{space_id}/api/context_engine/ai_index/{aiIndexId}`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/authentication#apikeyauth)

#### Path Parameters

- `aiIndexId` (string · min: 1 · max: 256)
  The unique identifier of the AI Index.

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Deletes an AI Index by ID.

By default, the API preserves the backing data stream or index, its Knowledge Indicators, and attached workflow automations. Set `delete_knowledge_indicators` to `true` to delete the backing data stream or index and its Knowledge Indicators. Set `delete_automations` to `true` to delete the attached workflow automations.

The API does not delete the backing data stream or index when another AI Index uses the same destination.

Returns a 404 response when Context Engine is turned off in this space (`contextEngine:enabled`).

**For more information, refer to the [Context Engine documentation](https://www.elastic.co/docs/explore-analyze/ai-features/context-engine).**<br/><br/>[Required authorization] Route required privileges: contextEngine:write. Extended privileges (optional, expand functionality when granted): workflowsManagement:delete.

## Query String Parameters

- `delete_knowledge_indicators` (boolean · default: false)
  When true, also delete the backing data stream/index, which removes its Knowledge Indicators. Skipped when another AI Index still uses the same dest. Defaults to false.
- `delete_automations` (boolean · default: false)
  When true, also delete the attached workflow automations. Defaults to false.

## Responses

#### `200`

The AI Index entry was deleted. `errors` lists any best-effort cleanup failures.

`application/json`

- `acknowledged` (boolean)
  Whether the AI Index entry was deleted.
- `errors` ([] string)
  Best-effort cleanup errors after the entry was deleted, if any.
#### `404`

No AI Index with the given ID exists in the current space, or Context Engine is turned off in this space.

`application/json`

- `error` (string)
  The HTTP status text.
- `message` (string)
  A human-readable error message.
- `statusCode` (number)
  The HTTP status code.
#### `409`

The AI Index is managed and cannot be deleted.

`application/json`

- `error` (string)
  The HTTP status text.
- `message` (string)
  A human-readable error message.
- `statusCode` (number)
  The HTTP status code.
## Code Examples

#### Console

```console
DELETE kbn:/api/context_engine/ai_index/customer_support?delete_knowledge_indicators=true
```

#### curl

```curl
curl \
  -X DELETE "https://${KIBANA_URL}/api/context_engine/ai_index/customer_support?delete_knowledge_indicators=true" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "kbn-xsrf: true"
```

## Response Examples

#### Deleted with a cleanup error

The entry was deleted but a best-effort cleanup step failed

```json
{
  "acknowledged": true,
  "errors": [
    "Failed to delete automations: Workflows management is unavailable."
  ]
}
```

#### AI Index deleted

Example response after the AI Index entry is deleted

```json
{
  "acknowledged": true,
  "errors": []
}
```

#### Context Engine turned off

Context Engine is turned off in this space

```json
{
  "error": "Not Found",
  "message": "Not Found",
  "statusCode": 404
}
```

#### AI Index not found

No AI Index with the given ID exists in the current space

```json
{
  "error": "Not Found",
  "message": "AI index \u0027customer_support\u0027 not found",
  "statusCode": 404
}
```

#### Managed AI Index

The AI Index is managed by a plugin and cannot be deleted

```json
{
  "error": "Conflict",
  "message": "AI index \u0027customer_support\u0027 is managed and cannot be modified via the API",
  "statusCode": 409
}
```

