/anthropic/v1/messages endpoint implements official Anthropic Tool Use specifications, where tool parameters are defined using the input_schema format.
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)
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 |
| Token Streaming | Anthropic Streaming |
| OpenAI Tool Calling | OpenAI Tool Calling |