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.
МирVisaMastercardСБПT-PayТ-Банк