Skip to main content
The two simplest patterns: one tool, one call (simple), and many tools available with the model picking one (multiple).

Simple function calling

Suppose your application has access to a get_current_weather function that takes two named arguments, location and unit:
Make this function available to the LLM by passing its description to the tools key alongside the user’s query. Suppose the user asks, “What is the current temperature of New York?”
The model responds with a single function call in the tool_calls array, specifying the function name and arguments needed to get the weather for New York.
JSON
You can now programmatically execute the function call to answer the user’s question.

Streaming

Function calling also works with streaming responses. When you enable streaming, the model returns tool calls incrementally, accessible from the delta.tool_calls object in each chunk.
The model responds with streamed function calls:
Tool calls don’t show up in message.content: When a model decides to call a tool, the call lands in message.tool_calls, not in the content string. Some models return null for message.content on a tool-calling turn. Read the call from message.tool_calls[0].function.name and .arguments.

Multiple function calling

Multiple function calling makes several functions available and lets the model choose the best one based on the user’s intent. The model has to understand the request and pick the appropriate tool from the options. The example below provides two tools to the model. The model responds with one tool invocation.
In this example, both weather and stock functions are available. The model correctly identifies that the user is asking about stock prices and calls the get_current_stock_price function.

Select a specific tool

To force the model to use a specific tool, pass the tool’s name to the tool_choice parameter:
This forces the model to use the specified function regardless of the user’s phrasing.

tool_choice options

The tool_choice parameter controls how the model uses functions. It accepts: String values:
  • "auto" (default): The model decides whether to call a function or generate a text response.
  • "none": The model never calls functions, only generates text.
  • "required": The model must call at least one function.