Anthropic Claude API
Access Claude models for chat, reasoning, tool use and long-context tasks.
What it does
The Anthropic API gives you Claude models for chat, long-context reasoning, summarisation, coding help, tool use and vision. The core endpoint is /v1/messages: you send a list of user/assistant turns and get back a structured message. Streaming, system prompts, tool calling and prompt caching are all supported.
Base URL
Authentication
Sign up at console.anthropic.com, add billing, then create a key. Send two headers on every call: x-api-key: YOUR_KEY and anthropic-version: 2023-06-01. There is no open free tier, though new accounts get a small starter credit.
Code examples
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-20250514","max_tokens":128,
"messages":[{"role":"user","content":"Say hi in one word"}]}'import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY
msg = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=128,
messages=[{"role": "user", "content": "Say hi in one word"}],
)
print(msg.content[0].text)Rate limits & quotas
Rate limits depend on your usage tier and apply to requests per minute plus input and output tokens per minute. A new paid account is typically around 50 requests/min and tens of thousands of tokens/min, rising automatically with spend. Responses carry anthropic-ratelimit-* headers. max_tokens is required on every request.
Key response fields
| content[0].text | The reply text (content is a list of blocks) |
| stop_reason | end_turn, max_tokens, tool_use or stop_sequence |
| usage.input_tokens | Billed input tokens (prompt-cache hits are cheaper) |
| usage.output_tokens | Billed output tokens |
| model | Model that served the request |
Common errors
| 401 | Missing or wrong x-api-key. |
| 400 invalid_request_error | Often a missing max_tokens or a malformed message list. |
| 429 | Per-minute request or token limit exceeded — back off. |
| 529 overloaded_error | The API is temporarily overloaded; retry with backoff. |
When to use it (and alternatives)
Reach for Claude when the job is long documents, careful instruction following, agentic tool use or code. It is a direct alternative to the OpenAI API; the request shape differs (/v1/messages, required max_tokens, content blocks) so budget a little porting time.
FAQ
Is there a free Claude API tier?
No ongoing free tier. New accounts get a small one-off credit; after that it is pay-per-token, priced per million input and output tokens with a discount for prompt-cache hits.
Why do I get a 400 error on a request that looks fine?
The most common cause is a missing max_tokens field — it is mandatory on the Messages API. Also check that roles alternate user/assistant and the first turn is user.
Can Claude read images?
Yes. Add an image content block (base64 or URL) inside a user turn. Vision works on the current Claude 3-family and later models.
New to APIs?
Short guides for working with this API — and any other.
🛠️ Handy LarzOS tools
Free tools to help you work with this API.
Prompt ImproverLearn Prompt Engineering