> ## 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.

<CodeGroup>
  ```python Python (Anthropic SDK) icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
  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":"ayu-dark","dark":"catppuccin-latte"}}
  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"}]
    }'
  ```
</CodeGroup>

## 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](/en/gateway/anthropic-messages/thinking)     |
| Token Streaming     | [Anthropic Streaming](/en/gateway/anthropic-messages/streaming)  |
| OpenAI Tool Calling | [OpenAI Tool Calling](/en/gateway/chat-completions/tool-calling) |


## Related topics

- [Anthropic Messages API](/en/gateway/anthropic-messages.md)
- [Function Calling (Tools)](/en/gateway/chat-completions/tool-calling.md)
- [Claude Code Integration](/en/agents/claude-code.md)
