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.
This article was originally published at kalyna.pro
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.
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
*.env
Step 5: Test Your Key
Python:
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY automatically
message = client.messages.create(
model="claude-haiku-4-5",
max_tokens=64,
messages=[{"role": "user", "content": "Say hello!"}],
)
print(message.content[0].text)
Node.js:
import 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);
curl:
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
| Tier | RPM | TPM | TPD |
|---|---|---|---|
| Tier 1 ($5+ spent) | 50 | 40,000 | 1,000,000 |
| Tier 2 ($100+/30d) | 1,000 | 80,000 | 2,500,000 |
| Tier 3 ($500+/30d) | 2,000 | 160,000 | — |
When rate-limited (HTTP 429), use 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
print(f"Rate limited. Waiting {wait}s...")
time.sleep(wait)
Multiple Keys Best Practices
Create separate keys per environment:
-
Development
my-app-dev— local testing -
Staging
my-app-staging— pre-production -
Production
my-app-prod— live traffic -
CI/CD
my-app-ci— automated tests
Revoke a compromised key without affecting others: API Keys → three dots → Delete.
Pricing Overview
| Model | Input (per 1M tokens) | Output (per 1M tokens) |
|---|---|---|
| claude-haiku-4-5 | $0.80 | $4.00 |
| claude-sonnet-4-5 | $3.00 | $15.00 |
| claude-opus-4-5 | $15.00 | $75.00 |
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-5before switching to Sonnet or Opus - Create separate keys per environment; revoke immediately if leaked
- Monitor spending via the Console and set billing alerts
Top comments (0)