How to Get Your Claude API Key (Step-by-Step Guide)

The Claude API from Anthropic lets you build AI-powered applications using Claude models. Whether you’re integrating Claude into an app, using Claude Code from the terminal, or connecting to tools like Cursor, you’ll need an Anthropic API key.

Here’s how to get one, make your first API call, and avoid common pitfalls.

Prerequisites

You’ll need:

  • An email address (or Google/GitHub account)
  • A phone number for verification
  • A credit card for billing (there are free credits to start)

Step 1: Create an Anthropic Console Account

Head to console.anthropic.com and sign up. This is separate from a claude.ai chat account. Even if you already use Claude Pro or Max, you’ll need to create a console account specifically for API access.

The Claude Console sign-up page

Sign up with Google or email. You’ll need to verify your phone number.

Step 2: Generate Your API Key

Once you’re in the console:

  1. Click API keys under the Manage section in the left sidebar
  2. Click + Create Key
  3. Give it a descriptive name (e.g. my-app-dev, claude-code)
  4. Click Create Key

The API Keys page with the Create Key button

Your key will be displayed once. It starts with sk-ant-. Copy it immediately and store it somewhere safe. You won’t be able to see it again.

Save your API key dialog - copy it now, you won't see it again

Step 3: Set Up Billing

New accounts get a small amount of free credits. To keep using the API after they run out, add a payment method:

  1. Go to Settings > Billing
  2. Add a credit card
  3. Optionally set a monthly spend limit (recommended)

The API is pay-as-you-go. You’re charged per token (roughly per word) based on which model you use. More on pricing below.

Make Your First API Call

First, set your API key as an environment variable. Both SDKs read ANTHROPIC_API_KEY automatically, so you never need to hardcode it:

export ANTHROPIC_API_KEY="sk-ant-your-key-here"

Python

Install the SDK:

pip install anthropic
import anthropic

client = anthropic.Anthropic()  # Reads ANTHROPIC_API_KEY from environment

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "What is an API key in one sentence?"}
    ]
)

print(message.content[0].text)

JavaScript / TypeScript

Install the SDK:

npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic(); // Reads ANTHROPIC_API_KEY from environment

const message = await client.messages.create({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  messages: [
    { role: "user", content: "What is an API key in one sentence?" },
  ],
});

console.log(message.content[0].text);

cURL

curl https://api.anthropic.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "What is an API key in one sentence?"}
    ]
  }'

The anthropic-version header tells the API which version of the response format to use. Use the latest version from the API docs.

For a deeper dive on .env files, .gitignore setup, and what to do if you accidentally commit a key, see my guide on how to use .env files to keep your API keys out of Git.

Using Your API Key with Claude Code

If you’re using Claude Code (Anthropic’s CLI coding agent), it will prompt you for your API key on first run:

npm install -g @anthropic-ai/claude-code
claude

Claude Code reads from the ANTHROPIC_API_KEY environment variable. Set it in your shell profile (.bashrc, .zshrc, etc.) so it persists:

echo 'export ANTHROPIC_API_KEY="sk-ant-your-key-here"' >> ~/.zshrc
source ~/.zshrc

Claude API Pricing

The API uses token-based pricing. Here’s what the main models cost (as of March 2026):

ModelInput (per 1M tokens)Output (per 1M tokens)Best for
Claude Haiku 3.5$0.80$4.00Fast, cheap tasks
Claude Sonnet 4$3.00$15.00Balanced performance
Claude Opus 4$15.00$75.00Complex reasoning

For context, 1 million tokens is roughly 750,000 words. A typical API call for a short task costs fractions of a cent.

Free credits: New accounts receive a small amount of free credits (typically $5) to experiment with. No billing setup required to use them.

Does Claude Pro Include API Access?

No. This is the most common point of confusion. Claude Pro ($20/month) and Claude Max ($100/month) are subscriptions for the claude.ai chat interface. They do not include API credits.

The API is a completely separate product with its own pay-as-you-go billing. You can use both, but they’re independent accounts and charges.

Is the Claude API Free?

Sort of. You get a small amount of free credits when you first sign up. After that, it’s pay-as-you-go. There’s no free tier with ongoing monthly credits.

If you need free access to Claude models, OpenRouter offers some free-tier Claude access for low-volume use.

Keep Your API Key Secure

A few rules:

  • Never commit it to git. Use .env files and add .env to your .gitignore. I wrote a full guide on using .env files if you’re not sure how.
  • Never expose it in frontend code. API calls should happen server-side.
  • Use separate keys for different projects. If one gets compromised, you only need to rotate that one.
  • Set spend limits. In the console under Billing, set a monthly cap so a bug or leak doesn’t run up a surprise bill.
  • Rotate keys periodically. You can create new keys and delete old ones from the console at any time.

Quick Reference

WhatWhere
Create accountconsole.anthropic.com
Generate API keyManage > API keys > + Create Key
API docsdocs.anthropic.com
Pricinganthropic.com/pricing
Python SDKpip install anthropic
JavaScript SDKnpm install @anthropic-ai/sdk
Status pagestatus.anthropic.com