# Delete data source

Removes a source from the knowledge base; the original Catalog table or file is not deleted. Before deleting, confirm that there are no processing tasks still running on this source.

```text
DELETE https://moi.matrixorigin.cn/newmoi/semantic-models/{model_id}/sources/{source_row_id}
```

## Preparation before calling

First [query the data source list](list-data-sources.md) to obtain the source record ID, and confirm that there are no processing tasks still running in this source. Prepare a personal access token and target workspace ID that has access to the target workspace.

The example below uses:

- `$AI_STUDIO_API_KEY`: The actual personal access token, passed through the `X-API-Key` Header.
- `$WORKSPACE_ID`: Target workspace ID, passed through `X-Workspace-ID` Header.
- `$MODEL_ID`: Knowledge Base ID.
- `$SOURCE_ROW_ID`: Source record ID to be deleted.

## Request example

```bash
curl -X DELETE "https://moi.matrixorigin.cn/newmoi/semantic-models/$MODEL_ID/sources/$SOURCE_ROW_ID" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID"
```

## Path parameters

| Parameters | Type | Description |
| --- | --- | --- |
| `model_id` | integer | Knowledge base ID. |
| `source_row_id` | string | Source record ID. |

## Successful response

The source record was deleted when `code` was `OK` and `data.deleted` was `true` in the response.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "deleted": true
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data.deleted` | boolean | `true` indicates that the source record has been deleted. |

## Error response

```json
{
  "code": "ErrNotFound",
  "msg": "resource not found",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `ErrParamInvalid`
  - `model_id` is invalid or `source_row_id` is empty.
  - Query the source list again, using the returned `row_id`.
* - `401`
  - `ErrUnauthorized`
  - The API Key is invalid or has expired.
  - Check API Key.
* - `403`
  - `ErrForbidden`
  - The caller does not have permission to delete the source.
  - Check workspace and object authorization.
* - `404`
  - `ErrNotFound`
  - The knowledge base or source does not exist or is not visible to the current caller.
  - Reconfirm the path ID.
* - `500`
  - `ErrServer`
  - The service failed to delete the source.
  - Keep the desensitized response information and try again.
```

## Follow-up operations

[Query data source list](list-data-sources.md) Confirm that the source has been removed.
