Skip to content
Antonio Kodheli

Claude API: How to Get an API Key and Make Your First Call (2026)

Start with the Claude API in minutes: create an Anthropic API key in the Claude Console, add credits, keep the key secure and make your first call to the Anthropic API in Node.js.

Antonio Kodheli··3 min read

The Claude API (also called the Anthropic API) is how your own code talks to Claude. Getting a Claude API key takes about two minutes. This guide walks through creating one in the Claude 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 platform.claude.com (the Claude Console, formerly console.anthropic.com) and sign up or log in. The Console is Anthropic's developer dashboard for the Anthropic API, 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:

  1. In the Console, open Settings → Billing.
  2. Add a payment method.
  3. 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. For every model's rates and worked cost examples, see Claude API pricing.

Step 3: Generate the API key

  1. Go to Settings → API Keys.
  2. Click Create Key.
  3. Give it a descriptive name (e.g. my-app-dev).
  4. 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-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 of the Claude API: authenticate with the key, send messages, read the reply.

Where to go from the Claude API

The Messages API above is the raw building block: you send messages and write any tool loop yourself. If you want an agent that can read files, run commands and call tools without writing that loop, look at the Claude Agent SDK, which uses the same ANTHROPIC_API_KEY. To give Claude access to your own app's data and actions, build an MCP server.

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 my Claude projects

Written 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.