How to rotate an Anthropic (Claude) API key
Anthropic has no API for creating keys, so every rotation starts in the Claude Console. Everything after that, including retiring the old key, can be scripted. Here is the order that avoids downtime.
- Key format
- API keys start with
sk-ant-(todaysk-ant-api03-). Admin API keys start withsk-ant-admin. - Where to create
- platform.claude.com/settings/keys. The full value is shown once.
- Create by API
- Not possible. The Admin API lists, retrieves and updates keys, but can't create one you can call Claude with.
- Retire by API
POST /v1/organizations/api_keys/{id}with{"status": "inactive"}, using an Admin API key.- Key types
- Personal keys (stop when you leave the org), service account keys (for workloads), and legacy workspace keys.
- Expiry
- Choose an expiration when you create the key. The API reports it as expires_at.
- Limits
- Scope a key to a workspace and give that workspace its own rate and spend limits in the Console.
- Leaks on GitHub
- Exposed keys in public repos are reported to Anthropic, which deactivates them and emails you. Push protection blocks them by default.
- Keysquid
- Assisted: you create the key, Keysquid distributes it and deactivates the old one.
Why Anthropic rotation starts by hand
With OpenAI or Cloudflare, a tool can mint a fresh key through the API. Anthropic deliberately doesn’t allow that: its docs say the Admin API “can’t recover a lost key or give you a key to call the Claude API with.” The Admin API endpoints for keys are list, retrieve and update. So a rotation always has one human step (create the key in the Console), and the rest is the usual overlap: two keys live at once, traffic moves, then the old key is switched off.
That one constraint makes the limits on the key more important. If you can’t rotate every hour, put the key in its own workspace with a spend limit, so a leaked key can only ever cost that much.
Rotate it by hand, step by step
- Create the replacement in the Console. Open API keys, click Create key, name it after what and when (for example
prod-api-2026-11), pick an expiration, link it to a service account rather than yourself, and select the same workspace as the old key. Copy the value straight into your secret store: the Console won’t show it again. - Roll it out with the old key still active. Update every platform, CI secret and
.envthat holdsANTHROPIC_API_KEY, and restart anything that reads it only at startup. - Verify the new key. A cheap authenticated call proves it works:
curl -s -o /dev/null -w "%{http_code}\n" "https://api.anthropic.com/v1/models?limit=1" \ -H "x-api-key: $NEW_ANTHROPIC_API_KEY" -H "anthropic-version: 2023-06-01" - Watch the old key go quiet. Check the Console’s Logs and Usage pages until nothing uses it any more.
- Deactivate the old key. In the Console, or with the Admin API. Find the key’s ID (
apikey_…) by listing keys, then set its status:
Deactivating rather than deleting means one call puts the key back if something you missed breaks.curl -s "https://api.anthropic.com/v1/organizations/api_keys?limit=100&status=active" \ -H "x-api-key: $ANTHROPIC_ADMIN_KEY" -H "anthropic-version: 2023-06-01" \ | jq -r '.data[] | [.id, .name, .partial_key_hint, (.expires_at // "never")] | @tsv' curl -s -X POST "https://api.anthropic.com/v1/organizations/api_keys/$OLD_KEY_ID" \ -H "x-api-key: $ANTHROPIC_ADMIN_KEY" -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" -d '{"status": "inactive"}' - Delete it later. Once a day or two has passed without complaints, delete the old key from its menu (⋯ → Delete API key) in the Console.
The Admin API key itself starts with sk-ant-admin, can be created only by organization members with the admin role, and should live in exactly one place: whatever runs step 5. It never goes into an app.
By hand vs. with Keysquid
By hand
- Remember that the key is due.
- Create it in the Console.
- Paste it into every platform and CI system.
- Redeploy, verify, watch logs.
- Deactivate and later delete the old key.
With Keysquid
- Keysquid reminds you on schedule.
- Create the key in the Console and paste it, with its key ID, into Keysquid in your browser.
- Keysquid verifies it, writes it to every mapped platform and redeploys.
- With an Admin API key connected, it deactivates the old key for you.
How Keysquid handles Anthropic keys
Assisted Anthropic doesn't offer an API that Keysquid can use to create keys, so rotation is assisted: Keysquid reminds you on schedule, you create the key, and Keysquid does the rest. Not automatic: Anthropic has no API for creating keys. Paste a new key and Keysquid distributes it and deactivates the old one.
Setup, as the app shows it:
- Automatic rotation isn't possible for Anthropic. Protect yourself first: put the key in its own workspace and set a monthly spend limit on it in the Claude Console.
- Create new keys in the Claude Console → API keys when Keysquid reminds you.
- Optional: an Admin API key (org admins only) lets Keysquid deactivate the previous key for you. When you paste a key, include its key ID (apikey_…).
- Writes to: API key (default variable ANTHROPIC_API_KEY), in every platform and secret store you map it to.
- Interval: from every 1 day to every 4 weeks, subject to your plan’s minimum.
- Workspace spend limit (set in Anthropic): Put this key in its own workspace and give the workspace a monthly spend limit. Anthropic only allows this in the Claude Console (not the Default Workspace).
- Inventory: Keysquid lists every Anthropic key the connection can see, including keys it doesn’t manage, with names and last use.
- Note: Anthropic keys can't be rotated automatically, because Anthropic doesn't offer an API to create them. Set a monthly spend limit on the key's workspace in the Claude Console so a leaked key can only ever cost that much.
When you paste the new key, Keysquid verifies it against Anthropic, writes it everywhere it is mapped, and redeploys where a platform needs it. If any write fails, the previous values are restored. With the optional admin credential connected, it then retires the previous key for you. The value is encrypted to the agent you run, so Keysquid’s servers never see it.
If an Anthropic key leaked
- Deactivate it now, before you have a replacement. A few failed requests are cheaper than someone else’s usage on your bill.
- Pushed to a public GitHub repo? Anthropic is a GitHub secret scanning partner: GitHub notifies Anthropic, which deactivates the exposed key and emails you. Treat the email as the start of your incident, not the end of it: the key was public until then.
- Check Logs and Usage in the Console for requests you don’t recognise.
- Block the next one. Since October 13, 2026, GitHub push protection blocks Anthropic keys by default in repositories with secret scanning on.
The general checklist is in what to do in the first 10 minutes after you leak an API key.
Frequently asked questions
Can I rotate Anthropic API keys automatically?
Not fully. Anthropic doesn't offer an API that creates usable API keys; they're created in the Claude Console. Everything else can be automated: distributing the new key, verifying it, and deactivating the old one with the Admin API.
What's the difference between an Admin API key and a regular Claude API key?
A regular key (sk-ant-api03-…) calls Claude. An Admin API key (sk-ant-admin…) manages the organization, including listing and deactivating API keys, and can only be created by organization admins. It can't be used to call Claude.
Does deactivating a key delete it?
No. Setting a key's status to inactive stops it working but keeps it, so the same update call can switch it back. Delete it in the Console once you're sure nothing needs it.
What happens if I push my Claude API key to a public GitHub repo?
GitHub's secret scanning notifies Anthropic, Anthropic deactivates the key and emails you. Create a replacement, update your apps, and check your usage for anything you don't recognise.
Should I use a workspace key or a service account key?
A service account key. Anthropic describes workspace keys as legacy keys without an owner; personal and service account keys stop working automatically when their account is removed from the organization.