Skip to main content
Configure your model to work with external tools and use the results in its response.
Tool calling (also known as function calling) refers to a model’s ability to interact with external tools outside itself—such as querying a database or calling an external API. You provide tool definitions in your request. The model does not run your code. The model returns a structured tool call request. Your application decides whether and how to execute this request, and then returns the results to the model to be integrated into a final response. Support is per-model—check the Tool Calling column under Available Models.

How tool calling works

A tool calling interaction consists of four main steps:
  1. Define your tools: Use the tools request parameter to tell the model which functions your application can run, what each function does, and what arguments it accepts. You must also implement the corresponding functions in your application.
  2. Send the request: Include the tool definitions in a Chat Completions request. Use the tool_choice parameter to control tool selection.
  3. Run the requested function: If the model returns a tool call, validate its arguments and execute the corresponding function in your application.
  4. Return the result: Append the assistant’s tool-call message to the conversation, followed by the tool result associated with the matching tool_call_id. Send the updated conversation back to the model so it can compose an answer.
The model may answer directly without calling a tool, or request one or more tool calls, depending on the prompt, model capabilities, and tool_choice setting. Tool-calling behavior and support varies by model. See the annotated example below, which shows a complete tool calling interaction.

Streaming

When streaming is enabled, tool-call information may arrive across multiple chunks. Accumulate the relevant deltas off choices[0].delta.tool_calls in the stream until the tool call and its arguments are complete before parsing and executing it.