> ## Documentation Index
> Fetch the complete documentation index at: https://docs.antarah.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Tool calling

> Let the model call your functions.

Models with `supports_tools: true` in `GET /v1/models` can call tools you define. Tools work on all three endpoints, in each API's own format. You run the tool and send the result back in the next request.

```python Chat Completions theme={null}
import json

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Current weather for a city",
        "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
    },
}]
messages = [{"role": "user", "content": "What's the weather in Riyadh?"}]

first = client.chat.completions.create(model="a1", messages=messages, tools=tools)
call = first.choices[0].message.tool_calls[0]
result = {"city": json.loads(call.function.arguments)["city"], "temp_c": 31}

messages += [first.choices[0].message, {"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)}]
second = client.chat.completions.create(model="a1", messages=messages, tools=tools)
print(second.choices[0].message.content)
```

```python Messages theme={null}
tools = [{
    "name": "get_weather",
    "description": "Current weather for a city",
    "input_schema": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
}]
messages = [{"role": "user", "content": "What's the weather in Riyadh?"}]

first = client.messages.create(model="a1", max_tokens=1024, tools=tools, messages=messages)
use = next(b for b in first.content if b.type == "tool_use")

messages += [
    {"role": "assistant", "content": first.content},
    {"role": "user", "content": [{"type": "tool_result", "tool_use_id": use.id, "content": '{"temp_c": 31}'}]},
]
second = client.messages.create(model="a1", max_tokens=1024, tools=tools, messages=messages)
print(next(b.text for b in second.content if b.type == "text"))
```

| Option | Chat Completions | Responses | Messages |
| - | - | - | - |
| Define tools | `tools` (function tools) | `tools` (function tools) | `tools` |
| Choose | `tool_choice`: `none`, `auto`, `required`, or a named function | `tool_choice` | `tool_choice`: `auto`, `any`, `tool`, `none` |
| Parallel calls | `parallel_tool_calls` | `parallel_tool_calls`, `max_tool_calls` | `tool_choice.disable_parallel_tool_use` |
| Call finished | `finish_reason: "tool_calls"` | `function_call` output items | `stop_reason: "tool_use"` |

Limits: up to 128 tools per request. Streamed tool calls arrive as argument deltas, which the SDK stream helpers assemble for you.

> [!NOTE]
>
> Built-in server tools (web search, file search, code execution, computer use) aren't available; requests with them get `400 unsupported_parameter`. Tools on a model without tool support get the same error.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.