Tool calling
Connect the model to external functions, APIs, and data sources. OpenAI-compatible tool format with up to 128 tools per request.
How tool calling works
You define tools (functions) in your request. The model decides when to call them, generates the arguments, and returns a tool_calls response. Your code executes the function, returns the result, and the model incorporates it into its final answer.
You send a message with tool definitions
The model sees the function names, descriptions, and parameter schemas.
The model decides to call a tool
It returns finish_reason: "tool_calls" with the function name and JSON arguments.
Your code executes the function
You run the function with the provided arguments and get a result.
You return the result to the model
Send the tool result back as a message with role: "tool".
The model generates its final response
It incorporates the tool result into a natural language answer.
The model never executes functions itself. It only generates the call specification. Your code handles execution, which means you control security, validation, and error handling.
Defining tools
Tools are defined as an array of objects in the request body. Each tool has a type (always "function"), a name, a description, and a parameters schema in JSON Schema format.
Handling the response
When the model decides to call a tool, the response contains tool_calls instead of content. Execute the function, then return the result.
Strict mode
Set strict: true on a tool definition to guarantee the model output complies with your JSON schema. When strict mode is enabled:
- •All properties must be listed in required
- •additionalProperties must be set to false on every object
- •The output is guaranteed to match your schema exactly
- •Use $def and $ref for reusable schema modules and recursive structures
Parallel calls and limits
The model can call multiple tools in a single response. When this happens, tool_calls contains multiple entries. Execute each one and return all results before sending the next request.
Limits
Tool calling with thinking mode
Thinking mode supports tool calls. The model can reason through a problem, decide to call tools, process the results, and continue reasoning before generating a final answer.
Important: When using tool calls within thinking mode, you must pass reasoning_content back to the API in all subsequent requests for turns that involved tool calls. Failure to do so returns a 400 error. For turns without tool calls, reasoning_content can be omitted.
See the thinking modes guide for full details on reasoning_content handling in multi-turn conversations.
Ready to connect your tools?
Start with the quickstart guide, then add tool definitions to your requests.