# Delete a file from a knowledge base

Source: [Delete a file from a knowledge base](<https://docs.gptunnel.ru/en/rag/file-delete/>)

<a id="_top"></a>
> **Note: API key access**
>
> Get an API key from your [personal or business profile](<https://docs.gptunnel.ru/en/#get-an-api-key>) and send it in the `Authorization` header.

 <a id="удаление-файла-из-rag"></a>
 
`POST https://gptunnel.ru/v1/database/file/delete`

Use the `databaseId` and `fileId` from the [list of files in the knowledge base](<https://docs.gptunnel.ru/en/rag/file-list/>). A successful response contains `success: true`. Request the file list again to verify the deletion.

### Request headers

| Parameter | Type | Description |
| --- | --- | --- |
| `Authorization` (required) | `string` | API key |

### Request parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `databaseId` (required) | `string` | Knowledge base ID |
| `fileId` (required) | `string` | File ID |
| `clearAssistants` | `boolean` | If true and no files with status ready remain after deletion, the API unlinks the knowledge base from its associated assistants and bots. By default, those links are preserved. |

<a id="example-request"></a>
## Example request

Set `GPTUNNEL_API_KEY` to your API key and `GPTUNNEL_DATABASE_ID` to the ID from the [list of knowledge bases](<https://docs.gptunnel.ru/en/rag/list/>). Set `GPTUNNEL_FILE_ID` to the file’s `id` from the [add file response](<https://docs.gptunnel.ru/en/rag/file-add/>). The cURL example requires version 8.3 or later.

<a id="tab-panel-0-0"></a>
**Python**

```python
import json
import os
from urllib.request import Request, urlopen

fields = {
    'databaseId': os.environ['GPTUNNEL_DATABASE_ID'],
    'fileId': os.environ['GPTUNNEL_FILE_ID'],
}
request = Request(
    'https://gptunnel.ru/v1/database/file/delete',
    headers={'Authorization': os.environ['GPTUNNEL_API_KEY'], 'Content-Type': 'application/json'},
    method='POST',
    data=json.dumps(fields).encode('utf-8'),
)
with urlopen(request, timeout=30) as response:
    print(json.load(response))
```

<a id="tab-panel-0-1"></a>
**cURL**

```bash
curl --fail-with-body \
  'https://gptunnel.ru/v1/database/file/delete' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --variable '%GPTUNNEL_DATABASE_ID' \
  --variable '%GPTUNNEL_FILE_ID' \
  --header 'Content-Type: application/json' \
  --expand-data '{"databaseId": "{{GPTUNNEL_DATABASE_ID:json}}", "fileId": "{{GPTUNNEL_FILE_ID:json}}"}'
```

<a id="tab-panel-0-2"></a>
**JavaScript (Node.js)**

```javascript
const key = process.env.GPTUNNEL_API_KEY
if (!key) throw new Error('Set GPTUNNEL_API_KEY')
const databaseId = process.env.GPTUNNEL_DATABASE_ID
if (!databaseId) throw new Error('Set GPTUNNEL_DATABASE_ID')
const fileId = process.env.GPTUNNEL_FILE_ID
if (!fileId) throw new Error('Set GPTUNNEL_FILE_ID')

const url = new URL('https://gptunnel.ru/v1/database/file/delete')
const response = await fetch(url, {
  method: 'POST',
  headers: { Authorization: key, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    databaseId,
    fileId,
  }),
})
if (!response.ok) throw new Error(await response.text())
console.log(await response.json())
```

<a id="example-response"></a>
## Example response

<a id="tab-panel-1-0"></a>
**200 OK**

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

<a id="tab-panel-1-1"></a>
**401 Unauthorized**

```json
{
  "error": {
    "message": "Unauthorized",
    "type": "unauthorized_request_error",
    "param": null,
    "code": null
  }
}
```
