← Blog

How to Generate an API Key for Anthropic Projects

2026-09-03 · 5 min read · SubToAPI Team

Generating an API key for Anthropic means creating credentials in the Anthropic Console that let your application call Claude programmatically instead of through the chat interface. The process takes about five minutes: create an account, set up billing, open the API Keys section, and click generate. The part that trips people up isn't the button click — it's naming the key correctly, scoping it to the right workspace, and storing it so it doesn't leak into a git history six months later.

This guide walks through the full process, plus the decisions you should make along the way (workspaces, key naming conventions, rotation) that most quick tutorials skip.

Step 1: Create or Sign In to an Anthropic Console Account

Go to the Anthropic Console and sign in with Google, or create an account with an email and password. This account is separate from consumer Claude.ai — even if you already use Claude.ai daily, you'll need a Console account to generate API keys, and it has its own billing.

If you're setting this up for a company, decide now whether this is a personal account or an organization account. Organizations support multiple workspaces and team members, which matters once more than one person needs access.

Step 2: Add Billing Details

The Anthropic API is prepaid or postpaid depending on your account type, but either way you need a valid payment method on file before you can generate a working key. Navigate to Billing in the Console sidebar and add a card. New accounts sometimes come with a small free credit grant, but you shouldn't count on this — check your account status directly rather than assuming.

Without billing set up, you can technically generate a key, but requests will fail until credits or a payment method are attached.

Step 3: Create a Workspace (Optional but Recommended)

Workspaces let you separate API usage and keys by project, environment, or team. If you're just testing something solo, you can skip this and use the default workspace. But if you're building something that will eventually have a staging environment, a production environment, and maybe a separate internal tools project, create workspaces now:

Each workspace gets its own keys, spend limits, and usage dashboard. This makes it much easier to answer "why did our bill spike" later, because you can see exactly which workspace and key generated the cost.

Step 4: Generate the API Key

Inside the Console, go to API Keys and click Create Key. You'll be asked for:

Click generate, and the key appears once, in full, starting with sk-ant-. Copy it immediately — the Console will only ever show you the full value at creation time. After that, you'll only see a truncated version for identification purposes.

Step 5: Store the Key Securely

Never paste the key directly into your source code. Use environment variables:

export ANTHROPIC_API_KEY="sk-ant-xxxxxxxxxxxxxxxx"

And reference it in code:

const apiKey = process.env.ANTHROPIC_API_KEY;

Add .env to your .gitignore before you add the key to a .env file, not after. If you're deploying to a hosting platform (Vercel, Railway, Fly.io, etc.), use their secrets manager rather than baking the key into a config file that gets committed.

If a key does leak — in a commit, a screenshot, a log file — revoke it immediately from the Console and generate a replacement. There's no way to "un-leak" a key; rotation is the only fix.

Step 6: Test the Key

A quick curl request confirms the key works before you build anything on top of it:

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-sonnet-4-20250514",
    "max_tokens": 100,
    "messages": [{"role": "user", "content": "Say hello in one sentence."}]
  }'

A successful response confirms billing, key permissions, and connectivity are all working.

Where This Gets Complicated for Teams

A single API key works fine for one developer building one app. It gets messier once you have a team, multiple applications, or customers who each need their own credentials. Anthropic's Console gives you workspaces and org-level keys, but it doesn't give you per-application keys with independent rate limits, usage breakdowns per key, or a way to hand out access without sharing the same underlying secret.

That's the gap SubToAPI fills. Instead of managing raw Anthropic keys across your stack, you generate application-scoped keys (sub_live_...) from one dashboard, each with its own usage metadata, and route them through a single HTTPS endpoint that supports streaming, tool use, and standard Messages-style requests. It's useful once "generate one key" turns into "manage keys for five services and three team members."

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 100,
    "messages": [{"role": "user", "content": "Say hello in one sentence."}]
  }'

Check the quickstart if you want to see the full request/response shape, or pricing for Solo, Team, and Scale plans — all with a free trial at signup.

questions

Do I need a credit card to generate an Anthropic API key? You can generate the key without one, but it won't successfully process requests until a valid payment method is attached in the Billing section of the Console.

Can I have more than one API key on the same Anthropic account? Yes. You can create as many keys as you need, each independently named and optionally assigned to a different workspace, and revoke them individually without affecting the others.

What's the difference between an Anthropic Console account and Claude.ai? They're separate systems with separate logins and billing. Claude.ai is the consumer chat product; the Console is where you manage API keys, workspaces, and programmatic usage.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →