🚢
API Docs
  • С чего начать?
  • Стоимость запросов
  • Интеграция чат-ботов
  • Токенизация
  • API - Ассистенты
    • Assistant API
    • Чат с ассистентом
  • API - Общие запросы
    • Запрос баланса
  • API - OpenAI -ChatGPT
    • Список моделей
    • Запрос чату
  • API - OpenAI - Embedding
    • embedding-ada-v2
    • text-embedding-3-small
    • text-embedding-3-large
  • Moderation
    • text-moderation
  • RAG DATABASE
    • List of RAGs
    • List of files
    • Add file to RAG
    • Delete file from RAG
  • FaceSwap 2.0
    • /create
    • /result
  • Background Remover
    • /create
    • /result
  • API -Midjourney
    • /imagine
    • /result
    • /upsample
    • /variation
    • /outpaint
    • /pan
    • /upscale
    • /inpaint
    • /reroll
Powered by GitBook
On this page
  • Диалог с чатом
  • Пример запроса
  • Пример ответа
  1. API - OpenAI -ChatGPT

Запрос чату

Отправить синхронный запрос и получить ответ от ChatGPT

PreviousСписок моделейNextembedding-ada-v2

Last updated 1 year ago

Чтобы отправлять авторизованные запросы нужно получить API ключ, как это сделать написано в разделе

Диалог с чатом

POST https://gptunnel.ru/v1/chat/completions

Синхронный запрос к моделям ChatGPT

Headers

Name
Type
Description

Authorization*

string

API ключ

Request Body

Name
Type
Description

model*

string

ID модели чата

messages*

array

Контекст сообщений

max_tokens

number

Длина ответа (MAX 4096)

temperature

number

Креативность (от 0 до 1)

top_p

number

frequency_penalty

number

presence_penalty

number

functions

object

useWalletBalance

bool

Использовать личный счет

{
  "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
    }
}
{
  "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,
  }
}

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

import axios from '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",
    max_tokens: 100,
    messages: [
      {
        role: "system",
        content: "My name is Robert.",
      },
      {
        role: "user",
        content: "как тебя зовут",
      },
    ],
  },
})

request.then((result) => {
  console.log(result)
}).catch((error) => {
  console.error(error)
})
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",
	"max_tokens": 100,
	"messages": [
		{
			"role": "system",
			"content": "My name is Robert."
		},
		{
			"role": "user",
			"content": "как тебя зовут"
		}
	]
}'

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

{
  "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
    }
}

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