Tool flow
The model first decides which tool to call, you run the tool and return its result, then the model produces the final answer. Three steps, three separate HTTP requests.
1. Request with tool definitions
json
{
"model": "gemini-3.8-flash",
"messages": [{"role": "user", "content": "What is the weather in Istanbul?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}2. Model returns a tool call
json
{
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {"name": "get_weather", "arguments": "{\"city\":\"Istanbul\"}"}
}
]
}3. Send the result, get the answer
json
{
"model": "gemini-3.8-flash",
"messages": [
{"role": "user", "content": "What is the weather in Istanbul?"},
{"role": "assistant", "content": null, "tool_calls": [
{"id": "call_abc123", "type": "function",
"function": {"name": "get_weather", "arguments": "{\"city\":\"Istanbul\"}"}}
]},
{"role": "tool", "tool_call_id": "call_abc123", "content": "{\"temp\": 18, \"desc\": \"partly cloudy\"}"}
]
}The tool_calls in the assistant message must match the tool result one-to-one (tool_call_id must be identical). A missing side may be rejected upstream. If you use the Responses API, the same flow is built with function_call and function_call_output items.