Document Utilities
Anthropic Claude API Reference
Anthropic's Messages API is built around role-based conversational inputs and explicit max-token limits. It is commonly used for assistant chat, structured analysis, and policy-bound generation workflows.
Endpoint Summary
- Method: POST
- URL:
https://api.anthropic.com/v1/messages - Auth:
x-api-keyheader + required version header
Required Headers
| Header | Example | Purpose |
|---|---|---|
x-api-key |
YOUR_ANTHROPIC_KEY |
Authenticates request. |
anthropic-version |
2023-06-01 |
Locks request schema version. |
content-type |
application/json |
Declares JSON payload. |
VS Code Style cURL Example
# Claude Messages API call
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: YOUR_ANTHROPIC_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-3-5-sonnet-latest",
"max_tokens": 300,
"system": "You are a precise architecture reviewer.",
"messages": [
{"role": "user", "content": "Explain rate limiting in distributed APIs."}
]
}'
VS Code Style Python Example
import requests
url = "https://api.anthropic.com/v1/messages"
headers = {
"x-api-key": "YOUR_ANTHROPIC_KEY",
"anthropic-version": "2023-06-01",
"content-type": "application/json",
}
payload = {
"model": "claude-3-5-sonnet-latest",
"max_tokens": 250,
"messages": [
{"role": "user", "content": "Draft a short API migration checklist."}
],
}
resp = requests.post(url, headers=headers, json=payload, timeout=60)
resp.raise_for_status()
content_blocks = resp.json().get("content", [])
if content_blocks:
print(content_blocks[0].get("text", ""))
Response Structure
Anthropic responses usually include a top-level content array. Each block can contain text or other
modalities depending on model capabilities. Production integrations should check for partial outputs and gracefully
handle safety stops or truncation.
Implementation tip: Keep API version headers explicit to reduce unexpected behavior changes over time.