Anthropic API keys are created on the API keys page of the Claude Console (platform.claude.com/settings/keys) and sent as Authorization: Bearer <key> (the legacy x-api-key header still works). SDKs read the ANTHROPIC_API_KEY environment variable. You choose an expiry from 3 hours to Never when you create the key.
Anthropic key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| Personal key Archived when you are removed from the organization. | sk-ant-api | Yes | Acts as you, with your roles and permissions, in one workspace or the workspaces your role allows | Chosen at creation (3 hours, 1 day, 7 days, 30 days, custom or Never); stops working if you lose access to the organization |
| Service account key Recommended for shared or automated workloads such as CI and production services. | sk-ant-api | Yes | Acts as a service account, in one workspace or anything the service account can access | Chosen at creation; stops working when the service account is archived |
| Workspace key (legacy) Still works but Anthropic calls it legacy and prefers identity-backed keys or Workload Identity Federation. | sk-ant-api | Yes | The single workspace it was created in | Expires, or is disabled or deleted, or its workspace is archived |
How to create a Anthropic key
- Sign in to the Claude Console.
- Open the API keys page (
platform.claude.com/settings/keys) and click Create key. - Name the key and pick an expiration.
- Set Linked account to yourself for a personal key, or to a service account for a shared key.
- Optionally scope the key to one workspace, then copy it.
Limiting what the key can do
A key can be scoped to a single workspace. A key not scoped to a workspace must send the anthropic-workspace-id header on every request. Use workspaces to separate environments and control spend.
How to rotate a Anthropic key
- Create a new key on the API keys page, scoped to the integration's workspace.
- Deploy it wherever the old one is read, typically
ANTHROPIC_API_KEYor a secrets manager entry. - Confirm requests succeed, then delete the old key.
Expiration is set at creation and cannot be changed afterwards. Anthropic emails the creator before expiry for keys with a lifetime of at least 7 days.
How to revoke a Anthropic key
- Open the API keys page in the Claude Console.
- Click Disable to turn a key off reversibly (it can be re-enabled), or Delete to archive it permanently.
If your Anthropic key leaked
- Delete the exposed Anthropic API key on the API keys page (three-dot menu, Delete API key), or Disable it first if you must investigate.
- Create a replacement with Create key and store it in a secrets manager, not in version control.
- Check the Logs and Usage pages in the Claude Console for requests you do not recognise.
- Set spend limits on the Billing page (or turn on auto-reload with a careful threshold) so a leaked key cannot run up unexpected usage.
- Prefer a short expiration or Workload Identity Federation for the new credential.
- Contact Anthropic Support if suspicious API activity continues. Anthropic is a GitHub secret scanning partner, so when GitHub finds an Anthropic API key in a public repository, Anthropic deactivates it and emails the account holder.
Environment variables and CLI
Anthropic's SDKs and docs read the key from ANTHROPIC_API_KEY.
Anthropic CLI (ant): Reads ANTHROPIC_API_KEY from the environment
Things that catch people out
- Expired keys return
401 authentication_errorand cannot be reactivated. - A key not scoped to a workspace is rejected with a 400 unless the
anthropic-workspace-idheader is sent. - Disable is reversible; Delete is permanent.
- Anthropic suggests rotating keys on a fixed schedule, such as every 90 days.
Common Anthropic authentication errors
authentication_error
HTTP 401. The key is malformed, revoked or expired.
permission_error
HTTP 403. The key does not have permission to use the requested resource.
Recent incidents that put Anthropic keys at risk
If you were affected by one of these, rotate your Anthropic keys using the rotation steps above.
- LiteLLM 1.107.0 on PyPI and Docker carried a credential stealer after a leaked master key 2026-10-21
- OpenCode Console breach may have exposed users' linked AI provider API keys 2026-10-17
- OpenCode on Windows and WSL ran commands from a malicious MCP server during OAuth sign-in 2026-10-04
- OpenCode server's upgrade endpoint let any webpage install an attacker's npm package 2026-09-24
- Cursor before 3.0: prompt-injected agent could escape its sandbox and run code as the user 2026-06-05
- Claude Code trust dialog could be bypassed with a spoofed git worktree, running repo hooks 2026-04-24
Using your Anthropic key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a Anthropic key, these intents fit:
| Intent | What BotPassword does |
|---|---|
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
rotate | Partly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet. |
store_secret | Saves a value the agent already holds as a new vault item. |
capture_secret | Planned, not built yet: will read a newly created key straight from the page or command output into the vault. |
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
Where do I find my Anthropic API key?
Create one at platform.claude.com/settings/keys in the Claude Console. Existing keys cannot be shown again.
What is the Anthropic API key environment variable?
The SDKs read ANTHROPIC_API_KEY.
Do Anthropic API keys expire?
You choose at creation: a preset (3 hours, 1 day, 7 days, 30 days), a custom duration, or Never. Your organization may cap the maximum.
What should I do if my Anthropic API key is compromised?
Delete the key on the API keys page of the Claude Console, create a replacement, and check the Logs and Usage pages. Contact Anthropic Support if suspicious activity continues.
What happens if I push an Anthropic API key to GitHub?
Anthropic is a GitHub secret scanning partner. GitHub notifies Anthropic when it finds an Anthropic API key in a public repository, and Anthropic deactivates the key and emails the account holder.
What is the difference between disabling and deleting an Anthropic API key?
Disabling turns the key off and can be undone; deleting archives it permanently.
Can an AI agent use my Anthropic key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, store_secret, so the agent gets the result and never the value.