# С чего начать?

## Для начала нужно получить API ключ

Чтобы работать с API и отправлять запросы, в первую очередь необходимо получить API ключ. Вы можете сгенерировать его во вкладке API в своем бизнес профиле [здесь](https://gptunnel.ru/profile/business).

Вы можете также получить API как физическое лицо. Для этого на форме регистрации бизнеса нажмите соответствующую кнопку.

{% hint style="info" %}
В рамках тестирования API можно использовать и персональный счет для списания средств. Для этого необходимо передать в запросе параметр useWalletBalance. Однако для работы в production мы рекомендуем использовать бизнес-счет.
{% endhint %}

## Отправь первый запрос

Чтобы сделать свой первый запрос, отправьте авторизованный запрос на `chat/completions`. В результате вы получите ответ от чата.

## Запрос в ChatGPT

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

Задает вопрос к ChatGPT

#### Headers

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

#### Request Body

| Name                                       | Type   | Description         |
| ------------------------------------------ | ------ | ------------------- |
| model<mark style="color:red;">\*</mark>    | string | Используемая модель |
| messages<mark style="color:red;">\*</mark> | array  | Контекст сообщений  |

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

```json
{
  "id": "chatcmpl-8FheRf68Hi4pnuiRqYPHyZJr3UlAU",
  "object": "chat.completion",
  "created": 1698753407,
  "model": "gpt-3.5-turbo-0613",
  "choices": [
    {
      "index": 0,
      "message": {
      	"role": "assistant",
        "content": "Меня зовут Robert."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 8,
    "total_tokens": 32,
    "prompt_cost": 0.01608,
    "completion_cost": 0.007200000000000001,
    "total_cost": 0.023280000000000002
    }
}
```

{% endtab %}
{% endtabs %}

Посмотрим на то, как вы могли бы вызвать этот метод:

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

```javascript
// require the axios module
const http = require('axios')

const request = axios({
  method: 'POST',
  url: 'https://gptunnel.ru/v1/chat/completions',
  headers: {
    // use your API key here
    Authorization: 'YOUR_API_KEY',
  },
  data: {
    model: "gpt-3.5-turbo",
    messages: [
      {
        role: "system",
        content: "My name is Robert.",
      },
      {
        role: "user",
        content: "как тебя зовут",
      },
    ],
  },
})

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

{% endtab %}

{% tab title="curl" %}

```bash
curl --request POST \
  --url https://gptunnel.ru/v1/chat/completions \
  --header 'Authorization: YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
	"model": "gpt-3.5-turbo",
	"messages": [
		{
			"role": "system",
			"content": "My name is Robert."
		},
		{
			"role": "user",
			"content": "как тебя зовут"
		}
	]
}'
```

{% 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/get-started.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.
