guides/claude-api-key8 min read

How to get your Claude API key and make your first request

A step-by-step walkthrough of creating an Anthropic account, generating an API key, installing the SDK, and making your first Claude API call — in Python, TypeScript, and curl.

Step 1: Create an Anthropic account

Go to console.anthropic.comand sign up. You'll need a valid email address. Anthropic offers $5 in free credits for new accounts, which is enough for thousands of API calls with their smaller models.

Once you've verified your email and logged in, you'll land on the Anthropic Console dashboard.

Step 2: Generate your API key

  1. In the Console, navigate to Settings → API Keys.
  2. Click Create Key. Give it a descriptive name (e.g., “my-app-dev”).
  3. Copy the key immediately — Anthropic won't show it again. It starts with sk-ant-.

Store it safely. Use an environment variable, never commit it to source control. In your terminal:

export ANTHROPIC_API_KEY="sk-ant-your-key-here"

Step 3: Install the SDK

Anthropic maintains official SDKs for Python and TypeScript. Both use the same API under the hood.

Python
pip install anthropic
TypeScript
npm install @anthropic-ai/sdk

Step 4: Make your first API call

Here's a minimal working example in each language. The SDK reads your ANTHROPIC_API_KEY environment variable automatically.

Python
import anthropic client = anthropic.Anthropic() message = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=1024, messages=[ {"role": "user", "content": "What is the capital of France?"} ], ) print(message.content[0].text)
TypeScript
import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic(); const message = await client.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 1024, messages: [ { role: "user", content: "What is the capital of France?" }, ], }); console.log(message.content[0].text);
curl
curl https://api.anthropic.com/v1/messages \ -H "content-type: application/json" \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "claude-sonnet-4-20250514", "max_tokens": 1024, "messages": [ {"role": "user", "content": "What is the capital of France?"} ] }'

Claude API pricing

Anthropic charges per million tokens (MTok) for both input and output. Output tokens typically cost 3–5x more than input tokens. Here's what's currently available:

Live data · Claude model pricing
ModelAvg Score$/in$/outContext
Claude Sonnet 4.64.69$3.00$15.001M
Claude Opus 4.64.62$5.00$25.001M
Claude Opus 4.74.46$5.00$25.001M
Claude Haiku 4.54.00$1.00$5.00200K

Common gotchas

  • Rate limits. New accounts start with lower rate limits (typically 50 requests/minute). You can request increases through the Console as your usage grows.
  • Key rotation. Rotate your API keys periodically. You can have multiple active keys — create a new one before revoking the old one to avoid downtime.
  • Environment variables. Never hardcode your key. Use .env files locally and your platform's secret management in production (Vercel, Railway, etc.).
  • Billing alerts. Set a monthly spending limit in the Console under Settings → Plans & Billing. Anthropic will pause your API access rather than surprise you with a large bill.
  • Model versions. Use dated model IDs (e.g., claude-sonnet-4-20250514) in production for reproducibility. The alias claude-sonnet-4-latest is fine for development.

Which Claude model should you use?

Right now, Claude Sonnet 4.6 is Anthropic's top-performing model on our benchmarks (4.69/5.0). For cost-sensitive workloads, look at the cheaper models in the table above — the quality-to-price ratio varies significantly across the lineup.

Not sure if Claude is the right choice for your use case? See how it compares to every other model on our pricing page, or ask our model recommendation chatbot what's best for your specific workload.