Chat Completions
Используйте Chat Completions для text chat, vision input, streaming, JSON output и tool calling.
text
POST https://api.rout.my/v1/chat/completionsЗапрос
bash
curl https://api.rout.my/v1/chat/completions \
-H "Authorization: Bearer $ROUTMY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "provider/model-id",
"messages": [
{ "role": "system", "content": "Answer briefly." },
{ "role": "user", "content": "What does this endpoint do?" }
],
"temperature": 0.7,
"max_tokens": 256
}'Поля запроса
| Поле | Тип | Обязательное | Примечания |
|---|---|---|---|
model | string | Да | Точный model ID из /v1/models. |
messages | array | Да | Сообщения с role и content. |
stream | boolean | Нет | true включает Server-Sent Events. |
temperature | number | Нет | Sampling temperature. |
top_p | number | Нет | Nucleus sampling. |
max_tokens | integer | Нет | Максимум generated tokens. |
max_output_tokens | integer | Нет | Принимается для Gemini-style клиентов. |
stop | string or array | Нет | Stop sequence или массив sequences. |
response_format | object | Нет | OpenAI-style response format, например JSON object mode. |
tools | array | Нет | OpenAI-style function tools. |
tool_choice | string or object | Нет | Управляет выбором tool. |
reasoning | object | Нет | Reasoning controls, если поддерживаются моделью/провайдером. |
metadata | object | Нет | Client metadata. |
Неизвестные поля сохраняются и пробрасываются дальше, если upstream provider их принимает.
Message content
Text-only сообщение может быть строкой:
json
{
"role": "user",
"content": "Summarize this in one paragraph."
}Vision-capable модели могут получать массив content parts:
json
{
"role": "user",
"content": [
{ "type": "text", "text": "Describe this image." },
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.png"
}
}
]
}Для image input принимаются data URLs:
text
data:image/png;base64,...Streaming
Установите stream в true, чтобы получать Server-Sent Events:
json
{
"model": "provider/model-id",
"messages": [{ "role": "user", "content": "Write three short lines." }],
"stream": true
}Стрим завершается строкой:
text
data: [DONE]Tool calling
json
{
"model": "provider/model-id",
"messages": [
{ "role": "user", "content": "What is the status of order 123?" }
],
"tools": [
{
"type": "function",
"function": {
"name": "get_order",
"description": "Look up an order by ID.",
"parameters": {
"type": "object",
"properties": {
"order_id": { "type": "string" }
},
"required": ["order_id"]
}
}
}
],
"tool_choice": "auto"
}Image-capable chat models
Некоторые chat models генерируют изображения через chat endpoint. Для них добавьте image output в modalities:
json
{
"model": "provider/image-chat-model-id",
"messages": [
{ "role": "user", "content": "Create a square icon of a blue glass cube." }
],
"modalities": ["image", "text"],
"image_config": {
"aspect_ratio": "1:1",
"image_size": "1K"
}
}Сгенерированные изображения могут прийти в images массиве assistant message.
Ответ
json
{
"id": "chatcmpl_abc123",
"object": "chat.completion",
"created": 1744000000,
"model": "provider/model-id",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "This endpoint creates model responses from chat messages."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 12,
"total_tokens": 40
}
}