Справочник Gonka API
Полный справочник API GonkaGate. OpenAI-совместимые эндпоинты с документацией параметров.
Base URL
Все API запросы должны отправляться на:
https://api.gonkagate.com/v1Аутентификация
Авторизуйте API запросы с помощью Bearer токена в заголовке Authorization.
Authorization: Bearer YOUR_API_KEYЭндпоинты
Создать Chat Completion
/chat/completionsСоздаёт ответ для чат-диалога.
Тело запроса
model- Тип
- string
- Обязателен
- Да
- По умолчанию
- —
- Описание
- Model ID (e.g., Qwen/Qwen3-32B-FP8)
messages- Тип
- array
- Обязателен
- Да
- По умолчанию
- —
- Описание
- Array of message objects with role and content
stream- Тип
- boolean
- Обязателен
- Нет
- По умолчанию
- false
- Описание
- Enable streaming responses
temperature- Тип
- number
- Обязателен
- Нет
- По умолчанию
- 1.0
- Описание
- Sampling temperature (0-2)
max_tokens- Тип
- integer
- Обязателен
- Нет
- По умолчанию
- 4096
- Описание
- Maximum tokens in response
top_p- Тип
- number
- Обязателен
- Нет
- По умолчанию
- 1.0
- Описание
- Nucleus sampling threshold
stop- Тип
- string | array
- Обязателен
- Нет
- По умолчанию
- null
- Описание
- Stop sequences
Ответ
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1735500000,
"model": "Qwen/Qwen3-32B-FP8",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 10,
"total_tokens": 35,
"base_cost_usd": 0.000175,
"platform_fee_usd": 0.0000175,
"total_cost_usd": 0.0001925
}
}Примеры кода
from openai import OpenAI
client = OpenAI(
base_url="https://api.gonkagate.com/v1",
api_key="your-gonkagate-api-key"
)
response = client.chat.completions.create(
model="Qwen/Qwen3-32B-FP8",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
temperature=0.7,
max_tokens=1000
)
print(response.choices[0].message.content)
print(f"Usage: {response.usage.total_tokens} tokens")Список моделей
/modelsВозвращает список доступных моделей.
Ответ
{
"data": [
{
"id": "Qwen/Qwen3-235B-A22B-Instruct-2507-FP8",
"name": "Qwen3 235B A22B Instruct 2507 FP8",
"description": "A powerful 235B parameter model for complex reasoning tasks.",
"context_length": 131072,
"pricing": {
"prompt": "0.000000350",
"completion": "0.000000350"
}
},
{
"id": "Qwen/QwQ-32B",
"name": "QwQ 32B",
"description": "Compact reasoning model with strong logic capabilities.",
"context_length": 32768,
"pricing": {
"prompt": "0.000000580",
"completion": "0.000000580"
}
}
]
}Примеры кода
import requests
response = requests.get(
"https://api.gonkagate.com/v1/models",
headers={"Authorization": "Bearer your-gonkagate-api-key"}
)
models = response.json()["data"]
for model in models:
price_per_m = float(model["pricing"]["prompt"]) * 1_000_000
print(f"{model['name']}: ${price_per_m:.2f}/1M tokens")Параметры
Полный справочник параметров запроса.
Совместимость с OpenAI
model- Тип
- string
- Обязателен
- Да
- По умолчанию
- —
- Описание
Model ID to use for completion
The model ID specifies which Gonka Network model to use. Example: `Qwen/Qwen3-32B-FP8`.
messages- Тип
- array
- Обязателен
- Да
- По умолчанию
- —
- Описание
Array of message objects with `role` and `content`
A list of messages comprising the conversation. Each message has a `role` (system, user, assistant, or tool) and `content`. See Messages Schema below for full structure.
stream- Тип
- boolean
- Обязателен
- Нет
- По умолчанию
- false
- Описание
Enable streaming responses
If true, partial message deltas are sent as Server-Sent Events (SSE). Tokens are sent as they become available.
max_tokens- Тип
- integer
- Обязателен
- Нет
- По умолчанию
- 4096
- Описание
Maximum tokens in response
The maximum number of tokens to generate. The model will stop when this limit is reached.
Ограничения: 1 to context window size
Схема массива messages
Схема массива messages
Структура параметра messages. Каждое сообщение — объект с role и content.
role- Тип
- string
- Обязательно
- Да
- Описание
The role of the message author
Допустимые значения:
system,user,assistant,developer
content- Тип
- string | null
- Обязательно
- Да
- Описание
The message content. Can be null for assistant messages with tool_calls.
name- Тип
- string
- Обязательно
- Нет
- Описание
Optional name for the participant. Useful for multi-agent conversations.
tool_calls- Тип
- array
- Обязательно
- Нет
- Описание
Tool calls made by the assistant. Only present in assistant messages.
tool_call_id- Тип
- string
- Обязательно
- Нет
- Описание
ID of the tool call this message is responding to. Required for tool role.
Примеры
[
{
"role": "user",
"content": "Hello!"
}
]Схемы ответов
Структура API ответов.
Ответ Chat Completion
Ответ Chat Completion
| Поле | Тип | Описание |
|---|---|---|
id | string | Unique identifier for the completion |
object | string | Always "chat.completion" |
created | integer | Unix timestamp when created |
model | string | Model used for the completion |
choices | array | Array of completion choices |
index | integer | Index of this choice |
message | object | The generated message |
role | string | Always "assistant" |
content | string | null | The generated text |
tool_calls | array | Tool calls (if any) |
finish_reason | string | "stop", "length", "tool_calls", or "content_filter" |
usage | object | Token usage and cost statistics |
prompt_tokens | integer | Tokens in the input prompt |
completion_tokens | integer | Tokens in the response |
total_tokens | integer | Total tokens used |
base_cost_usd | number | Base cost before platform fee (USD) |
platform_fee_usd | number | Platform fee — 10% of base cost (USD) |
total_cost_usd | number | Total cost deducted from balance (USD) |
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1735500000,
"model": "Qwen/Qwen3-32B-FP8",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 10,
"total_tokens": 35,
"base_cost_usd": 0.000175,
"platform_fee_usd": 0.0000175,
"total_cost_usd": 0.0001925
}
}Streaming ответ
При stream: true ответы отправляются как Server-Sent Events (SSE).
Формат чанка
| Поле | Тип | Описание |
|---|---|---|
id | string | Same ID for all chunks in a stream |
object | string | Always "chat.completion.chunk" |
created | integer | Unix timestamp |
model | string | Model used |
choices | array | Array with incremental content |
index | integer | Choice index |
delta | object | Incremental content |
role | string | Role (first chunk only) |
content | string | Text content to append |
finish_reason | string | null | null until final chunk, then "stop" |
usage | object | undefined | Token usage and cost (only in final chunk before [DONE]) |
prompt_tokens | integer | Tokens in the input prompt |
completion_tokens | integer | Tokens in the response |
total_tokens | integer | Total tokens used |
base_cost_usd | number | Base cost before platform fee (USD) |
platform_fee_usd | number | Platform fee — 10% of base cost (USD) |
total_cost_usd | number | Total cost deducted from balance (USD) |
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","created":1735500000,"model":"Qwen/Qwen3-32B-FP8","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","created":1735500000,"model":"Qwen/Qwen3-32B-FP8","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","created":1735500000,"model":"Qwen/Qwen3-32B-FP8","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","created":1735500000,"model":"Qwen/Qwen3-32B-FP8","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":10,"completion_tokens":5,"total_tokens":15,"base_cost_usd":0.000075,"platform_fee_usd":0.0000075,"total_cost_usd":0.0000825}}
data: [DONE]Ответ списка моделей
Ответ списка моделей
| Поле | Тип | Описание |
|---|---|---|
data | array | Array of model objects |
id | string | Model identifier for API requests |
name | string | Human-readable model name |
description | string | null | Model description (from HuggingFace) |
context_length | number | null | Maximum context window in tokens |
pricing | object | Cost per token in USD |
prompt | string | Cost per input token in USD |
completion | string | Cost per output token in USD |
{
"data": [
{
"id": "Qwen/Qwen3-235B-A22B-Instruct-2507-FP8",
"name": "Qwen3 235B A22B Instruct 2507 FP8",
"description": "A powerful 235B parameter model for complex reasoning tasks.",
"context_length": 131072,
"pricing": {
"prompt": "0.000000350",
"completion": "0.000000350"
}
},
{
"id": "Qwen/QwQ-32B",
"name": "QwQ 32B",
"description": "Compact reasoning model with strong logic capabilities.",
"context_length": 32768,
"pricing": {
"prompt": "0.000000580",
"completion": "0.000000580"
}
}
]
}Коды ошибок
GonkaGate использует стандартные HTTP коды и OpenAI-совместимые ответы об ошибках. Нажмите на ошибку, чтобы увидеть причины, решения и пример ответа.
HTTP коды статусов
Все возможные ответы об ошибках API с их значениями.
Обработка ошибок
Реализуйте логику повторных попыток с экспоненциальной задержкой для rate limits и серверных ошибок. Клиентские ошибки (4xx кроме 429) повторять не нужно.
import openai
import time
client = openai.OpenAI(
api_key="your-gonkagate-api-key",
base_url="https://api.gonkagate.com/v1"
)
def chat_with_retry(messages, max_retries=3):
"""Make API request with exponential backoff retry logic."""
for attempt in range(max_retries):
try:
response = client.chat.completions.create(
model="Qwen/Qwen3-32B-FP8",
messages=messages
)
return response.choices[0].message.content
except openai.RateLimitError as e:
# 429: Wait and retry with exponential backoff
wait_time = 2 ** attempt
print(f"Rate limited. Waiting {wait_time}s...")
time.sleep(wait_time)
except openai.AuthenticationError as e:
# 401: Invalid API key - don't retry
print(f"Auth error: {e.message}")
raise
except openai.BadRequestError as e:
# 400: Invalid request - don't retry
print(f"Bad request: {e.message}")
raise
except openai.APIStatusError as e:
# 5xx: Server error - retry with backoff
if e.status_code >= 500:
wait_time = 2 ** attempt
print(f"Server error {e.status_code}. Retrying in {wait_time}s...")
time.sleep(wait_time)
else:
raise
raise Exception("Max retries exceeded")
# Usage
result = chat_with_retry([{"role": "user", "content": "Hello!"}])
print(result)Лимиты запросов
Лимиты API применяются на IP-адрес для обеспечения справедливого использования.
| Лимит | Значение | Область |
|---|---|---|
| Запросов в минуту | 100 | На IP |
| Токенов в минуту | 100,000 | На IP |
| Запросов в день | 10,000 | На IP |
При превышении лимита проверьте заголовок Retry-After для времени ожидания. Реализуйте экспоненциальную задержку для повторных попыток.
Предупреждение о низком балансе
Когда ваш баланс опускается ниже $5, вы увидите предупреждение в Dashboard. Рекомендуем пополнить баланс, чтобы избежать прерывания сервиса.