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-5 before switching to Sonnet or Opus
- Create separate keys per environment; revoke immediately if leaked
- Monitor spending via the Console and set billing alerts