Skip to main content

Tool calling

Tool calling lets a model invoke external functions. The model generates structured JSON arguments, your code executes the function, and the result goes back into the conversation.

How it works

  1. Define tools as JSON schemas and pass them in the tools parameter.
  2. The model may emit a tool_calls field instead of a text response.
  3. Execute the function with the provided arguments.
  4. Return the result as a tool message in the next request.

Example

Anthropic format

The same flow works in the Messages API. Tool definitions and response shapes match the Anthropic schema.

Model support matrix

Limitations

  • Parallel tool calls are supported; the model chooses whether to call one or multiple tools
  • For multi-step tool loops, inject the tool result back into the conversation as a tool message
  • Some niche OpenAI tool features (e.g., function_call: "none" behavior) may have minor differences