# Чат с ассистентом

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

## Запрос

<mark style="color:green;">`POST`</mark> `https://gptunnel.ru/v1/assistant/chat`

Запрос вернет ответ ассистента в контексте чата

#### Request Body

| Name                                            | Type           | Description                                                                          |
| ----------------------------------------------- | -------------- | ------------------------------------------------------------------------------------ |
| chatId<mark style="color:red;">\*</mark>        | string         | Уникальный ID чата создается на стороне клиента и может содержать от 24 до 36 знаков |
| assistantCode<mark style="color:red;">\*</mark> | string         | Код ассистента может быть изменен в настройках ассистента                            |
| message<mark style="color:red;">\*</mark>       | string         | Сообщение ассистенту                                                                 |
| maxContext                                      | number         | Количество сообщений чата, которое нужно помнить (по умолчанию 0)                    |
| images                                          | Array\<string> | Массив ссылок на изображения для Vision                                              |
| stream                                          | boolean        | Экспериментальная опция -  чат будет присылать ответы в стриме                       |

#### Headers

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

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

```json
{
  "id": "66c6dcf2e2826d0001f48d37",
  "chatId": "a11e52c2-5ecc-4d86-a9fa-0cac92414a72",
  "assistantId": "66c6e3d09d2eba00010257ff",
  "assistantCode": "ai08158128",
  "message": "Hello! How can I assist you today?",
  "model": "gpt-4o",
  "usage": {
    "context_messages": 2,
    "prompt_tokens": 111,
    "completion_tokens": 10,
  "embedding_tokens": 0,
  "total_tokens": 121,
  "prompt_cost": 0.14985,
  "completion_cost": 0.027,
  "embedding_cost": 0,
  "total_cost": 0.17685
  }
}
```

{% endcode %}
{% endtab %}

{% tab title="404" %}

```json
{
  "error": {
    "param": null,
    "code": null,
    "type": "invalid_request_error",
    "message": "Assistant not found"
  }
}
```

{% endtab %}

{% tab title="401" %}

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

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gptunnel.ru/assistant/chat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
