Define tools with JSON Schema, handle tool_calls responses, implement parallel tool calls, control tool_choice, and return tool results
0 / 5 completed
1 / 5
How are tools defined in the OpenAI Chat Completions API?
tools array: Each tool is { type: 'function', function: { name: 'get_weather', description: '...', parameters: { type: 'object', properties: { location: { type: 'string' } }, required: ['location'] } } }. The model decides whether to call a tool based on the conversation context and returns a tool_calls array if it does.
2 / 5
What does the model return when it decides to use a tool?
tool_calls response: When the model invokes a tool, the response has choices[0].finish_reason === 'tool_calls' and choices[0].message.tool_calls as an array of { id, type: 'function', function: { name, arguments } }. arguments is a JSON string you parse and pass to your actual function. Return the result by adding a { role: 'tool', tool_call_id: ..., content: result } message.
3 / 5
What is parallel tool calls in the OpenAI API?
Parallel tool calls: When the model determines multiple independent tool calls are needed (e.g. checking weather for two cities), it returns multiple entries in tool_calls. Execute these concurrently with Promise.all() and append all { role: 'tool' } messages before the next completion call. Disable with parallel_tool_calls: false to force sequential execution.
4 / 5
How does tool_choice control model behaviour?
tool_choice: Use 'required' when you always need structured output via a tool — e.g. a structured data extraction pipeline. Use a specific function override when you know exactly which tool is needed. 'none' is equivalent to not passing tools at all. 'auto' is best for general assistants that decide contextually.
5 / 5
What is the correct way to return a tool result in a multi-turn conversation?
Tool result message: The conversation history must include the assistant message containing tool_calls, followed by one { role: 'tool', tool_call_id: 'call_abc', content: JSON.stringify(result) } per tool call. Send the full messages array (including these) in the next request. The model reads the tool results and continues generating the final answer.