# List files and check their status

Source: [List files and check their status](<https://docs.gptunnel.ru/en/rag/file-list/>)

<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="получить-список-файлов"></a>
 
`GET https://gptunnel.ru/v1/database/file/list`

**List all files.** Pass `databaseId` to retrieve the files in one knowledge base.

**Check one file.** Also pass `fileId` to retrieve an array with one entry. If the file is not found, the API returns HTTP `404`.

After you [add a file](<https://docs.gptunnel.ru/en/rag/file-add/>), use its `id` to poll for updates. When `status` is `ready`, processing is complete. Check `progress` while the file is processing and `error` if processing fails.

### Request headers

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

### Request parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `databaseId` (required) | `string` | ID Knowledge base |
| `fileId` | `string` | File ID |

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

Set `GPTUNNEL_API_KEY` to your API key. Set `GPTUNNEL_DATABASE_ID` to the ID from the [list of knowledge bases](<https://docs.gptunnel.ru/en/rag/list/>) and `GPTUNNEL_FILE_ID` to the file’s `id` from the [add file response](<https://docs.gptunnel.ru/en/rag/file-add/>). This example retrieves one file. To list every file in the knowledge base, send only `databaseId`.

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

```python
import json
import os
from urllib.parse import urlencode
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/list' + '?' + urlencode(fields),
    headers={'Authorization': os.environ['GPTUNNEL_API_KEY']},
)
with urlopen(request, timeout=30) as response:
    print(json.load(response))
```

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

```bash
curl --fail-with-body \
  --get 'https://gptunnel.ru/v1/database/file/list' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --data-urlencode "databaseId=${GPTUNNEL_DATABASE_ID:?Set GPTUNNEL_DATABASE_ID}" \
  --data-urlencode "fileId=${GPTUNNEL_FILE_ID:?Set GPTUNNEL_FILE_ID}"
```

<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/list')
url.searchParams.set('databaseId', databaseId)
url.searchParams.set('fileId', fileId)
const response = await fetch(url, { headers: { Authorization: key } })
if (!response.ok) throw new Error(await response.text())
console.log(await response.json())
```

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

Example of a separate file processed with the divider `|` The values may differ from the file added on the previous page.

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

```json
[
  {
    "id": "66a346f64dcb57627c03d596",
    "createDate": "2024-07-26T06:49:27.430Z",
    "status": "ready",
    "name": "Split check",
    "databaseId": "669b1824c0d8dbde07d07d10",
    "chunkSize": 1024,
    "overlapSize": 0,
    "splitVariable": "|",
    "tokenCount": 6,
    "tokenCost": "0.0003",
    "error": null,
    "progress": 100,
    "chunkCount": 3
  }
]
```

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

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