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/messages

#Headers

x-api-key: $ANTHROPIC_API_KEY
anthropic-version: 2023-06-01
content-type: application/json

#Core 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.

#Try it yourself

Edit the question and re-run — this executes real Python against a small local stand-in for the Anthropic client, so you can experiment with the request shape without an API key.

Try it yourself — runs in your browser. Simulated response, not a live API call.