- Run custom code
- Retrieve real-time data
- Interact with third-party services
- Connect to MCP servers
- And perform other dynamic actions
Important: The model does not execute the functions itself. Instead, it outputs tool invocation instructions in an OpenAI-compatible function calling format. You are responsible for parsing these outputs and executing the corresponding functions on your backend or client side.
1
Define Available Tools
Start by specifying the tools (functions) the model can use. Each tool is described using a JSON Schema that defines its name, input parameters, and expected data types. This schema informs the model how each tool should be invoked.
2
Model Determines Intent
When the model receives a user query, it analyzes the intent and decides how to respond. Based on the context and the tools available, it may:
- Respond conversationally, or
- Propose a function call by selecting a relevant tool and filling in the required arguments according to the schema.
3
Execute and Iterate
If a function call is proposed, your system is responsible for executing the function with the provided arguments. You then pass the function’s output back to the model as part of the next prompt. This allows the conversation to continue seamlessly, with the model incorporating the function result into its response or triggering further tool use.API Example
Limitations
Thetool_choice
parameter controls how the model selects which function (tool) to use. It determines whether the model should choose a tool automatically or follow an explicit instruction. Supported values include:
-
"auto"
The model automatically selects the most appropriate function based on the context of the prompt. This is the default behavior and is useful for most use cases. -
Explicit Function Call
You can instruct the model to call a specific function using the following structure:This forces the model to call theread_file
function regardless of context, overriding its own tool selection logic.
API Example
Try it in our Cookbook
Function & Tool Calling Cookbook
Function calling in Playground
You can explore Function Calling capabilities of models directly in the Playground:- Go to the “Model Parameters” section.
- In the “Function calling” section add function description
- Enter your prompt and run it to test whether the model returns the expected function selection for your use case.