Запрос чату
Диалог с чатом
POST
https://gptunnel.ru/v1/chat/completions Синхронный запрос к моделям ChatGPT.
Headers
| Параметр | Тип | Описание |
|---|---|---|
Authorization* | string | API ключ |
Request Body
| Параметр | Тип | Описание |
|---|---|---|
model* | string | ID модели чата |
messages* | array | Контекст сообщений |
max_tokens | number | Длина ответа (макс. 4096) |
temperature | number | Креативность (от 0 до 1) |
top_p | number | Nucleus sampling |
frequency_penalty | number | Штраф за повторение |
presence_penalty | number | Штраф за присутствие |
functions | object | Определения функций |
useWalletBalance | bool | Использовать личный счёт |
Пример запроса
import axios from 'axios'
const response = await axios({ method: 'POST', url: 'https://gptunnel.ru/v1/chat/completions', headers: { Authorization: 'YOUR_API_KEY', }, data: { model: 'gpt-4o', max_tokens: 100, messages: [ { role: 'system', content: 'My name is Robert.' }, { role: 'user', content: 'Как тебя зовут?' }, ], },})
console.log(response.data)import requests
response = requests.post( 'https://gptunnel.ru/v1/chat/completions', headers={'Authorization': 'YOUR_API_KEY'}, json={ 'model': 'gpt-4o', 'max_tokens': 100, 'messages': [ {'role': 'system', 'content': 'My name is Robert.'}, {'role': 'user', 'content': 'Как тебя зовут?'}, ], },)
print(response.json())curl -X POST https://gptunnel.ru/v1/chat/completions \ -H 'Authorization: YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "model": "gpt-4o", "max_tokens": 100, "messages": [ {"role": "system", "content": "My name is Robert."}, {"role": "user", "content": "Как тебя зовут?"} ] }'Пример ответа
{ "id": "chatcmpl-8FheRf68Hi4pnuiRqYPHyZJr3UlAU", "object": "chat.completion", "created": 1698753407, "model": "gpt-4o", "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.0072, "total_cost": 0.02328 }}Ошибки
{ "error": { "message": "The model 'gpt-5' does not exist", "type": "invalid_request_error", "param": null, "code": "model_not_found" }}{ "error": { "message": "'model' is a required property", "type": "invalid_request_error", "param": null, "code": null }}{ "error": { "message": "Organization balance is too low to use API", "type": "insufficient_balance_error", "param": null, "code": null }}{ "error": { "message": "Unauthorized", "type": "unauthorized_request_error", "param": null, "code": null }}