OpenAI-Compatible Function Calling
Use thetools parameter with the Chat Completions endpoint:
Define Tools
Model Response with Tool Call
When the model decides to use a tool, the response includes atool_calls array:
Return Tool Results
Send the tool result back to continue the conversation:Full Python Example
Anthropic-Compatible Tool Use
Use thetools parameter with the Messages endpoint:
Response with Tool Use
Return Tool Results
Tool Choice Options
Control when the model uses tools:| Value | Behavior |
|---|---|
"auto" | Model decides whether to call a tool (default) |
"none" | Model will not call any tools |
"required" | Model must call at least one tool |
{"type": "function", "function": {"name": "get_weather"}} | Force a specific tool |
Tips
Write clear tool descriptions
Write clear tool descriptions
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.Use JSON Schema for parameters
Use JSON Schema for parameters
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.
Handle multiple tool calls
Handle multiple tool calls
Models may want to call multiple tools in a single response. Always check for and handle all tool calls in the
tool_calls array.Parallel tool calls
Parallel tool calls
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.

