If you want to call Claude directly from your code, use the API. This is a beginner's guide that walks a developer through making their first Claude API call. (Models and pricing may change — check the official docs for the latest.)
🟢 Model references match the current lineup · model notice · Fable subscription
Fable subscription (updated November 17, 2026): Claude Fable 5.2, released November 9, 2026, is the current Fable model; Fable 5.1 and Fable 5 are now legacy. Plan terms are the same for all three — Max and Ultra plans and premium seats on Team and seat-based Enterprise plans include Fable at up to 50% of the weekly usage limit; Pro plans and standard seats use usage credits (not available on Free). API pricing is $8/M input and $40/M output tokens for Fable 5.2, and $10/$50 for Fable 5.1 and 5. Some cybersecurity and biology requests may be answered by an Opus model due to safety classifiers. See the Fable 5.2 launch news and the Fable 5.2 guide for details.
How the API differs from chat (claude.ai)
The claude.ai chat product and the API are separate products.
- claude.ai / app: the interface where people chat directly. Used via a Pro/Max subscription.
- API: the channel through which your program calls Claude. Get a key from the console and you're billed by token usage.
Important: a Pro/Max subscription and API usage are separate. Subscribing doesn't make the API free; the API is billed per token. There's no ongoing free tier, though new accounts sometimes get a small one-time credit.
Step 1: Account and API key
- Sign up / log in to the developer platform (platform.claude.com, the console).
- Create a new key under API Keys in settings.
- The full key is shown only once, so store it somewhere safe. The key is like a password — anyone who has it can spend your usage.
- Don't hard-code the key; handle it via an environment variable.
export ANTHROPIC_API_KEY='your-key-here'
Step 2: Your first API call (curl)
The foundation of the Claude API is the Messages endpoint. Here's the simplest possible call.
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [
{ "role": "user", "content": "Hello, Claude!" }
]
}'
On success you get HTTP 200 with a JSON response. The content array holds Claude's reply text, and usage holds the input/output token counts.
Three headers you must know
Updated against the official API docs on November 11, 2026: a new API version, 2026-10-21, is out and the authentication guidance has changed.
- x-api-key — the auth key. The official docs now present
Authorization: Bearer <API key>as the primary authentication header and describex-api-keyas a legacy fallback that is still supported; send one or the other. If your key is not scoped to a single workspace, theanthropic-workspace-idheader is required too. - anthropic-version — the API version; the latest is
2026-10-21. Required on every request (the docs recommend the latest version whenever possible). In this version thetemperature,top_pandtop_kparameters are removed and sending them returns a 400 error. To move from the previous version,2023-06-01, see the official migration guide (platform.claude.com/docs/en/api/migration-2026-10-21). - content-type —
application/json
If you use the official SDKs (Python, TypeScript, etc.), these headers are added automatically.
Model strings (as of November 2026)
In production, use the full versioned model string (an unversioned alias may resolve to a different model over time).
claude-opus-5-5— maximum capabilityclaude-sonnet-5-5— balanced (recommended default for most tasks)claude-haiku-5-5— speed and low cost
Sonnet is enough for most tasks; reserve Opus for genuinely demanding reasoning to stay cost-efficient.
Cost and limits
The API is billed by input/output token count. Per-model rates differ (Opus is the most expensive, Haiku the cheapest); check exact rates in the official docs. There are per-tier rate and spend limits that increase automatically with usage, and you can view your current limits in the console.
Next steps
- Learn the core Messages API patterns: multi-turn conversations, system prompts, stop reasons
- Use tool use (function calling) to let Claude invoke external functions
- Optimize cost and latency with streaming responses, batch processing, and prompt caching
To receive long answers in real time, use API streaming (SSE) to show the response chunk by chunk.
To handle limits (429) and overload (529) reliably in production, see retry strategies in handling errors and rate limits.
For tasks that need complex reasoning, extended thinking can improve answer quality.
This article is for general guidance only. Model strings, pricing, limits, and the API version may change per Anthropic's policies. Always verify the latest values in the official docs (platform.claude.com/docs) before implementing.
Once you are comfortable with text calls, sending images is a natural next step — see how to handle image and PDF input with the Claude API.