To use Claude in your applications, you need an Anthropic API key. This guide shows you exactly how to get one, how to set it up securely, and what you need to know about rate limits and billing.
Step 1: Create an Anthropic Account
Go to console.anthropic.com and click Sign Up. You can register with Google or an email address. Email verification is required.
Once logged in, you land on the Anthropic Console — the dashboard where you manage keys, usage, and billing.
Step 2: Get Your API Key
In the Console, navigate to Settings → API Keys (or click your avatar → API Keys). Then:
- Click Create Key
- Give it a descriptive name (e.g.,
my-app-dev) - Click Create Key — copy it immediately
- Store it somewhere safe — you won’t see the full key again
Your key looks like: sk-ant-api03-...
Step 3: Add a Payment Method
API access requires a credit card on file. Go to Settings → Billing and add your card. Usage is billed monthly — you’re only charged for what you use.
New accounts may receive a small free credit to test the API before committing to a plan.
Step 4: Set Your API Key Securely
Never paste your API key directly into source code. Use environment variables:
# Linux / macOS — add to ~/.bashrc or ~/.zshrc
export ANTHROPIC_API_KEY="sk-ant-api03-..."
# Windows PowerShell
$env:ANTHROPIC_API_KEY = "sk-ant-api03-..."For projects, use a .env file (and add it to .gitignore):
# .env
ANTHROPIC_API_KEY=sk-ant-api03-...# .gitignore
.env
*.envThe official SDKs automatically read ANTHROPIC_API_KEY from the environment — no extra config needed.
Step 5: Test Your Key
Verify the key works with a quick test. Using Python:
pip install anthropicimport anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY automatically
message = client.messages.create(
model="claude-haiku-4-5", # cheapest model for testing
max_tokens=64,
messages=[{"role": "user", "content": "Say hello!"}],
)
print(message.content[0].text)Using Node.js:
npm install @anthropic-ai/sdkimport Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const message = await client.messages.create({
model: "claude-haiku-4-5",
max_tokens: 64,
messages: [{ role: "user", content: "Say hello!" }],
});
console.log(message.content[0].text);Using curl (no SDK needed):
curl https://api.anthropic.com/v1/messages \
--header "x-api-key: $ANTHROPIC_API_KEY" \
--header "anthropic-version: 2023-06-01" \
--header "content-type: application/json" \
--data '{
"model": "claude-haiku-4-5",
"max_tokens": 64,
"messages": [{"role": "user", "content": "Say hello!"}]
}'Understanding Rate Limits
Anthropic enforces rate limits per API key. Limits depend on your account tier:
# Tier 1 (after first payment, $5+)
Requests per minute (RPM): 50
Tokens per minute (TPM): 40,000
Tokens per day (TPD): 1,000,000
# Tier 2 ($100+ spend / 30 days)
RPM: 1,000
TPM: 80,000
TPD: 2,500,000
# Tier 3 ($500+ spend / 30 days)
RPM: 2,000
TPM: 160,000When you hit a rate limit, the API returns HTTP 429. Handle it with exponential backoff:
import time
import anthropic
client = anthropic.Anthropic()
def call_with_retry(prompt, max_retries=3):
for attempt in range(max_retries):
try:
return client.messages.create(
model="claude-haiku-4-5",
max_tokens=512,
messages=[{"role": "user", "content": prompt}],
)
except anthropic.RateLimitError:
if attempt == max_retries - 1:
raise
wait = 2 ** attempt # 1s, 2s, 4s
print(f"Rate limited. Waiting {wait}s...")
time.sleep(wait)Multiple Keys Best Practices
Create separate API keys for different environments — never share one key across everything:
- Development:
my-app-dev— for local testing - Staging:
my-app-staging— for pre-production - Production:
my-app-prod— for live traffic - CI/CD:
my-app-ci— for automated tests
If a key is leaked, you can revoke just that one without affecting other environments. Go to API Keys → click the three dots → Delete.
Monitoring Usage and Costs
The Console shows real-time usage at Settings → Usage. You’ll see:
- Token consumption per model
- Request counts
- Cost breakdown for the billing period
Set up spending alerts at Settings → Billing → Notifications to get emailed when you hit a cost threshold.
Free Tier and Pricing
There’s no permanent free tier, but Anthropic sometimes offers free credits for new accounts. After that, pay-as-you-go pricing applies:
# Approximate pricing (May 2026)
# Input tokens / Output tokens per million
claude-haiku-4-5: $0.80 / $4.00
claude-sonnet-4-5: $3.00 / $15.00
claude-opus-4-5: $15.00 / $75.00For most dev projects, claude-haiku-4-5 is the right choice — it’s fast, cheap, and handles most tasks well. Switch to claude-sonnet-4-5 when you need better reasoning.
See the full Claude API pricing breakdown for a detailed cost comparison.
Summary
- Sign up at console.anthropic.com and create a key under Settings → API Keys
- Store the key in an environment variable, never in code
- Add a payment method — billing is pay-as-you-go
- Test with
claude-haiku-4-5(cheapest model) before switching to Sonnet or Opus - Create separate keys per environment; revoke immediately if leaked
- Monitor spending via the Console and set billing alerts