The Claude API lives at https://api.anthropic.com/v1. Everything goes through the Messages endpoint: send a list of messages, get Claude's reply as a list of content blocks.
Create a key at console.anthropic.com and send it as x-api-key (not Authorization), along with anthropic-version: 2023-06-01. In the examples it's written {{ANTHROPIC_API_KEY}}.
The anthropic-dangerous-direct-browser-access: true header lets the request run from a browser. It's harmless from the command line; leave it out of server code.
Full reference: https://docs.anthropic.com/en/api
The reply is in content[] — read the blocks with type: "text". max_tokens is required.
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: {{ANTHROPIC_API_KEY}}" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-dangerous-direct-browser-access: true" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-5",
"max_tokens": 16000,
"messages": [{"role": "user", "content": "Explain HTTP caching in two sentences."}]
}'
system is a top-level field, not a message role.
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: {{ANTHROPIC_API_KEY}}" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-dangerous-direct-browser-access: true" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-5",
"max_tokens": 16000,
"system": "You are a senior backend engineer. Answer in one paragraph.",
"messages": [{"role": "user", "content": "When should I use PATCH instead of PUT?"}]
}'
"stream": true returns server-sent events; text arrives in content_block_delta events.
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: {{ANTHROPIC_API_KEY}}" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-dangerous-direct-browser-access: true" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-5",
"max_tokens": 16000,
"stream": true,
"messages": [{"role": "user", "content": "Write a limerick about a 404."}]
}'
How many input tokens a request would use, without running it. Free.
curl https://api.anthropic.com/v1/messages/count_tokens \
-H "x-api-key: {{ANTHROPIC_API_KEY}}" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-dangerous-direct-browser-access: true" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-5",
"messages": [{"role": "user", "content": "How many tokens is this sentence?"}]
}'
Model IDs, context windows, and output limits your key can use.
curl https://api.anthropic.com/v1/models \
-H "x-api-key: {{ANTHROPIC_API_KEY}}" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-dangerous-direct-browser-access: true"