# Anthropic API keys: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/anthropic
Last checked: 2026-11-08

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Personal key | `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 | `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) | `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

1. Sign in to the Claude Console.
2. Open the **API keys** page (`platform.claude.com/settings/keys`) and click **Create key**.
3. Name the key and pick an expiration.
4. Set **Linked account** to yourself for a personal key, or to a service account for a shared key.
5. 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](https://platform.claude.com/settings/workspaces) to separate environments and control spend.

## How to rotate a Anthropic key

1. Create a new key on the API keys page, scoped to the integration's workspace.
2. Deploy it wherever the old one is read, typically `ANTHROPIC_API_KEY` or a secrets manager entry.
3. Confirm requests succeed, then delete the old key.

## How to revoke a Anthropic key

1. Open the API keys page in the Claude Console.
2. Click **Disable** to turn a key off reversibly (it can be re-enabled), or **Delete** to archive it permanently.

## If the key leaked

1. Delete the exposed Anthropic API key on the [API keys](https://platform.claude.com/settings/keys) page (three-dot menu, **Delete API key**), or **Disable** it first if you must investigate.
2. Create a replacement with **Create key** and store it in a secrets manager, not in version control.
3. Check the **Logs** and **Usage** pages in the Claude Console for requests you do not recognise.
4. 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.
5. Prefer a short expiration or Workload Identity Federation for the new credential.
6. 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

- `ANTHROPIC_API_KEY`

## Gotchas

- Expired keys return `401 authentication_error` and cannot be reactivated.
- A key not scoped to a workspace is rejected with a 400 unless the `anthropic-workspace-id` header is sent.
- Disable is reversible; Delete is permanent.
- Anthropic suggests rotating keys on a fixed schedule, such as every 90 days.

## Using this key with AI agents (BotPassword)

- `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.

## FAQ

### 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.

## Sources

- https://platform.claude.com/docs/en/manage-claude/authentication
- https://platform.claude.com/docs/en/api/overview
- https://platform.claude.com/docs/en/api/errors
- https://support.claude.com/en/articles/8384961-what-should-i-do-if-i-suspect-my-api-key-has-been-compromised
- https://support.claude.com/en/articles/9767949-api-key-best-practices-keeping-your-keys-safe-and-secure
- https://docs.github.com/en/code-security/secret-scanning/introduction/supported-secret-scanning-patterns
