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

# Tool Use

> Use Anthropic-style tool_use and tool_result blocks.

`Messages API` models tool workflows through content blocks rather than `tool_calls` arrays.

Use this page when your app already depends on Anthropic-style tool semantics.

## Define Tools

<CodeGroup>
  ```python Python theme={null}
  from anthropic import Anthropic

  client = Anthropic(
      base_url="https://api.naga.ac",
      api_key="YOUR_API_KEY",
  )

  message = client.messages.create(
      model="claude-sonnet-4.5",
      max_tokens=256,
      messages=[
          {
              "role": "user",
              "content": "Check the weather in Prague and tell me if I need a coat.",
          }
      ],
      tools=[
          {
              "name": "lookup_weather",
              "description": "Look up current weather for a city.",
              "input_schema": {
                  "type": "object",
                  "properties": {
                      "city": {"type": "string"}
                  },
                  "required": ["city"],
              },
          }
      ],
  )

  if message.stop_reason == "tool_use":
      tool_use = next(block for block in message.content if block.type == "tool_use")
      print(tool_use.name)
      print(tool_use.input)
  ```

  ```javascript Node.js theme={null}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
    baseURL: 'https://api.naga.ac',
    apiKey: 'YOUR_API_KEY',
  });

  const message = await client.messages.create({
    model: 'claude-sonnet-4.5',
    max_tokens: 256,
    messages: [
      { role: 'user', content: 'Check the weather in Prague and tell me if I need a coat.' },
    ],
    tools: [
      {
        name: 'lookup_weather',
        description: 'Look up current weather for a city.',
        input_schema: {
          type: 'object',
          properties: {
            city: { type: 'string' },
          },
          required: ['city'],
        },
      },
    ],
  });

  if (message.stop_reason === 'tool_use') {
    const toolUse = message.content.find((block) => block.type === 'tool_use');
    console.log(toolUse?.name);
    console.log(toolUse?.input);
  }
  ```

  ```bash cURL theme={null}
  curl https://api.naga.ac/v1/messages \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "claude-sonnet-4.5",
      "max_tokens": 256,
      "messages": [
        {
          "role": "user",
          "content": "Check the weather in Prague and tell me if I need a coat."
        }
      ],
      "tools": [
        {
          "name": "lookup_weather",
          "description": "Look up current weather for a city.",
          "input_schema": {
            "type": "object",
            "properties": {
              "city": { "type": "string" }
            },
            "required": ["city"]
          }
        }
      ],
      "tool_choice": {
        "type": "auto"
      }
    }'
  ```
</CodeGroup>

## Assistant Tool Use Block

```json theme={null}
{
  "type": "tool_use",
  "id": "call_1",
  "name": "lookup_weather",
  "input": {
    "city": "Prague"
  }
}
```

## Return Tool Results

Tool results go back in a `user` message with `tool_result` blocks.

```json theme={null}
{
  "model": "claude-sonnet-4.5",
  "max_tokens": 256,
  "messages": [
    {
      "role": "assistant",
      "content": [
        {
          "type": "tool_use",
          "id": "call_1",
          "name": "lookup_weather",
          "input": {
            "city": "Prague"
          }
        }
      ]
    },
    {
      "role": "user",
      "content": [
        {
          "type": "tool_result",
          "tool_use_id": "call_1",
          "content": "{\"temperature_c\":7,\"raining\":true}"
        }
      ]
    }
  ]
}
```

Keep the assistant `tool_use` block in the replayed history before you send the `tool_result` block.

Some reasoning-capable models also return `thinking` blocks alongside `tool_use`. If you want continuity across turns, replay those blocks unchanged, including `signature`, before the later `tool_result` block. See [Messages Thinking Blocks](/api/messages/thinking-blocks).

## Streaming Behavior

When streaming is enabled:

* the tool-use block begins with `content_block_start`
* argument deltas arrive as `content_block_delta` with `type: input_json_delta`
* tool-oriented turns usually end with `message_delta.stop_reason: "tool_use"`

## Caveats

* assistant messages can include `tool_use` blocks but not `tool_result` blocks
* user messages can include `tool_result` blocks but not `tool_use` blocks
* `tool_choice: {"type":"any"}` maps to required tool use semantics internally

## Common mistakes

* sending `tool_result` in an assistant message instead of a user message
* losing the original `tool_use` block before sending the result back
* trying to use Chat Completions or Responses tool payload shapes on this surface

## Related Docs

* [Capability-level Tool Calling Comparison](/build/tool-calling)
* [Messages Thinking Blocks](/api/messages/thinking-blocks)
* [Messages Streaming](/api/messages/streaming)
* [Migration to Responses](/api/messages/migration-to-responses)
