Skip to main content

Getting Started with the Claude API: Your First Call (Developer Intro)

How a developer makes their first Claude API call: getting a key, x-api-key auth, the first Messages endpoint call (curl), model strings, and how billing works.

ByUpdated
🌐 This article was machine-translated and may contain inaccuracies. Read the Korean original if in doubt.

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
🟢 Model references match the current lineup · Claude Opus 5.5 / Claude Sonnet 5 / Claude Haiku 4.5 (higher tier: Claude Fable 5.1). This notice changes only when Anthropic ships a new model.

Fable 5 and 5.1 subscription (updated September 7, 2026): Claude Fable 5.1, released September 1, 2026, is the current Fable model and Fable 5 is now legacy. Plan terms are the same for both — Max and Team Premium plans include Fable at up to 50% of the weekly usage limit; Pro and Team Standard use usage credits (

🟢 Model references match the current lineup · Claude Opus 5.5 / Claude Sonnet 5 / Claude Haiku 4.5 (higher tier: Claude Fable 5.1). This notice changes only when Anthropic ships a new model.
0/M input, $50/M output tokens). The one-time
🟢 Model references match the current lineup · Claude Opus 5.5 / Claude Sonnet 5 / Claude Haiku 4.5 (higher tier: Claude Fable 5.1). This notice changes only when Anthropic ships a new model.
00 credit applied only to the Fable 5 transition and is not offered for 5.1. Some coding and debugging requests may be answered by an Opus model due to a security classifier (both models). See the Fable 5.1 guide and the Fable 5 availability guide for details.

Claude API first-call flow 1 Get key platform.claude.com -> API Keys 2 Env var ANTHROPIC_ API_KEY 3 Request POST /v1/messages x-api-key header 4 Response content + usage (tokens) Subscription and API billing are separate. Keep keys in env vars. June 2026.

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

  1. Sign up / log in to the developer platform (platform.claude.com, the console).
  2. Create a new key under API Keys in settings.
  3. 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.
  4. 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: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-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

  • x-api-key — the auth key. (Different from OpenAI's Authorization: Bearer — Anthropic uses a custom header.)
  • anthropic-version — the API version, currently 2023-06-01. Required on every request.
  • content-type — application/json

If you use the official SDKs (Python, TypeScript, etc.), these headers are added automatically.

Model strings (as of September 2026)

In production, use the full versioned model string (an unversioned alias may resolve to a different model over time).

  • claude-opus-5 — maximum capability
  • claude-sonnet-5 — balanced (recommended default for most tasks)
  • claude-haiku-4-5-20251001 — 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.

Chat (claude.ai) vs APIChat (claude.ai)· A person, on screen· Monthly subscription· Use now, no codingAPI· Code calls it programmatically· Pay-per-token usage· Embed Claude in your appPrices, model strings, limits may change — see official docs · as of 2026.6

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.

See also: Claude API Error Handling & Retry Guide

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.

Was this helpful?

Keep reading