Tool calling

Tool calling passes through in each protocol's native format: the Anthropic format uses tools + input_schema, the OpenAI format uses tools + function.parameters, and the Responses API uses tools with top-level name/parameters. The flow is the same three steps: send a request with tools → run the tool on your side → send the result back.

Request body examples

Inference request with tools

Anthropic format:

json
{
  "model": "claude-sonnet-5",
  "max_tokens": 256,
  "tools": [
    {
      "name": "get_weather",
      "description": "Get the weather for a city",
      "input_schema": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}
    }
  ],
  "messages": [{"role": "user", "content": "What is the weather in Beijing right now?"}]
}

When the model decides to call a tool, stop_reason is tool_use and content contains a tool_use block with id, name, and input.

OpenAI format:

json
{
  "model": "gpt-5.6-sol",
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the weather for a city",
        "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}
      }
    }
  ],
  "messages": [{"role": "user", "content": "What is the weather in Beijing right now?"}]
}

When the model decides to call a tool, finish_reason is tool_calls, the calls are in choices[0].message.tool_calls[], and the arguments are the JSON string function.arguments.

Tool execution

Read the tool name and arguments from the response and run the tool in your program (a weather lookup, a database query, and so on) to get a result.

Inference request with tool results

Append the model's tool-call message and your result to the conversation and call again. In the Anthropic format, put a tool_result block in a user message (tool_use_id matches the earlier id); in the OpenAI format, append a message with role tool (tool_call_id matches tool_calls[].id). The model then produces its final reply, with stop_reason back to end_turn (stop for OpenAI).

Best practices

  • Write clear descriptions and parameter schemas; the model relies on them to decide when to call and how to fill arguments
  • Loop: while the response is still a tool call, run it and send the result back, until the stop reason is no longer tool_use / tool_calls
  • Keep tool results concise; long results count as input tokens on later requests
Ready? Three steps to startLog in to the console · top up · create an API key
DiscordGet community help instantly
Tool calling · Docs