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

# Tool calling

> Pass function definitions, receive OpenAI-compatible tool calls, and send results back for a follow-up turn.

MESH forwards `tools[]` and `tool_choice` to tool-capable models and returns OpenAI-shaped
`tool_calls` in the response. Streaming responses include tool-call deltas.

The [Models](/models) catalogue marks which models support tool calling. Anthropic Claude, Llama 3.x
/ 4.x, Mistral / Ministral / Pixtral, Qwen, Kimi, GLM 4.7+, and the MESH house tier all accept tool
definitions.

## Request a tool

```json theme={null}
{
  "model": "mesh/claude-sonnet-4.5",
  "messages": [{ "role": "user", "content": "What is the weather in New York?" }],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get current weather for a city",
        "parameters": {
          "type": "object",
          "properties": { "city": { "type": "string" } },
          "required": ["city"]
        }
      }
    }
  ]
}
```

## Response

When the model calls a tool, `finish_reason` is `tool_calls` and the assistant message carries a
`tool_calls[]` array.

```json theme={null}
{
  "choices": [
    {
      "finish_reason": "tool_calls",
      "index": 0,
      "message": {
        "content": null,
        "role": "assistant",
        "tool_calls": [
          {
            "id": "tooluse_abc123",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"city\":\"New York\"}"
            }
          }
        ]
      }
    }
  ]
}
```

## Send the result back

Append the assistant message and a `role: "tool"` message keyed to the `tool_call_id` for a
follow-up turn:

```json theme={null}
{
  "model": "mesh/claude-sonnet-4.5",
  "messages": [
    { "role": "user", "content": "What is the weather in New York?" },
    {
      "role": "assistant",
      "content": null,
      "tool_calls": [
        {
          "id": "tooluse_abc123",
          "type": "function",
          "function": {
            "name": "get_weather",
            "arguments": "{\"city\":\"New York\"}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "tooluse_abc123",
      "content": "72°F, sunny"
    }
  ],
  "tools": [
    /* same tool definitions */
  ]
}
```

## Disabling tools

`tool_choice: "none"` disables calls for that request. `tool_choice: "auto"` (the default) lets the
model decide. Pin a specific function with
`{ "type": "function", "function": { "name": "get_weather" } }`.

## Billing

Tool definitions count toward `prompt_tokens` (input). Tool-call output tokens count toward
`completion_tokens`. Both are billed at the model's standard rate — receipts on every response
include the breakdown via `x-mesh-upstream-cost-usd`, `x-mesh-margin-usd`, `x-mesh-total-usd`.
