How It Works
You include atools array in your request describing the functions available to the model. If the model determines that a function call is the best way to answer the user’s request, it returns a response with finish_reason: "tool_calls" and a tool_calls array instead of a plain text reply. You then execute the requested function with the provided arguments, send the result back as a tool role message, and make one more API call to get the model’s final answer.
Step-by-Step
Controlling Tool Use with tool_choice
The tool_choice parameter lets you override the model’s default behavior.
Use
"none" when you want to ask the model a follow-up question without triggering a tool call. Use a specific function name when the user action unambiguously maps to a single function and you want to skip the model’s decision step.