How to Get a Claude AI API Key (Step-by-Step)
If you want to call Claude from your own code, you need an API key — a credential that authenticates your requests to Anthropic's servers instead of a browser session. This guide walks through the exact steps: creating an account, setting up billing, generating the key, and making your first request. It also covers a faster path if you already pay for Claude.ai and don't want to set up a separate billing account.
Two things trip people up most often: confusing your Claude.ai chat login with API access (they're separate systems), and forgetting that the API requires prepaid credit before any request will succeed. Fix those two points and the rest takes about ten minutes.
Step 1: Create an Anthropic Console account
The API key comes from the Anthropic Console, not from claude.ai.
- Go to console.anthropic.com
- Sign up with an email address (or Google/GitHub SSO)
- Verify your email
- Complete the organization setup — you'll be asked for a name and sometimes an intended use case
Your claude.ai subscription and your Console account are not linked. Paying for Claude Pro does not give you API credit, and having API credit does not give you Claude Pro. They're billed and provisioned separately.
Step 2: Add billing and prepaid credit
The Anthropic API is pay-as-you-go with no free tier for production use. Before your key will work:
- In the Console, go to Settings → Billing
- Add a payment method
- Purchase credit (minimum purchase amounts apply and vary by region)
Without credit on the account, every API call returns a billing/quota error even if the key itself is valid. This is the single most common reason a "working" key suddenly stops working — the balance ran out.
Step 3: Generate the API key
- Go to Settings → API Keys
- Click Create Key
- Give it a name you'll recognize later (e.g.,
backend-prod,local-dev) - Copy the key immediately — it starts with
sk-ant-and is shown only once
Store it in an environment variable, not in source code:
export ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxx
Step 4: Make your first request
Test the key with a minimal request:
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4-5",
"max_tokens": 100,
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}'
A 200 response with a content array means the key works and billing is active. A 401 usually means a bad key; a 400 or credit-related error usually means the account has no balance.
Step 5: Set limits before you ship
Once the key works, go back to Settings → Limits in the Console and set a spend cap. New API accounts have no ceiling by default, and a bug that loops a Claude call in production can burn through credit fast. This step is easy to skip and expensive to skip.
What if you already pay for Claude.ai and don't want a second billing setup?
Some teams already have a Claude.ai subscription and just want programmatic access without managing a separate Anthropic Console account, prepaid credit balance, and spend limits. That's a common enough situation that tools exist specifically for it.
SubToAPI turns an existing Claude subscription into an HTTPS API with its own key (sub_live_...), so you skip the Console setup entirely. Instead of x-api-key, you send:
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4-5",
"max_tokens": 100,
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}'
You get streaming responses, tool use, usage metadata per key, and team seats for sharing access without sharing credentials — all from one dashboard. Plans start at €9/month (Solo), with Team at €19/seat and Scale at €49/seat, and there's a free trial at /signup. Full request/response formats are in /docs/messages and /docs/quickstart if you want to see the exact payloads before signing up.
This is worth considering if you're a solo developer testing an idea, or a small team that wants shared API access without every member managing their own Anthropic billing account.
Getting a Claude AI API key: the short version
- Direct from Anthropic: Console account → add billing → generate key → test with curl → set spend limits. Free to sign up, but the API itself is prepaid usage — no free API tier.
- Via SubToAPI: sign up, get a
sub_live_key immediately, start making requests with no separate billing account to configure. See /pricing for plan details.
Either path gets you an HTTPS endpoint you can call from a backend, script, or app. The right choice depends on whether you want direct Anthropic billing and rate limits, or a faster setup layered on top of a subscription you already have.
questions
Is the Claude AI API key the same as my claude.ai login? No. Your claude.ai account handles the chat interface; the API key comes from a separate Anthropic Console account with its own billing. You can have one without the other.
Why does my Claude API key return an error even though it looks correct? The most common cause is an empty billing balance, not a bad key. Check Settings → Billing in the Console — the API requires prepaid credit and returns errors on every request once it runs out.
Can I get a Claude API key without setting up Anthropic billing separately? Yes — services like SubToAPI issue an API key backed by an existing Claude subscription, so you skip the Console billing setup and get a working key right after signup.