# Set via Vercel CLI
vercel env add ANTHROPIC_API_KEY production
# Or in vercel.json (use env vars, not literal values)
# In your function:
import anthropic
client = anthropic.Anthropic() # reads process.env.ANTHROPIC_API_KEY in Node.js
Check your key is working
import anthropic
client = anthropic.Anthropic()
try:
# Cheapest possible call to verify auth
r = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=10,
messages=[{"role": "user", "content": "Hi"}]
)
print("Key valid. Model:", r.model)
except anthropic.AuthenticationError:
print("Invalid API key — check ANTHROPIC_API_KEY in your environment")
Sign up at console.anthropic.com. Create an account, go to Settings → API Keys, and click 'Create Key'. Free tier includes rate-limited access immediately. For higher limits, add a payment method and request a tier upgrade.
How does the SDK find my API key?
The SDK reads `ANTHROPIC_API_KEY` from the environment by default. If you load a `.env` file before initializing the client, the key is available. You can also pass it explicitly: `Anthropic(api_key='sk-ant-...')` — but never hardcode keys in source code.
Can I use multiple API keys in the same codebase?
Yes. Create separate `Anthropic(api_key=key)` instances for each key. Common use case: per-customer keys for usage tracking, or a low-rate key for testing and a high-rate key for production.