One function call takes two API calls, not one. The model never runs your code. It only asks you to run it, and you send the result back.
1. Your app sends the messages plus the tool schemas
2. Model replies with a tool_use block: name, input, and an id
(stop_reason "tool_use" - no final text yet)
3. Your app runs the real function
4. Your app appends that assistant turn, then a user turn holding a
tool_result block whose tool_use_id matches the same id
5. Resend the whole message list; the model reads the result and answers
Two details prove you have built this. The API is stateless and remembers nothing between calls, so step 5 resends every earlier turn, including the tool_use one. And the ids must pair exactly, or the request is rejected.
OpenAI names the same pieces tool_calls and role: "tool" with tool_call_id. The loop can repeat: the model may ask for another call before it stops.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓