Claude API keys: how to get, scope, store, rotate, and revoke them
A Claude API key is a static secret, starting with sk-ant-, that authenticates requests to the Claude API and draws on the credits of the organization that created it. Claude API keys, which Anthropic also calls Anthropic API keys, are created in the Claude Console at platform.claude.com, and the old console.anthropic.com address now redirects there. This guide covers getting a key and then the choices that limit what a leaked key can do: key type, workspace scope, expiration, storage, rotation, and revocation. It belongs to the AI engineering fundamentals hub.
What is a Claude API key?#
A Claude API key is a secret credential from the Claude Console that a program sends with every Claude API request to identify the organization, workspace, and identity behind it. Each key belongs to one organization, its usage is billed to that organization, and the Console never displays the full secret after creation.
Claude API keys are one of four credentials that reach Claude:
| Credential | Where it comes from | What it authenticates | Format or billing |
|---|---|---|---|
| Claude API key | API keys page in the Claude Console | Messages and the other Claude API endpoints | Starts with sk-ant-api; usage is billed to the Console organization |
| Admin API key | Admin keys page, created by organization admins | Admin API, usage and cost reports, Rate Limits API | Starts with sk-ant-admin01- in Console organizations |
| Claude plan login | A Pro, Max, Ultra, Team, or Enterprise plan | Claude apps and Claude Code sign-in | Billed separately from the API |
| Cloud provider credentials | AWS, Google Cloud, or Microsoft Azure | Claude on Amazon Bedrock, Google Cloud, and Microsoft Foundry | The cloud provider's IAM and billing |
Anthropic's API overview states that requests through a cloud platform authenticate with that provider's IAM system, not with a Console key, so this guide covers the first row only.
How to get a Claude API key#
You get a Claude API key by signing in to the Claude Console, making sure the organization has credits, and clicking Create key on the API keys page. Creating the key is free, but every request is billed, usually from prepaid credits, and the Console shows the full secret only once, so copy it straight into a secrets manager. The steps, as of November 2026:
- Sign in. Go to platform.claude.com and sign in, or create a Console account.
- Add credits. API calls and the playground stop working at a zero balance, so a user with the Admin or Billing role buys credits first on the Billing page (
platform.claude.com/settings/billing), as Anthropic's billing article explains. Purchased credits expire one year after purchase. - Open the API keys page at
platform.claude.com/settings/keysand click Create key. - Configure the key. Enter a name, select an expiration, and set Linked account to yourself (a personal key) or to a service account (a service account key). Optionally, pick a workspace to scope it to.
- Copy the secret. The full key starts with
sk-ant-and appears once. Store it in a secrets manager right away.
If Create key is disabled, your role does not allow key creation there. Organization developers and admins can manage keys, as can the Workspace Developer and Workspace Limited Developer roles inside a workspace, while the organization user role can only use the playground. Ask an admin to change your role or to create a service account key, as Anthropic's key guide suggests.
Make a test request#
Set the key as an environment variable and send a small request. The official SDKs read ANTHROPIC_API_KEY automatically, and direct HTTP requests send the key as a bearer token:
export ANTHROPIC_API_KEY="sk-ant-api03-..."
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": 64,
"messages": [{"role": "user", "content": "Reply with OK."}]
}'A JSON response with a content array confirms the key works. Claude Haiku 5.5, the fastest and lowest-priced model in Anthropic's November 2026 lineup, keeps the test cheap, and the Anthropic release history lists the others. The legacy x-api-key header also still works in place of Authorization.
Choose the right key type#
Use a personal key for your own development and scripts, and a service account key for anything shared, such as CI pipelines, production services, and AI agents. Both types are identity-backed: each acts as a user or service account the organization manages and stops working when that identity is removed. Skip workspace keys, a legacy type, for new integrations.
| Key type | Acts as | Stops working when | Use it for |
|---|---|---|---|
| Personal key | You, with your roles and permissions | You lose access to the organization; the key is archived when you are removed | Your own development and scripts |
| Service account key | A service account that an organization admin creates | The service account is archived | CI, production services, and agents |
| Workspace key (legacy) | No one; it belongs to the workspace it was created in | It expires, is disabled or deleted, or its workspace is archived | Existing integrations you plan to migrate |
The difference shows up during offboarding. A shared personal key breaks the integration when its owner leaves, and a workspace key keeps working for anyone who copied it, while a service account key outlives its creator and stops only when an admin archives the service account. Anthropic's authentication docs add that a single-workspace key also stops working when its owner loses access to that workspace.
To retire a workspace key, have an organization admin create a service account on the Service accounts page (platform.claude.com/settings/service-accounts), create a key for the integration's workspace, deploy it, confirm that requests succeed, and delete the old key.
Scope Claude API keys to workspaces#
Scope each key to a single workspace, and give development, staging, and production their own workspaces. A key created for one workspace always runs there, so its requests can omit the workspace ID. A key without a workspace scope must send an anthropic-workspace-id header on every request, or the Claude API returns a 400 invalid_request_error.
A workspace groups members, service accounts, API keys, and limits inside one organization. Every organization has a Default Workspace that cannot be renamed, archived, or deleted, and only organization admins can create more. Workspace IDs start with wrkspc_ and appear in the ID column of the Workspaces page.
For a key without a workspace scope, set the header once on the SDK client:
from anthropic import Anthropic
client = Anthropic( # reads ANTHROPIC_API_KEY
default_headers={"anthropic-workspace-id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"},
)Successful responses carry an anthropic-workspace-id header naming the workspace each request counted against.
Workspaces also cap what a leaked key can spend. Set a monthly spend limit per workspace on the Spend limits page, and per-model rate limits in requests, input tokens, and output tokens per minute on the Rate limits page. Workspace limits can sit below the organization's limits but cannot raise them.
Check two side effects before reorganizing:
- Archiving a workspace archives every API key created for it within seconds, and the archive cannot be undone.
- Prompt caches are isolated by workspace on the Claude API, so splitting one workload across workspaces also splits its cache.
Set an expiration on every key#
Pick the shortest expiration the job allows when you create a key, because the expiration cannot be changed afterward. The Console offers presets of 3 hours, 1 day, 7 days, or 30 days, a custom duration, or Never, which Anthropic intends for keys stored in a secrets manager and rotated on your own schedule.
An organization's maximum expiration policy caps presets and custom durations and removes Never. Anthropic emails the creator 7 days before expiry for keys with a lifetime of at least 14 days, and 1 day before for keys of at least 7 days. An expired key returns 401 authentication_error and can only be deleted, not reactivated, as the key expiration docs explain.
| Use case | Suggested expiration | Warning email |
|---|---|---|
| Workshop, demo, or contractor test | 3 hours or 1 day | None |
| Personal development key | 7 or 30 days | 1 day ahead (7 days) or 7 days ahead (30 days) |
| CI pipeline that cannot use federation | 30 days, rotated by the pipeline | 7 days ahead |
| Production service in a secrets manager | Never, with scheduled rotation | Not applicable |
These are this guide's suggestions, not Anthropic defaults.
Store and use Claude API keys safely#
Keep Claude API keys out of source code. Load each key from the ANTHROPIC_API_KEY environment variable during development and from encrypted secret storage in the cloud, call Claude only from your back end, and give every person and workload its own key, so one key can be revoked without breaking the others.
Anthropic's key safety article adds these rules:
- Use the environment variable. The official SDKs read
ANTHROPIC_API_KEY, so the key stays out of code. - Git-ignore
.envfiles. List local.envfiles in.gitignore, and use the cloud provider's secret manager in deployments. - Keep keys personal. Give each person their own key, and never paste one into email, forums, or support tickets, including tickets to Anthropic.
- Vet third-party tools. A key uploaded to a web IDE or CI platform gives that tool's developer access to your Console account, so store it there only as an encrypted secret.
- Scan for secrets. Run secret scanning, with a tool such as Gitleaks, in source control and CI before code reaches the main branch.
Anthropic also takes part in GitHub's secret scanning partner program. When GitHub detects a Claude API key in a public repository, Anthropic deactivates the key automatically and emails the affected user.
Never ship a key in browser code, where anyone using the page can read it; the front end should call your back end, which holds the key. The API rejects cross-origin browser requests without the anthropic-dangerous-direct-browser-access: true header, and organizations with zero data retention or the Compliance API enabled cannot call it from a browser at all.
Teams with many services can put an AI gateway in front of Claude, so the gateway holds the provider key and each application gets its own virtual key. Keys also leak through agents: a key pasted into a prompt, a tool result, or a log line is exposed to every system that reads that text, a risk the MCP security guide covers for tool servers.
Rotate a Claude API key without downtime#
Rotate a key by running the replacement alongside the old key until traffic has moved, then retiring the old key in two steps: disable it, and delete it after a quiet period. Anthropic's key safety article recommends rotating on a consistent schedule and gives every 90 days as an example.
- Create the new key with the same type, workspace, and linked account, plus an expiration.
- Store it in your secrets manager under the name your service reads, usually
ANTHROPIC_API_KEY. - Deploy, then confirm on the Console's Logs and Usage pages that requests succeed.
- Disable the old key. Disable is reversible, so Re-enable restores it if a forgotten job still depended on it.
- Delete the old key once no authentication errors appear. Delete is permanent, and the Admin API lists the key as
archived.
Audit keys with the Admin API#
The Admin API reads and updates existing keys across an organization, but it cannot create them. List API Keys returns each key's status, its expires_at timestamp (null when the key never expires), its scope, and its principal, which is null for a legacy workspace key. Update API Key renames a key or sets its status to active, inactive, or archived.
# Active keys with no expiration, a common audit target
curl "https://api.anthropic.com/v1/organizations/api_keys?status=active&limit=100" \
-H "x-api-key: $ANTHROPIC_ADMIN_KEY" \
-H "anthropic-version: 2026-10-21" \
| jq -r '.data[] | select(.expires_at == null) | "\(.id) \(.name) \(.partial_key_hint)"'
# Disable one key (reversible with status "active")
curl "https://api.anthropic.com/v1/organizations/api_keys/$API_KEY_ID" \
-H "x-api-key: $ANTHROPIC_ADMIN_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d '{"status": "inactive"}'The Admin API accepts an Admin API key, an org:admin OAuth token, or a personal or service account key without a workspace scope; workspace keys do not work there. Only organization admins can create Admin API keys, and an individual Console account must set up an organization first. No endpoint returns a key's secret, only a partially redacted hint such as sk-ant-api03-R2D...igAA.
Revoke a Claude API key after a leak#
Revoke a key on the API keys page of the Console. Disable stops the key and can be undone, while Delete archives it permanently. If a key may have leaked, delete it right away, create and deploy a replacement, and then review the Logs and Usage pages for requests you do not recognize.
Anthropic's steps for a compromised key are short:
- On the API keys page, open the menu (three horizontal dots) next to the key and select Delete API key.
- Click Create key, store the replacement in a secrets manager, and redeploy the affected services.
- Review the Logs (
platform.claude.com/logs) and Usage pages for unfamiliar traffic. - Contact Anthropic support if suspicious activity continues.
When exposure is uncertain, Disable stops the key at once and can still be undone. After the incident, limit what the next leaked key could do:
- Spend limit. Set your own monthly limit below your tier's cap on the Spend limits page. Once usage reaches it, requests return HTTP 400 instead of accumulating charges, as the spend limit docs describe.
- IP allowlisting. IP allowlisting, in beta as of November 2026, lets an organization admin or owner list the public IP ranges allowed to call the API. Requests from anywhere else get a 403
permission_error, so a stolen key fails outside your network. Changes take up to 15 minutes, so list every server, CI runner, VPN, and office network first.
Claude API key errors and fixes#
Most key problems surface as a 401, 403, 400, 404, or 429 response, and the error type and message usually name the cause: a bad or expired key, a missing permission or blocked IP address, a missing workspace header, an unreachable workspace, or a limit. Anthropic's error reference lists every code.
| Status and type | Key-related cause | Fix |
|---|---|---|
401 authentication_error |
The key is malformed, disabled, deleted, or expired | Check the stored value; create and deploy a new key |
403 permission_error |
The key lacks access to the resource, or the IP address is outside the allowlist | Check workspace access and the allowlist |
400 invalid_request_error |
The key has no workspace scope and the header is missing, or your own spend limit is reached | Add anthropic-workspace-id, or raise the limit |
404 not_found_error |
The workspace ID does not exist, or the key's identity has no access to it | Check the ID and the account's workspace membership |
429 rate_limit_error |
A rate limit, or the tier's monthly spend cap | Wait for retry-after; for the cap, request a tier increase |
A spend-cap 429 carries no retry-after header and has the error_code enforced_spend_limit_reached, and retries fail until the next month starts at 00:00 UTC or the tier is raised. As of November 2026, the Start, Build, and Scale tiers cap monthly spend at $500, $1,000, and $200,000. Logging status codes per service, part of LLM observability, surfaces a revoked or expired key before users report it.
How to use a Claude API key with Claude Code#
Claude Code uses an API key when ANTHROPIC_API_KEY is set and you approve it at the prompt, and that key takes priority over a Pro, Max, Ultra, Team, or Enterprise subscription login. To go back to the subscription, run unset ANTHROPIC_API_KEY, then run /status to confirm which credential is active.
Claude Code's authentication docs give the full precedence order when several credentials are present:
- Cloud provider credentials, when
CLAUDE_CODE_USE_BEDROCK,CLAUDE_CODE_USE_VERTEX, orCLAUDE_CODE_USE_FOUNDRYis set ANTHROPIC_AUTH_TOKEN, sent as a bearer token, for LLM gateways and proxiesANTHROPIC_API_KEY, sent as theX-Api-Keyheader- The output of an
apiKeyHelperscript, for rotating or vault-issued credentials CLAUDE_CODE_OAUTH_TOKEN, a long-lived token fromclaude setup-token- Anthropic profile and federation credentials
- The subscription login from
/login
In interactive mode, Claude Code asks once whether to use the key and remembers the answer, which the "Use custom API key" toggle in /config changes; with -p, the key is always used. A key from a disabled or expired organization therefore breaks sessions even for subscribers.
Signing in with a Console account instead mints a per-user API key in the organization's Claude Code workspace, and that key stops working when the member is removed. The Claude Code vs Cursor comparison covers plan pricing, and the AI coding agents guide covers team rollout.
When to replace static API keys#
Move a production workload to Workload Identity Federation once it runs somewhere with a platform identity, such as AWS, Google Cloud, Azure, GitHub Actions, or Kubernetes. Federation exchanges that identity for short-lived Claude API tokens with the same API access as a key, so there is no sk-ant-api string to distribute or rotate.
With Workload Identity Federation, the workload exchanges its identity provider's token at POST /v1/oauth/token for a short-lived access token that the SDK refreshes automatically. Setup needs a service account, a federation issuer, and a federation rule in the Console. Federation is only as strong as the identity provider's configuration, so protect any static credential that can mint its tokens.
Two other cases avoid static keys:
- Local development. Anthropic's quickstart recommends signing in with the
antCLI throughant auth login, after which the SDKs and CLI pick up the credential automatically. - iOS and macOS apps. App Attest issues each genuine installation of a registered app a token that is scoped to a workspace, expires after 1 hour, and authorizes only Messages API calls.
Where to go next#
With Claude API keys scoped and on a rotation schedule, the next step is building with them. The guide to building an AI agent puts a key to work in a Python agent loop, the AI engineer roadmap places model APIs in a wider learning path, and the model providers directory compares Anthropic with the other labs that offer model APIs.
Frequently asked questions
Is a Claude API key free?
- Creating a Claude API key costs nothing, but using it does. Claude API requests usually draw on prepaid usage credits that a user with the Admin or Billing role buys on the Console's Billing page, and an organization with no credits cannot call the API or use the playground. Claude Max, Ultra, and Team plans include monthly API credits once a Console organization is linked to the plan.
Where do I find my Claude API key?
- Claude API keys are listed on the API keys page of the Claude Console at platform.claude.com/settings/keys, and the old console.anthropic.com address redirects there. The page shows each key's name and expiration but never the full secret, which the Console displays only once, at creation. If the secret is lost, create a new key, deploy it, and delete the old one.
Can I view or copy my Claude API key again?
- No. The Claude Console shows the full key, which starts with sk-ant-, only once, when it is created. Afterward neither the Console nor the Admin API can reveal it; the Admin API returns only a partially redacted hint that helps identify the key. Copy each new key straight into a secrets manager, and replace any key whose secret has been lost.
Does a Claude Pro or Max subscription include API access?
- A Claude subscription and the Claude API are billed separately: paid plans cover the Claude apps, and API usage runs on Console credits. Of the paid plans, Anthropic lists Max, Ultra, and Team as including monthly API credits, claimed by linking a Claude Console organization to the plan. Those credits expire at the end of each billing cycle and cannot be spent in Claude Code or the Claude apps.
Are Claude API keys the same as Anthropic API keys?
- Yes. Anthropic's documentation uses both names for the same credential: a secret starting with sk-ant- that is created in the Claude Console and authenticates requests to the Claude API. The Console moved from console.anthropic.com to platform.claude.com, while the API itself is still served from api.anthropic.com. Admin API keys, which start with sk-ant-admin01- in Console organizations, are a separate credential for organization management.
Do Claude API keys work with Amazon Bedrock or Google Cloud?
- They are separate credentials. Claude on Amazon Bedrock, Google Cloud, and Microsoft Foundry authenticates through the cloud provider's IAM system and bills through the cloud account, while a Claude Console key authenticates the first-party Claude API. Console controls follow the same split: Anthropic's IP allowlist, for example, does not apply to Claude on Amazon Bedrock, Google Cloud, or Microsoft Foundry.
Terms in this guide
Cite this guide
The AI Engineering Editors. "Claude API keys: how to get, scope, store, rotate, and revoke them." The AI Engineering, updated Nov 23, 2026. https://theaiengineering.com/articles/claude-api-keys
- Title
- Claude API keys: how to get, scope, store, rotate, and revoke them
- Author
- The AI Engineering Editors
- Publisher
- The AI Engineering
- Published
- Updated