Перейти к содержанию

POST /v1/chat/completions#

Полностью совместимо с OpenAI Chat Completions API.

Request#

http POST /v1/chat/completions HTTP/1.1 Host: api.ml-router.su Authorization: Bearer orb_live_… Content-Type: application/json

Параметры#

Поле Тип Описание
model string id из /v1/models. Обязательно.
messages array OpenAI message objects (role+content). Обязательно.
stream bool SSE-стрим, см. Streaming.
temperature number 0..2, по умолчанию зависит от модели
max_tokens int Максимум токенов в ответе
top_p number Альтернатива temperature, 0..1
tools array Function-calling, см. ниже
response_format object {"type": "json_object"} для JSON-mode
seed int Воспроизводимость (не все модели поддерживают)
stop string | array Стоп-последовательности
user string Опциональный user-id для абуза-трекинга

Любой параметр, поддерживаемый OpenAI или конкретной моделью, форвардится без изменений.

Tool calling#

```python tools = [{ "type": "function", "function": { "name": "get_weather", "description": "Get current weather", "parameters": { "type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"] } } }]

resp = client.chat.completions.create( model="openai/gpt-4o", messages=[{"role": "user", "content": "What's the weather in Moscow?"}], tools=tools, ) ```

Response#

json { "id": "gen-1234567890-abcdef", "object": "chat.completion", "created": 1714291200, "model": "openai/gpt-4o-mini", "choices": [{ "index": 0, "message": { "role": "assistant", "content": "Привет! Чем могу помочь?" }, "finish_reason": "stop" }], "usage": { "prompt_tokens": 12, "completion_tokens": 8, "total_tokens": 20, "cost": 0.000018 } }

Поле usage#

Ключ Что
prompt_tokens Сколько токенов было в твоём запросе
completion_tokens Сколько в ответе
total_tokens Сумма
cost Сколько списано с баланса в USD

cost всегда возвращается в наших ответах — можешь использовать для точного учёта расходов на твоей стороне. Прайс-лист за 1M токенов — в GET /v1/prices или в /prices бота.

Ошибки#

См. Коды ошибок. Самые частые:

  • 402 insufficient_funds — баланс ниже $0.10. Пополни через /topup в @ML_Router_bot.
  • 429 rate_limit — превышен RPM-кэп (Rate limits).
  • 400 invalid_request — невалидный JSON или model не указан.