# Add file to RAG

{% hint style="info" %}
Чтобы отправлять авторизованные запросы нужно получить API ключ, как это сделать написано в разделе [**С чего начать?**](https://docs.gptunnel.ru/)
{% endhint %}

## Добавление файла в RAG

<mark style="color:green;">`POST`</mark> `https://gptunnel.ru/v1/database/file/add`

Запрос на добавление файла

#### Headers

| Name                                            | Type   | Description |
| ----------------------------------------------- | ------ | ----------- |
| Authorization<mark style="color:red;">\*</mark> | string | API ключ    |

#### Параметры запроса

| Name                                         | Type   | Description                                                             |
| -------------------------------------------- | ------ | ----------------------------------------------------------------------- |
| databaseId<mark style="color:red;">\*</mark> | string | ID базы данных                                                          |
| text<mark style="color:red;">\*</mark>       | string | Текст файла                                                             |
| name                                         | string | Имя файла                                                               |
| chunkSize                                    | number | Размер 1 фрагмента (по умолчанию 1024)                                  |
| overlapSize                                  | number | Размер перекрытия (по умолчанию 0)                                      |
| splitVariable                                | string | Разделитель (если указан, chunkSize и overlapSize будут игнорироваться) |

{% tabs %}
{% tab title="200: OK Успешный ответ" %}
{% code fullWidth="false" %}

```json
{
  "id": "66a346f64dcb57627c03d596",
  "createDate": "2024-07-26T06:49:27.430Z",
  "status": "idle",
  "name": "Test file",
  "databaseId": "669b1824c0d8dbde07d07d10",
  "chunkSize": 1024,
  "overlapSize": 0,
  "splitVariable": "|",
  "tokenCount": 0,
  "tokenCost": "0",
  "error": null,
  "progress": null,
  "chunkCount": 0
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized Ошибка авторизации" %}

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

{% endtab %}
{% endtabs %}

### Пример запроса

{% tabs %}
{% tab title="NodeJS" %}

```typescript
import axios from 'axios'

const request = axios({
  method: 'POST',
  url: 'https://gptunnel.ru/v1/database/file/add',
  headers: {
    // use your API key here
    Authorization: 'YOUR_API_KEY',
  },
  data: {
    databaseId: "669b1824c0d8dbde07d07d10",
    text: "Hello world",
    name: "Test file",
    splitVariable: "|"
  }
})

request.then((result) => {
  console.log(result)
}).catch((error) => {
  console.error(error)
})
```

{% endtab %}

{% tab title="Curl" %}

```bash
curl --request POST \
  --url https://gptunnel.ru/v1/database/file/add \
  --header 'Authorization: YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "databaseId": "669b1824c0d8dbde07d07d10",
    "text": "Hello world",
    "name": "Test file",
    "splitVariable": "|"
}'
```

{% endtab %}
{% endtabs %}

### Пример ответа

```json
{
  "id": "66a346f64dcb57627c03d596",
  "createDate": "2024-07-26T06:49:27.430Z",
  "status": "idle",
  "name": "Test file",
  "databaseId": "669b1824c0d8dbde07d07d10",
  "chunkSize": 1024,
  "overlapSize": 0,
  "splitVariable": "|",
  "tokenCount": 0,
  "tokenCost": "0",
  "error": null,
  "progress": null,
  "chunkCount": 0
}
```
