How to Get a Claude API Key (Step-by-Step, 2026)
A quick, no-nonsense guide to creating an Anthropic Claude API key, adding credits, keeping it secure, and making your first API call in code.
Getting a Claude API key takes about two minutes. This guide walks through creating one in the Anthropic Console, adding credits, keeping the key secure, and making your first call — with the mistakes to avoid.
Step 1 — Create an Anthropic account
Go to console.anthropic.com and sign up (or log in). The Console is Anthropic's developer dashboard — separate from the Claude.ai chat app. Your Claude.ai subscription and your API billing are two different things; API usage is pay-as-you-go and billed separately.
Step 2 — Add a payment method and credits
Before a key will work, you need credits:
- In the Console, open Settings → Billing.
- Add a payment method.
- Buy a starting credit amount (you can begin small — even $5 is enough to test).
API pricing is per token (roughly, per word) and varies by model — smaller, faster models cost a fraction of the largest ones. You're only charged for what you use, so a bit of testing costs cents.
Step 3 — Generate the API key
- Go to Settings → API Keys.
- Click Create Key.
- Give it a descriptive name (e.g.
my-app-dev). - Copy it immediately — you're shown the full key only once. If you lose it, revoke it and create a new one.
Create separate keys per app and per environment (dev, staging, prod). It makes it painless to rotate or revoke one without breaking everything else.
Step 4 — Store the key securely (don't skip this)
The single most common mistake: pasting the key directly into code and pushing it to GitHub. Automated scrapers find committed keys within minutes.
Instead, put it in an environment variable:
# .env.local — and make sure .env* is in .gitignore
ANTHROPIC_API_KEY=sk-ant-...your-key...
Never hard-code it, never expose it in frontend/browser code, and never commit it. If a key ever leaks, revoke it in the Console right away.
Step 5 — Make your first call
With the key in an env var, here's a minimal Node.js request using the official SDK:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic(); // reads ANTHROPIC_API_KEY automatically
const msg = await client.messages.create({
model: "claude-sonnet-5",
max_tokens: 300,
messages: [{ role: "user", content: "Say hello in one sentence." }],
});
console.log(msg.content[0]);
Run it and you'll get a response back. That's the whole loop: authenticate with the key, send messages, read the reply.
Common questions
Is the Claude API key free? The key itself is free to create, but calls cost credits. There's no perpetual free tier — you pay per token, starting from a few dollars of credit.
Why is my key returning a 401? Either the key is wrong/revoked, or it isn't being loaded from your environment. Log process.env.ANTHROPIC_API_KEY (length only, never the value) to confirm it's present.
Why a 400 about credits? You have a valid key but no credit balance — add credits in Billing.
Can I use one key for multiple apps? You can, but don't. One key per app/environment keeps rotation and debugging clean.
That's it — you now have a working Claude API key and your first call. From here it's tool use, streaming, and building real features. If you want to see what shipping with the Claude API looks like in production, take a look at the projects below.
I build AI-native products with the Claude API and MCP. Here's what that looks like in production.
See the projects I build with ClaudeWritten by Antonio Kodheli
Full-stack web developer in Boston. I build modern web apps with TypeScript, Next.js, and the Claude API — and write about it here.