Anthropic API Key: Create, Use and Secure It
October 27, 2026

To get an Anthropic API key, sign in to the Claude Console at platform.claude.com, open Settings → API keys, click Create key, pick a name, expiration and linked account, then copy the key. It starts with sk-ant- and is shown only once. Add credits on the Billing page, set the key as the ANTHROPIC_API_KEY environment variable, and you can call Claude from curl or the official SDKs.
That's the two-minute version. The rest of this guide covers what causes trouble later: picking the right key type, workspaces and spend limits, how prepaid billing works, and what 401, 400 and 429 errors actually mean.
If you're new to the idea of an API key, start with our plain-English explainer. If you're mainly hunting for free usage, this guide to free Claude API access covers credit programs and what Pro does and doesn't include.
How to get an Anthropic API key in the Claude Console
Every Anthropic API key lives in the Claude Console, Anthropic's developer platform. The docs also call them Claude API keys; same thing. The old console.anthropic.com address now points to platform.claude.com.
Here's the flow, following Anthropic's get your API key guide:
- Sign in or create a Console account at platform.claude.com. This is a separate account area from the Claude chat app, with its own billing.
- Open the API keys page. It's under Settings, at
platform.claude.com/settings/keys. - Click Create key and give it a name you'll recognize, like "invoice-bot-prod".
- Choose an expiration. Presets are 3 hours, 1 day, 7 days or 30 days. You can also set a custom duration, or Never.
- Set the Linked account. Pick yourself for a personal key, or a service account for anything shared.
- Optionally scope it to a workspace. A scoped key only works there, which is usually what you want.
- Copy the key and store it. The Console shows the full key once. Lose it and you can't view it again; you create a new one.
If Create key is greyed out, your role doesn't allow it; ask an organization admin.
Personal, service account or workspace key?
The key type decides who the key acts as and when it stops working. Anthropic's authentication docs describe three:
| Key type | Acts as | Stops working when | Use it for |
|---|---|---|---|
| Personal key | You, with your roles | You leave the organization (or lose access to its workspace) | Your own scripts and local development |
| Service account key | A service account an admin created | The service account is archived | CI pipelines, production apps, agents, anything shared |
| Workspace key (legacy) | No one; it belongs to the workspace | It expires, is disabled or deleted, or the workspace is archived | Older setups only |
The practical rule: personal key for you, service account key for anything another person or machine depends on. A shared personal key breaks the day its owner leaves. Workspace keys still work, but Anthropic treats them as legacy and recommends identity-backed keys for new integrations.
Set up a workspace before you create the key
A workspace groups API keys, members, files and usage inside your Console organization, so you can separate projects or environments while billing stays in one place.
Every organization starts with a Default Workspace that can't be renamed, archived or deleted. The catch, per Anthropic's workspaces documentation: you can't set a spend limit on the Default Workspace. So if you're about to plug a key into a third-party app or an experimental agent, give it its own workspace first.
To create one, an organization admin goes to Settings → Workspaces, clicks Create workspace, enters a name and picks a color. After that:
- Spend limits: select the workspace on the Workspaces page and click Spend limits to cap monthly spending and set alerts.
- Rate limits: on the Rate limits page, pick the workspace from the dropdown and click Edit next to a model.
- Members: add people with a role. Workspace Developer and Workspace Limited Developer can create keys and call the API; Workspace User can only use the playground.
Workspace limits can be lower than your organization's limits, never higher. A common split is one workspace each for development, staging and production.
Add credits: how Claude API billing works
The Claude API runs on prepaid credits. You buy credits, and each request is deducted at current API rates. Anthropic's API billing article lays out the rules:
- Buying credits: someone with an Admin or Billing role opens the Billing page, clicks Buy credits, enters an amount and confirms. Credits are available immediately.
- Auto-reload: under Credit balance, Set up auto-reload tops you up to a target balance whenever you fall below a trigger balance you choose.
- Expiry and refunds: purchased credits expire one year after purchase and are non-refundable.
- What's charged: only successful calls. A request that disconnects or times out while it was on track to succeed is still billed.
- Running out: at zero balance you can't call the API or use the playground until you add more.
Per-token rates differ by model; the current numbers are on Anthropic's pricing page.
There are also ceilings. Your organization sits in a usage tier (new accounts may start in a lower Evaluation tier), and the Start, Build and Scale tiers each carry a monthly spend cap. You can set your own, lower spend limit on the Billing page. The rate limits documentation lists each tier's caps and per-model limits.
A Claude subscription doesn't include API billing
This trips up a lot of people. Paying for Claude Pro or Max gets you the chat apps, not an API balance. Anthropic's help center says Claude paid plans and the Claude Console are separate products, and that the Claude API is billed separately.
One exception worth knowing: per the billing article above, linking a Console organization to a Max or Team plan grants a monthly allowance of API credits. Those are used before purchased credits, expire at the end of each billing cycle, and don't work in Claude Code or the Claude apps.
How to use your Anthropic API key
Don't paste the key into your code. Put it in an environment variable called ANTHROPIC_API_KEY, which the official SDKs read automatically.
On macOS or Linux, for the current terminal session:
export ANTHROPIC_API_KEY="sk-ant-api03-..."
To make it stick, add that line to your shell profile (~/.zshrc or ~/.bashrc) and open a new terminal. The examples below assume the variable is set this way.
You can keep the key in a project .env file instead (list it in .gitignore), but nothing reads that file automatically. Load it before you run anything:
- Shell: with a line like
ANTHROPIC_API_KEY=sk-ant-api03-...in.env, runset -a; source .env; set +ain the terminal you'll use. - Python:
pip install python-dotenv, then callload_dotenv()before you create the client:
from dotenv import load_dotenv
load_dotenv() # reads .env into os.environ
Call Claude with curl
The fastest way to confirm the key works is one request to the Messages API. Direct HTTP requests send the key as a bearer token:
curl https://api.anthropic.com/v1/messages \
-H "Authorization: Bearer $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello, Claude"}]
}'
You'll get a JSON response with Claude's reply in content. The older x-api-key header still works in place of Authorization, which is why you'll see it in many tutorials.
Call Claude with the Python SDK
Install the official Anthropic Python SDK with pip install anthropic, then:
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude"}],
)
for block in message.content:
if block.type == "text":
print(block.text)
Both examples use the model ID from Anthropic's quickstart. Model IDs change as new models ship, so check the current list first.
One more header to know: if your key isn't scoped to a workspace, every request must also send anthropic-workspace-id with the workspace's ID (it starts with wrkspc_). A workspace-scoped key skips this.
Using the key with Claude Code
Claude Code reads ANTHROPIC_API_KEY too. Per the Claude Code authentication docs, once you approve it, the key takes priority over your Pro or Max login and usage bills to your API balance. Run unset ANTHROPIC_API_KEY to fall back to your subscription, and check /status to see which credential is active. For building your own agents on top of the API, see our Claude Agent SDK guide.
Keep your Anthropic API key safe
Anyone holding your key can spend your balance. Most leaks are a key committed to GitHub or shared in a screenshot, and these habits prevent nearly all of them.
- Never commit it. Keep keys in environment variables or a secrets manager. Add
.envto.gitignorebefore your first commit, not after. - Search before you push. Every Anthropic key starts with
sk-ant-, sogit grep "sk-ant-"catches one that slipped into a file. - Set an expiration. A key that expires in 30 days limits how long a leak is useful. Anthropic emails the creator before longer-lived keys expire.
- Scope it to one workspace with a spend limit. If the key leaks, the damage stops at that workspace's cap.
- One key per app. Separate keys mean you can kill one integration without breaking the others, and usage is easier to trace.
- Rotate on a schedule. Create the new key, deploy it, confirm requests succeed, then delete the old one.
If you think a key has leaked, act on the API keys page right away. Disable is reversible: you can re-enable the key later. Delete is permanent. Disable first if you're unsure which app depends on it; delete once you've confirmed it's compromised.
For production workloads, Anthropic also supports Workload Identity Federation, which swaps static keys for short-lived tokens from your identity provider.
Common Anthropic API key errors and how to fix them
Every API error comes back as JSON with an error.type, a message and a request_id. These are the ones tied to keys and billing. Status codes and error types follow Anthropic's error reference:
| Status | What it usually means | Fix |
|---|---|---|
401 authentication_error | The key is malformed, revoked or expired | Check for stray spaces or quotes; expired keys can't be reactivated, so create a new one |
| 400 "credit balance is too low" | Your organization has no usable credits | Buy credits on the Billing page, and confirm the key belongs to the organization you funded |
| 400 spend limit reached | You hit a spend limit you set on the organization or workspace | Raise or remove the limit, or wait for the date in the message |
| 400 missing workspace header | The key isn't scoped to a workspace | Send anthropic-workspace-id, or use a workspace-scoped key |
402 billing_error | A problem with your payment details | Update payment info in the Console |
403 permission_error | The key can't use that resource | Check organization and workspace access |
429 rate_limit_error | You exceeded requests or tokens per minute | Wait the seconds in the retry-after header, then retry with backoff |
429 with no retry-after | You hit your tier's monthly spend cap | Retries keep failing; request a tier increase on the Rate limits page |
529 overloaded_error | The API is busy across all users | Retry after a short wait |
Two of these deserve a note.
The credit balance error with money in the account. This often means the key belongs to a different organization or workspace than the one you topped up. It's common in Claude Code when a stale ANTHROPIC_API_KEY from your shell is billing another account.
429s on a brand-new account. New organizations can start with lower Evaluation-tier limits that rise with usage history. Bursts count too: Anthropic notes a 60-requests-per-minute limit might be enforced as one request per second. The official SDKs retry rate limits twice by default with exponential backoff.
When you contact support about a failed call, include the request_id. It's how Anthropic finds the exact request.
Where Taku fits
An API key is the right tool when you're writing code against Claude. But plenty of people search for one because an AI app someone else built starts its setup with "paste your Anthropic API key," followed by environment variables, a repo, and the errors above.
If that setup step is where you keep stalling, Taku mirrors an AI app someone already got working into a desktop workspace where you can run it, edit it and save it as your own. You can browse what's there in the Taku marketplace. Taku is in Beta, and the Mac app is available now.
FAQ
Is an Anthropic API key free?
Creating the key costs nothing, but using it draws on prepaid credits. Anthropic runs credit programs for some researchers and startups; the free Claude API guide linked at the top covers which ones are real.
Can I see my API key again after creating it?
No. The Console shows the full key once, at creation, and you can't view it again. If you lose a key, create a new one and delete the old one.
Does Claude Pro or Max include an API key?
No. Subscriptions and the API are billed separately. Max and Team plans linked to a Console organization do get a monthly allowance of API credits, but you still create the key and manage it in the Console.
What's the difference between an Anthropic API key and a Claude Code login?
A Claude Code login through Pro or Max uses your subscription's usage limits. An ANTHROPIC_API_KEY bills your Console credit balance at API rates. If both are set, Claude Code uses the key once you approve it.
Can I use my Anthropic API key on Amazon Bedrock or Google Cloud?
No. Claude is also available through cloud providers such as Amazon Bedrock and Google Cloud, but those use your cloud account's credentials and billing, not a Console key.
Where are the Anthropic API docs?
Under platform.claude.com/docs (console.anthropic.com now redirects to platform.claude.com). Start with the quickstart, then the authentication, rate limits and errors pages linked above.