Claude API Environment Setup Guide

Set up your Anthropic API key securely. Store it in .env files, environment variables, and secrets managers. Avoid hardcoding keys in source code.

💥 50p impulse-buy: Power Prompts PDF (first 10 buyers) 30 battle-tested Claude Code prompts · 8-page PDF · paste into CLAUDE.md and never re-type a prompt again · 50p impulse-buy, no commitment

Keeping your Anthropic API key secure is critical — leaked keys result in unexpected charges.

Step 1: Get your API key

  1. Go to console.anthropic.com
  2. Create an account or sign in
  3. Navigate to Settings → API Keys
  4. Click Create Key — give it a descriptive name (e.g. "dev-local")
  5. Copy the key immediately — it is shown only once

Step 2: Store in a .env file (local development)

# .env — add this to .gitignore
ANTHROPIC_API_KEY=sk-ant-api03-your-key-here
# Python — load with python-dotenv
pip install python-dotenv
from dotenv import load_dotenv
import anthropic

load_dotenv()  # reads .env into os.environ

client = anthropic.Anthropic()  # picks up ANTHROPIC_API_KEY automatically

Step 3: Add .env to .gitignore

# .gitignore
.env
.env.local
.env.*.local
*.key

Production: use a secrets manager

# AWS Secrets Manager example
import boto3
import json
import anthropic

def get_secret(secret_name: str) -> str:
    client = boto3.client("secretsmanager", region_name="us-east-1")
    response = client.get_secret_value(SecretId=secret_name)
    return json.loads(response["SecretString"])["ANTHROPIC_API_KEY"]

api_key = get_secret("prod/anthropic")
claude = anthropic.Anthropic(api_key=api_key)

Vercel / serverless deployment

# 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")

For Python quickstart once your key is set, see the Python quickstart. For Node.js, see the Node.js quickstart.

Frequently asked questions

Where do I get an Anthropic API key?
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.

Free tools

Cost Calculator → API Cookbook → Diff Summarizer → Skills Browser →

More examples

Claude API Python QuickstartClaude API Node.js / TypeScript QuickstartClaude API Streaming in PythonClaude API Streaming in Node.js / TypeScriptClaude API Tool Use in PythonClaude API Tool Use in Node.js / TypeScript