Skip to content

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
  }'

Поля запроса

ПолеТипОбязательноеПримечания
modelstringДаТочный model ID из /v1/models.
messagesarrayДаСообщения с role и content.
streambooleanНетtrue включает Server-Sent Events.
temperaturenumberНетSampling temperature.
top_pnumberНетNucleus sampling.
max_tokensintegerНетМаксимум generated tokens.
max_output_tokensintegerНетПринимается для Gemini-style клиентов.
stopstring or arrayНетStop sequence или массив sequences.
response_formatobjectНетOpenAI-style response format, например JSON object mode.
toolsarrayНетOpenAI-style function tools.
tool_choicestring or objectНетУправляет выбором tool.
reasoningobjectНетReasoning controls, если поддерживаются моделью/провайдером.
metadataobjectНет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
  }
}

API documentation for rout.my.