К содержимому
Base URLМодель в примерах
APItools.md

Function calling

Как в OpenAI: опишите функции в tools, модель вернёт tool_calls и finish_reason: tool_calls. Выполните функцию у себя, добавьте в историю ответ модели и результат сообщением с role: tool и tool_call_id вызова, затем повторите запрос. Инструменты работают на вашей стороне и стоят только токенов.

tools
Тип function. Тип custom (свободный текст, как apply_patch в Codex) — в Responses
tool_choice
none, auto, required, конкретная функция или allowed_tools из таких функций. allowed_tools понимают не все модели
functions
Старые functions и function_call шлюз пропускает, но модели их не понимают: ответ 400 или функции не видны модели. Пишите tools
responses
Функция описывается без обёртки: {"type": "function", "name": …, "parameters": …}. Модель вернёт элемент function_call, результат отправьте элементом function_call_output с тем же call_id. previous_response_id не работает: шлите весь input вместе с function_call
1curl https://api.polyapi.ru/v1/chat/completions \
2 -H "Authorization: Bearer $POLYAPI_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "model": "openai/gpt-6.1-sol",
6 "messages": [{"role": "user", "content": "Погода в Москве?"}],
7 "tools": [{
8 "type": "function",
9 "function": {
10 "name": "get_weather",
11 "parameters": {
12 "type": "object",
13 "properties": {"city": {"type": "string"}},
14 "required": ["city"]
15 }
16 }
17 }]
18 }'
{
"id": "chatcmpl-5f0c2b9e7d3a4e18a6c1d2b3e4f5a6b7",
"object": "chat.completion",
"created": 1794052800,
"model": "openai/gpt-6.1-sol",
"choices": [
{
"index": 0,
"finish_reason": "tool_calls",
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_7Qx2mV9k",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Москва\"}"
}
}
]
}
}
],
"usage": {
"prompt_tokens": 58,
"completion_tokens": 17,
"total_tokens": 75
}
}

Встроенные инструменты — web_search, file_search, code_interpreter, mcp — не поддерживаем: ответ 400 с param: tools. Исключение — web_search в Responses: его молча убираем из tools, и модель отвечает без поиска, иначе Codex не работал бы. Названный в tool_choice, он даёт 400. web_search_options в Chat Completions — тоже 400.