Call the Claude API with curl. Complete 2026 examples: basic message, streaming, tool use, system prompt, and JSON extraction — no SDK required.
curl is the fastest way to verify your API key, test prompt changes, or debug requests without writing any application code.
export ANTHROPIC_API_KEY="sk-ant-your-key-here"
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-6",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Hello, Claude!"}]
}'
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-6",
"max_tokens": 512,
"system": "You are a concise technical writer. Respond in bullet points.",
"messages": [{"role": "user", "content": "What is prompt caching?"}]
}'
curl -s 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-6","max_tokens":256,"messages":[{"role":"user","content":"What is 12*34?"}]}' \
| jq -r '.content[0].text'
curl --no-buffer 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-6",
"max_tokens": 512,
"stream": true,
"messages": [{"role": "user", "content": "Count from 1 to 10 slowly."}]
}' | grep "^data:" | jq -r 'select(.type=="content_block_delta") | .delta.text // empty' 2>/dev/null
curl -s 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-6",
"max_tokens": 256,
"system": "Return only valid JSON. No explanation.",
"messages": [{
"role": "user",
"content": "Extract: name, price, category from: Blue Widget, $12.99, Hardware"
}]
}' | jq '.content[0].text | fromjson'
curl -s 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-6",
"max_tokens": 256,
"tools": [{
"name": "get_weather",
"description": "Get weather for a city",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}],
"messages": [{"role": "user", "content": "What is the weather in London?"}]
}' | jq '.content[] | select(.type=="tool_use")'
curl -s 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-6","max_tokens":256,"messages":[{"role":"user","content":"Hello"}]}' \
| jq '{input_tokens: .usage.input_tokens, output_tokens: .usage.output_tokens, stop_reason: .stop_reason}'
| Header / Field | Required | Value |
|---|---|---|
x-api-key header | Yes | Your sk-ant-… key |
anthropic-version header | Yes | 2023-06-01 |
content-type header | Yes | application/json |
model | Yes | e.g. claude-sonnet-4-6 |
max_tokens | Yes | Integer; billed regardless of actual output length |
stream | No | true for SSE streaming |
system | No | System prompt string |
temperature | No | 0.0–1.0, default 1 |
Use these curl snippets as quick smoke tests before wiring the SDK into your app. Estimate token costs at the Claude API Cost Calculator.