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

# Anthropic Tool Use

> Invoke external tools and functions using Anthropic input_schema specifications.

The `/anthropic/v1/messages` endpoint implements official [Anthropic](https://www.anthropic.com/?utm_source=neosantara-docs\&utm_medium=referral) Tool Use specifications, where tool parameters are defined using the `input_schema` format.

```python Python (Anthropic SDK) icon="python" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
from anthropic import Anthropic
import json
import os

client = Anthropic(
    base_url="https://api.neosantara.xyz/anthropic",
    api_key=os.environ["NEOSANTARA_API_KEY"]
)

tools = [
    {
        "name": "get_stock_price",
        "description": "Fetch real-time stock price by ticker symbol.",
        "input_schema": {
            "type": "object",
            "properties": {
                "ticker": {"type": "string", "description": "Stock ticker (e.g. BBCA)"}
            },
            "required": ["ticker"]
        }
    }
]

# Step 1: Submit request with tool specifications
response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    tools=tools,
    messages=[{"role": "user", "content": "What is the stock price of BBCA today?"}]
)

# Step 2: Check for tool_use content blocks
tool_calls = [block for block in response.content if block.type == "tool_use"]

if tool_calls:
    tool_call = tool_calls[0]
    print(f"Selected tool: {tool_call.name}")
    print(f"Input arguments: {tool_call.input}")

    # Step 3: Run local function
    tool_result = json.dumps({"ticker": "BBCA", "price": 9850, "currency": "IDR"})

    # Step 4: Supply tool_result back to model
    final_response = client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=1024,
        tools=tools,
        messages=[
            {"role": "user", "content": "What is the stock price of BBCA today?"},
            {"role": "assistant", "content": response.content},
            {
                "role": "user",
                "content": [
                    {
                        "type": "tool_result",
                        "tool_use_id": tool_call.id,
                        "content": tool_result
                    }
                ]
            }
        ]
    )
    print("Final answer:", final_response.content[0].text)
```

```bash cURL icon="terminal" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
curl -X POST https://api.neosantara.xyz/anthropic/v1/messages \
  -H "x-api-key: $NEOSANTARA_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "tools": [
      {
        "name": "get_stock_price",
        "description": "Fetch stock price",
        "input_schema": {
          "type": "object",
          "properties": {
            "ticker": {"type": "string"}
          },
          "required": ["ticker"]
        }
      }
    ],
    "messages": [{"role": "user", "content": "Check BBCA price"}]
  }'
```

## Anthropic `tool_choice` Configurations

| Configuration | Description |
| :- | :- |
| `{"type": "auto"}` | Model autonomously determines whether to call a tool (default). |
| `{"type": "any"}` | Forces the model to invoke at least one tool. |
| `{"type": "tool", "name": "get_stock_price"}` | Forces the model to invoke a specific tool. |

## Next Steps

| Task | Guide |
| :- | :- |
| Extended Thinking | [Extended Thinking](https://docs.neosantara.xyz/en/gateway/anthropic-messages/thinking.md) |
| Token Streaming | [Anthropic Streaming](https://docs.neosantara.xyz/en/gateway/anthropic-messages/streaming.md) |
| OpenAI Tool Calling | [OpenAI Tool Calling](https://docs.neosantara.xyz/en/gateway/chat-completions/tool-calling.md) |


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