Reference · API
Anthropic Messages API
Send conversations to Claude models. Keys stay **server-side**.
Send conversations to Claude models. Keys stay **server-side**.
Endpoint
POST https://api.anthropic.com/v1/messagesHeaders
x-api-key: $ANTHROPIC_API_KEY
anthropic-version: 2023-06-01
content-type: application/jsonCore fields
| Field | Purpose |
|-------|---------|
| `model` | e.g. `claude-sonnet-4-20250514` |
| `max_tokens` | Required cap on output |
| `system` | Optional system instructions |
| `messages` | `{role: user|assistant, content}` array |
Python example
import anthropic
client = anthropic.Anthropic()
msg = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="You are a concise tutor.",
messages=[{"role": "user", "content": "What is RAG?"}],
)
print(msg.content[0].text)Long context
Claude models support large context windows — still summarize or trim when chats grow endlessly.
Related
- Snippet: Anthropic messages minimal
- Glossary: Anthropic API