Recommended endpoint
Minimal request
{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Fetch weather",
"input_schema": {
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
}
],
"messages": [
{
"role": "user",
"content": [{ "type": "text", "text": "Get today's Shanghai weather." }]
}
]
}
cURL example
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Fetch weather",
"input_schema": {
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
}
],
"messages": [
{
"role": "user",
"content": [{ "type": "text", "text": "Get today's Shanghai weather." }]
}
]
}'
Python example
from anthropic import Anthropic
client = Anthropic(api_key="<ANTHROPIC_API_KEY>")
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=[
{
"name": "get_weather",
"description": "Fetch weather",
"input_schema": {
"type": "object",
"properties": {
"city": {"type": "string"},
},
"required": ["city"],
},
}
],
messages=[
{
"role": "user",
"content": [{"type": "text", "text": "Get today's Shanghai weather."}],
}
],
)
print(response.content[0].text)
Node.js example
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
const response = await client.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
tools: [
{
name: "get_weather",
description: "Fetch weather",
input_schema: {
type: "object",
properties: {
city: { type: "string" }
},
required: ["city"]
}
}
],
messages: [
{
role: "user",
content: [{ type: "text", text: "Get today's Shanghai weather." }]
}
]
});
console.log(response.content[0].text);
Best practices
- Send tool results back as
tool_resultblocks - Preserve the assistant blocks returned before the tool call
- Clear tool descriptions improve parameter stability more than clever naming
