To get a Claude API key, sign in to the Claude Console at platform.claude.com, add a payment method and buy prepaid usage, then open the API keys page, click Create key, choose an expiration and copy the key. It starts with sk-ant- and the Console shows it only once. Put it in the ANTHROPIC_API_KEY environment variable and the official SDKs read it on their own.
A Claude Pro or Max subscription doesn't come with a key: the claude.ai apps and the API are billed separately. If you searched for a "Claude AI API key" or how to get an Anthropic API key, it's the same key, which Anthropic's docs describe as "also called Anthropic API keys".
Below: the Console as of 5 November 2026, code tested with anthropic 2.4.0 (Python) and @anthropic-ai/sdk 1.4.0 (TypeScript), and the mistakes that cost people hours.
How to get a Claude API key, step by step
The Claude API console lives at platform.claude.com. Older guides call it the Anthropic API console at console.anthropic.com, which now redirects there.

- Create a Console account and organization, or sign in. Your claude.ai email works; the two accounts run independently. The API is offered only in Anthropic's supported regions.
- Fill in the details Anthropic asks for about your organization and use case, then add a card on the Billing page and buy prepaid usage. Only the Admin or Billing role can buy, and the balance is usable right away.
- Open the API keys page and click Create key. Give it a name, pick an expiration, set Linked account to yourself (a personal key) or to a service account, and optionally limit it to one workspace. If Create key is disabled, your role doesn't allow it; ask an organization admin.
- Copy the key and store it. Anthropic's examples show the prefix
sk-ant-api03-. A lost key can't be viewed again, so create a new one. - Set
ANTHROPIC_API_KEYand run the test script below, which checks the key without generating tokens, then sends one request to Claude Haiku 5.5.
On your own machine you can skip the key: ant auth login in Anthropic's ant CLI (2.5.0) signs you in through the browser, and the quickstart says the SDKs pick that sign-in up. For CI and servers, Anthropic points to Workload Identity Federation instead.
Personal, service account or workspace key
Since 27 August 2026 the Console asks which kind of key you want. Guides written before then show only one kind.
| Key type | Acts as | Stops working when | Use it for |
|---|---|---|---|
| Personal key | You, with your roles and permissions | You leave the organization, or lose access to its workspace | Your own development and scripts |
| Service account key | A service account an admin creates | The service account is archived or removed from the workspace | CI, production services, agents |
| Workspace key (legacy) | Nobody: it belongs to the workspace | It expires, is disabled or deleted, or the workspace is archived | Older integrations; Anthropic recommends replacing them |
A personal key shared across a team breaks the day its owner leaves, so give anything shared a service account key.
Expiration (added 8 July 2026) is fixed at creation: 3 hours, 1 day, 7 days, 30 days, a custom duration or Never. Anthropic emails the creator 7 days before expiry for keys that live at least 14 days, and 1 day before for keys that live at least 7. An expired key returns 401 authentication_error and can't be reactivated.
Disable on the API keys page is reversible with Re-enable. Delete is permanent.
Workspaces: one per project
Workspaces split one organization's keys, limits and usage by project or environment. Every organization has a Default Workspace that can't be renamed, archived or deleted, and up to 100 more by default. Only organization admins create them: Workspaces page, Create workspace, a name and a color.
Why bother on day one:
- You can set a monthly spend limit and lower rate limits on each workspace (spend limits aren't available on the Default Workspace). A runaway script then stops at its own limit instead of draining the whole balance.
- A key scoped to one workspace works only there, so a leaked staging key can't touch production.
- Archiving a workspace archives every key created for it within seconds, and it can't be undone.
A personal or service account key that isn't scoped to a workspace has to name one on every request, or the API returns a 400 invalid_request_error:
This API key is not scoped to a workspace, so this request must include the anthropic-workspace-id header with the ID of the workspace to use. Add the header, or use an API key that is scoped to a workspace.
The wrkspc_ ID is in the ID column on the Workspaces page. Set it once on the client:
import anthropic
client = anthropic.Anthropic(
default_headers={"anthropic-workspace-id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"},
)
The simpler fix is to scope each key to its workspace when you create it.
What it costs to start
There's no real free tier. Anthropic's pricing FAQ says new users get a small amount of free usage for testing, without stating an amount, and its billing help article states no minimum purchase. What it does state: usage is prepaid in US dollars by card (invoicing is for accounts arranged with sales), a purchase expires one year after you buy it and isn't refundable, and auto-reload can buy more when the balance falls below a level you set.
A test request costs very little. At 1,000 input and 500 output tokens (thinking counts as output), at list prices:
| Model | ID | Input / output per 1M | Per test request | Test requests per $10 |
|---|---|---|---|---|
| Claude Haiku 5.5 | claude-haiku-5-5 | $0.10 / $0.50 | $0.00035 | 28,571 |
| Claude Sonnet 5.5 | claude-sonnet-5-5 | $2.00 / $10.00 | $0.007 | 1,428 |
| Claude Opus 5.5 | claude-opus-5-5 | $4.00 / $20.00 | $0.014 | 714 |
| Claude Fable 5.2 | claude-fable-5-2 | $8.00 / $40.00 | $0.028 | 357 |
Haiku 5.5's price applies to prompts up to 100,000 tokens; longer prompts cost $0.50 / $2.50. The Claude API pricing guide covers caching, Batch and long-context rates.
Max, Ultra and Team subscribers may not need a card at all (see below). For auto-reload and declined cards, see paying for Claude API usage and fixing a failed payment.
Claude API rate-limit tiers
Your organization's tier sets both its rate limits and a monthly spend cap. Anthropic's help center says "Usage tiers are assigned automatically" and that no deposit or purchase moves you up.

| Tier | How you get there | Monthly spend cap | Sonnet 5.5, Opus 5.5, Haiku 5.5 (RPM / input TPM / output TPM) |
|---|---|---|---|
| Evaluation | New organizations with little usage history | Not published | Below Start, not published |
| Start | Automatic | $500 | 4,000 / 2,000,000 / 400,000 |
| Build | Automatic, or on request | $1,000 | 10,000 / 5,000,000 / 1,000,000 |
| Scale | Automatic, or on request | $200,000 | 13,000 / 10,000,000 / 2,000,000 |
| Custom | Arranged with sales | None | Arranged |
- Sonnet 5.5, Opus 5.5 and Haiku 5.5 each get these limits separately, and cached input reads don't count toward input tokens per minute on most models.
- Ask for more with Request tier increase on the Rate limits page, once you're using at least 50% of your current limits.
- An organization linked to a Max, Ultra or Team plan moves to at least Start, and to at least Build if its included monthly usage is over $200.
- The Start cap matters early: at $30 a day you hit $500 on day 17, and requests return a 429 until 00:00 UTC on the 1st or a tier increase. The rate limit exceeded guide covers retries.
Store the key safely
Anthropic's own advice: one key per person and per environment, environment variables or a secrets manager, .env files kept out of source control, rotation on a schedule such as every 90 days, and secret scanning in your repositories.
Set the variable for your shell:
# macOS and Linux: this terminal only
export ANTHROPIC_API_KEY="sk-ant-api03-..."
# Keep it across sessions (zsh shown; use ~/.bashrc for bash)
echo 'export ANTHROPIC_API_KEY="sk-ant-api03-..."' >> ~/.zshrc
# Windows: saved for new terminals; open a new one afterwards
setx ANTHROPIC_API_KEY "sk-ant-api03-..."
A key in your shell profile reaches every program you start, Claude Code included. For a project, a .env file is tidier:
echo 'ANTHROPIC_API_KEY=sk-ant-api03-...' > .env
echo '.env' >> .gitignore
Then:
- In production, use a service account key from a secrets manager. On AWS, Google Cloud, Azure, GitHub Actions or Kubernetes, Workload Identity Federation (launched 4 May 2026) trades a short-lived identity token for API access, so there's no static key to leak.
- Never ship a key to a browser, where anyone can read it in the page's code. Call Claude from your own back end.
- Give keys an expiration. A 30-day key that leaks stops working on its own.
- If a key leaks, delete it on the API keys page, create a new one, and check the Usage page for calls you didn't make.
Anthropic deactivates keys that GitHub's secret scanning finds in public repositories and emails the owner. Since 13 October 2026, GitHub also blocks commits containing Anthropic keys by default in repositories with secret scanning on, free public ones included.
Use the key in Python, TypeScript and curl
This script checks the key with a model listing, which generates no tokens, then makes one real request. It ran against the live API with anthropic 2.4.0 on Python 3.14 (3.10 or later is required) and, with a bad key, printed the 401 branch.
# pip install anthropic python-dotenv
import anthropic
from dotenv import load_dotenv
load_dotenv() # copies ANTHROPIC_API_KEY from .env into the environment
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY; never paste the key here
try:
# 1. Check the key. Listing models generates no tokens.
print("Key accepted:", [m.id for m in client.models.list(limit=3).data])
# 2. First real request, on the lowest-priced current model
message = client.messages.create(
model="claude-haiku-5-5",
max_tokens=1000, # thinking counts toward this and is billed as output
messages=[{"role": "user", "content": "In one sentence, what is an API key?"}],
)
for block in message.content:
if block.type == "text":
print(block.text)
print("Tokens in/out:", message.usage.input_tokens, message.usage.output_tokens)
except anthropic.AuthenticationError as e: # 401
print("Key rejected:", e.message, e.request_id)
except anthropic.PermissionDeniedError as e: # 403
print("Key not allowed here:", e.message, e.request_id)
except anthropic.APIStatusError as e: # 400 balance or spend limit, 429, 5xx
print(e.status_code, e.message, e.request_id)
The TypeScript version ran with @anthropic-ai/sdk 1.4.0 on Node 26, which runs .ts files directly and loads .env with a flag: node --env-file=.env first-call.ts. Anthropic's quickstart uses npx tsx instead.
// npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic(); // reads ANTHROPIC_API_KEY
try {
// 1. Check the key. Listing models generates no tokens.
const models = await client.models.list({ limit: 3 });
console.log("Key accepted:", models.data.map((m) => m.id));
// 2. First real request
const message = await client.messages.create({
model: "claude-haiku-5-5",
max_tokens: 1000,
messages: [{ role: "user", content: "In one sentence, what is an API key?" }],
});
for (const block of message.content) {
if (block.type === "text") console.log(block.text);
}
} catch (err) {
if (err instanceof Anthropic.AuthenticationError) {
console.error("Key rejected:", err.message, err.requestID); // 401
} else if (err instanceof Anthropic.PermissionDeniedError) {
console.error("Key not allowed here:", err.message, err.requestID); // 403
} else {
throw err;
}
}
With curl, send the key as a bearer token. The older x-api-key header still works. The SDKs add anthropic-version for you; by hand, use the current version, 2026-10-21.
curl https://api.anthropic.com/v1/messages \
-H "Authorization: Bearer $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d '{"model": "claude-haiku-5-5", "max_tokens": 1000,
"messages": [{"role": "user", "content": "Hello, Claude"}]}'
Log the request ID (e.request_id in Python, err.requestID in TypeScript). Anthropic support asks for it.
Claude API key errors and how to fix them

| What you see | Status and type | Usual cause | Fix |
|---|---|---|---|
x-api-key header is required | 401 authentication_error | No key reached the API | Set ANTHROPIC_API_KEY in the process that runs the code |
invalid x-api-key | 401 authentication_error | Typo, extra characters, a deleted, disabled or expired key, or a subscription token | Create a new key; check what's in the environment |
This API key is not scoped to a workspace... | 400 invalid_request_error | Key covers several workspaces | Send anthropic-workspace-id, or scope the key |
permission_error | 403 | The key's user or service account can't use that resource | Ask an organization admin to check roles |
Your credit balance is too low to access the Anthropic API... | 400 invalid_request_error | The organization's prepaid balance is empty | Buy usage, or check which organization the key belongs to |
You have reached your specified API usage limits | 400 invalid_request_error | A spend limit someone in your organization set | Raise or remove it on the Billing page |
enforced_spend_limit_reached | 429 rate_limit_error | The tier's monthly spend cap | Request a tier increase, or wait for the 1st |
The two 401 messages are what api.anthropic.com returned on 5 November 2026 to a request with no key and with a made-up one. A bearer header and a key with a trailing space got the same invalid x-api-key.
Five mistakes behind most of these:
- A subscription token used as a key. Claude subscription tokens start with
sk-ant-oat, API keys withsk-ant-api; sent as a key, a subscription token getsinvalid x-api-key. - A stray variable. Both SDKs read
ANTHROPIC_BASE_URL, so a leftover value from a proxy setup sends every request to that host. Both also warn and use the key whenANTHROPIC_AUTH_TOKENis set too. Runenv | grep ANTHROPICwhere your code runs. - A line break or space pasted with the key. Claude Code refuses to send a key containing a line break.
- A key from another organization. Each key draws on its own organization's balance, so it can fail while the Console you're looking at shows money.
- No variable at runtime. With no key, the Python SDK raises a
TypeError("Could not resolve authentication method") at the first request, not when you create the client. Cron jobs, containers and systemd services don't read~/.zshrc.
Claude Pro or Max vs a Claude API key
A paid Claude plan and the Claude Console are separate products with separate billing. The one exception, added 7 October 2026: Max, Ultra and Team plans include monthly API usage.
| Plan | Monthly API usage included | Notes |
|---|---|---|
| Free, Pro | None | Buy prepaid usage in the Console |
| Max | $100 | Claim after 7 days on the plan |
| Ultra | $200 | Same |
| Team | $20 per Standard seat, $100 per Premium seat, pooled, capped at $500 | Claimed by a Team owner |
| Enterprise | None | Not eligible for this program |
To claim it, link one Console organization under Settings > Billing on claude.ai. It arrives each billing cycle, expires at the end of it, and is spent before anything you've bought. It covers the API, Managed Agents, the Agent SDK and the Console playground, but not interactive Claude Code.
In Claude Code the trap runs the other way. Once you approve it, ANTHROPIC_API_KEY outranks your subscription login, and claude -p always uses it. A key in your shell profile moves Claude Code onto API billing, and an empty Console balance then shows Credit balance is too low. Run /status, then unset ANTHROPIC_API_KEY to go back to the subscription. The Claude Code API key guide covers the setup.
What developers report
- "no indication this is a separate billing system from claude.ai subscriptions" (GitHub issue on claude-code-action, 14 Mar 2026, link)
- A subscription token (
sk-ant-oat…) passed asANTHROPIC_API_KEYmade every request from a Claude Code plugin fail with 401invalid x-api-key; moving it toANTHROPIC_AUTH_TOKENfixed it (GitHub issue on claude-plugins-official, 30 Oct 2026, link) - With $100 showing in the Console, every call returned the empty-balance 400, even token counting, which points to an account-level block (GitHub issue on claude-code, 1 Sep 2026, link)
- A Hacker News commenter's Anthropic key, stored in a Railway deployment, was disabled for unauthorized use about three hours after Railway's breach notice, after roughly $20 of Opus 4.8 usage (Hacker News, 22 Oct 2026, link)
- Another commenter, with a key in a plain environment variable on Northflank, learned of that host's breach from the Hacker News front page six hours later, with no email (Hacker News, 31 Oct 2026, link)
- "The following detectors are now included in push protection by default." The list includes Anthropic's service and user API keys (GitHub changelog, 13 Oct 2026, link)
Claude through an Aight key
If you call Claude next to other models through the OpenAI Chat Completions format, Aight gives you one sk-aight- key for Claude, GPT, Gemini, DeepSeek and the rest of its 138 models. Claude Sonnet 5.5 is $2.00 / $10.00 and Claude Opus 5.5 $4.00 / $20.00, the same as Anthropic's list prices.
What it adds to the key safety above: each key can have a monthly cap (a 403 key_cap_reached when it's hit), an expiry date and a list of allowed models. Balance is prepaid in US dollars from $5 plus 3% processing outside India, every recharge adds 10% extra (about $0.94 per $1 of list-price usage), and the balance doesn't expire, where Anthropic's purchases lapse after a year.
Where going direct is the better choice:
- Aight documents only Chat Completions, embeddings and the model list. The Anthropic SDKs and Claude Code speak Anthropic's Messages API, so they don't work with an Aight key.
- Anthropic's Message Batches API halves the price, and Aight documents no batch endpoint, so batch work costs less direct.
- Claude Fable 5.2 isn't on Aight's models page yet. Haiku 5.5 is, at Anthropic's $0.10 / $0.50.
The one-key setup guide shows the base URL and code.
FAQ
Is the Claude API free?
Not in any lasting way. Anthropic says new users get a small amount of free usage for testing, without stating an amount, and after that the API is prepaid. Max and Ultra include $100 and $200 a month of API usage, and Team plans up to $500.
Where can you see an existing Claude API key?
Nowhere. The Console shows the full key once, at creation, and afterwards the Admin API returns only a redacted hint. Create a new key, update your environment, then delete the old one.
Do Claude API keys expire?
Only if you choose an expiration when you create the key: 3 hours, 1 day, 7 days, 30 days, a custom duration or Never. If your organization has a maximum expiration policy, Never isn't offered. Expired keys return a 401 and can't be reactivated.
Does a Claude API key work with the OpenAI SDK?
Yes, through Anthropic's OpenAI-compatible endpoint at https://api.anthropic.com/v1/. Anthropic describes it as mainly for testing and comparing models, not a long-term production route, and recommends its own SDKs for full features.
Should every project get its own key?
Yes. Every key in an organization draws on the same balance, so give each project a workspace with a spend limit and a key scoped to it. A leaked or looping key then costs one key, not the account.
Sources
- Anthropic Claude docs: Get your Claude API key, Authentication (key types, expiration, workspace header, browser use, Workload Identity Federation), Get started, CLI authentication
- Anthropic Claude docs: Workspaces, Rate limits, Errors, Versions, Release notes (4 May, 8 July and 27 August 2026)
- Anthropic Claude docs: Pricing, Models overview, API usage for Max, Ultra and Team plans, OpenAI SDK compatibility
- Claude Help Center: paying for API usage, Claude plan vs API billing, Claude and Console accounts, starting with a new Console organization, higher rate limits, API key best practices, compromised keys, Agent SDK with a Claude plan
- Anthropic, Supported regions
- Claude Code docs: Authentication (precedence), Errors
- SDK and CLI releases: anthropic on PyPI, @anthropic-ai/sdk on npm, anthropic-cli releases
- GitHub: secret scanning changelog, 13 Oct 2026; issues claude-code-action #1053, claude-plugins-official #6955, claude-code #91322
- Hacker News: Railway security disclosure thread, Northflank breach thread
- Live API responses from api.anthropic.com and SDK test runs, 5 November 2026
- Aight: Models and pricing, API reference, Refund policy
Checked on 5 November 2026. Updated 17 November 2026: Claude Fable 5.2, and Aight's current model list.