Skip to main content
Function calling (also called “tool use”) lets models invoke structured functions you define. The model decides when to call a function, generates the arguments, and you execute the function and return the result.

OpenAI-Compatible Function Calling

Use the tools parameter with the Chat Completions endpoint:

Define Tools

Model Response with Tool Call

When the model decides to use a tool, the response includes a tool_calls array:

Return Tool Results

Send the tool result back to continue the conversation:

Full Python Example

Anthropic-Compatible Tool Use

Use the tools parameter with the Messages endpoint:

Response with Tool Use

Return Tool Results

Tool Choice Options

Control when the model uses tools:

Tips

The model uses the description field to decide when to call a tool. Be specific about what the tool does and when it should be used.
Define parameters with JSON Schema including types, descriptions, enums, and required fields. The more precise your schema, the better the model’s arguments will be.
Models may want to call multiple tools in a single response. Always check for and handle all tool calls in the tool_calls array.
Some models support calling multiple tools in parallel within a single response. Process all tool calls and return all results before sending the next message.