Tool calling
Let the model call your functions.
All three endpoints support function tools in their native format. Other tool types (built-in tools, code interpreter, file search) return 400 unsupported_tool.
The loop is the same everywhere: send tools, the model returns a call, you run it and send the result back.
{ "model": "flash", "messages": [{ "role": "user", "content": "Weather in Lisbon?" }], "tools": [{ "type": "function", "function": { "name": "get_weather", "description": "Current weather for a city", "parameters": { "type": "object", "properties": { "city": { "type": "string" } }, "required": ["city"] } } }]}The reply has choices[0].message.tool_calls. Append that assistant message, then a { "role": "tool", "tool_call_id": "...", "content": "..." } message per call, and send again.
tool_choice accepts "auto", "none", "required" or { "type": "function", "function": { "name": "get_weather" } }. parallel_tool_calls is supported.
{ "model": "flash", "input": "Weather in Lisbon?", "tools": [{ "type": "function", "name": "get_weather", "parameters": { "type": "object", "properties": { "city": { "type": "string" } }, "required": ["city"] } }]}The output contains function_call items. Send them back in input followed by { "type": "function_call_output", "call_id": "...", "output": "..." }. previous_response_id is not supported, so always send the full history.
{ "model": "flash", "max_tokens": 1024, "messages": [{ "role": "user", "content": "Weather in Lisbon?" }], "tools": [{ "name": "get_weather", "description": "Current weather for a city", "input_schema": { "type": "object", "properties": { "city": { "type": "string" } }, "required": ["city"] } }]}The reply contains tool_use blocks. Answer with a user message holding tool_result blocks. tool_choice accepts auto, any, none or { "type": "tool", "name": "..." }.