What you will be able to do
- Explain why an API key in browser or client code is exposed, and route requests through a backend that holds the key
- Choose between workspace-scoped keys, personal or service account keys, and Admin API keys for a given job
- Isolate teams and environments with separate workspaces and keys, each with its own limits
- Store keys in environment variables and secret managers, and keep them out of repositories
- Respond to a leaked key in the right order, and rotate and monitor keys on a schedule
Key concept
Key scope — Each Claude API key should sit where only its intended user can reach it: on a server, in one workspace, for one environment. If the key leaks, the damage stays inside that boundary and you can revoke the key without touching anything else.
1.Why the key belongs on a server, never in the client
A Claude API key works like a credit card number for your Console account. Anyone who holds it can call the API, and you pay for those calls. Handling a key well means it never reaches a place where someone outside its intended scope could read it. The first such place is the client. A key in a browser bundle, a mobile app or a desktop binary is a key you have given to every user.
Hiding the key in the client does not fix the problem, because the browser has to rebuild the real key before it can send a request. Encoding the key, splitting it into fragments, or fetching it after login only changes how a user finds it. The TypeScript SDK reflects this in its dangerouslyAllowBrowser option: turning it on places your secret credentials in client-side code, and browsers are less secure than server environments. Making the leaked key cheap does not fix it either. A low-limit key in its own workspace, rotated on a schedule, limits the damage, but every visitor can still copy it and use it until it runs out.
The fix is a server-side proxy. The browser sends the chat message to your own backend. The backend checks who the signed-in user is, adds the key from server configuration, and calls the Messages API. Your users never hold a credential. If someone else needs to call the Claude API directly, they should get their own key rather than borrow yours. The same idea applies to agents. In agent deployments, a proxy outside the agent's container injects the credentials, so the agent never sees the key. The proxy can also log every request for auditing. Wider sandboxing and network isolation are covered in least-privilege deployment.
Checkpoint 1 of 9· Check yourself
A mobile app team wants to ship a Claude API key inside the app. To make it 'safe', they plan to put the key in its own workspace with a low spend limit and rotate it every 90 days. What is the right assessment?
A low limit, its own workspace and rotation only limit the damage. Every user still holds a working key and can make calls billed to you. The fix is a server-side proxy that keeps the key in server config and makes the API call for the user.
“Much like a credit card number, if someone obtains and uses your API key, they incur charges on your behalf.”Source: support.claude.com
Checkpoint 2 of 9· Exam question
A startup ships a React single-page app that calls the Messages API directly from the browser so the team can skip building a backend. Security review flags that the key is visible in the network tab. What change fixes the exposure while keeping the chat feature?
Correct answer: C — Send chat requests to a backend endpoint that checks the signed-in user and calls the API with a key kept in server config, so the browser holds no key.
- A. Incorrect: splitting and encoding the key only hides it in the source. The assembled key is still sent in the request headers of every call, so it stays visible in the network tab.
- B. Incorrect: a spend limit and rotation reduce the damage from a leaked key, but the key is still embedded in the app and sent from the browser, so anyone can still read and copy it from the network tab.
- C. Correct: the key stays in server-side config and the browser talks only to the team's own endpoint. That endpoint can authenticate the user and validate each request before it calls the Messages API, so no key reaches the client.
- D. Incorrect: delivering the key to the browser after sign-in still puts it in a network response and in the page's memory. Any signed-in user or injected script can read it, and the requests that use it still expose it in the network tab.
2.Workspace-scoped keys versus Admin API keys
Workspaces are the boundary inside a Claude Console organization. You use them to separate projects, environments or teams while billing and administration stay central. A key scoped to a single workspace can only reach resources in that workspace. Keys stay in the workspace where they were created and cannot be moved to another. Every request except organization-level ones runs in exactly one workspace. Which workspace depends on the key: a legacy workspace key always runs in its own workspace, and a key that isn't scoped to a workspace runs in whichever workspace each request names in its anthropic-workspace-id header.
Admin API keys do a different job. An Admin API key authenticates calls that manage and report on the organization: members, workspaces, invites, key status, usage and cost. In the Claude Console, an Admin key starts with sk-ant-admin01-. Only members with the admin role can create one, and its full secret is shown only once. You choose no scopes when you create it, because every Console Admin key has full access to the endpoints that accept it. That much power is why an Admin key should never sit in a workload that only needs to send messages. Leaking it would expose management of the whole organization, not one team's traffic.
| Key type | Acts as / scope | Stops working when |
|---|---|---|
| Workspace key (legacy, no owner) | Its workspace; principal is null | Keeps working when members are removed |
| Personal key | The user (user_actor); single workspace or organization scope | Its user is removed from the organization |
| Service account key | The service account (service_account_actor) | Its service account is archived; survives removal of the user who created it |
Admin API key (sk-ant-admin...) | Organization-level Admin API calls | Provisioned only by members with the admin role |
To isolate two teams, give each team its own workspace and issue that team's keys inside it. Under the workspace's Limits tab, an admin sets spend and rate limits for each model tier, so one team cannot use up the other's budget. A leaked key can only reach its own workspace. Organization limits still apply alongside workspace limits, because Anthropic checks every applicable limiter on every request. Putting both teams' keys in the Default Workspace and splitting usage afterwards by key or request metadata does not isolate anything. Both teams still share one workspace's resources and limits.
The service stops working, because a personal key dies when its user is removed from the organization. A service account key survives the departure of the person who created it. It stops only if the service account itself is archived. That makes it the better choice for a long-lived production workload.
Checkpoint 3 of 9· Check yourself
Two product teams share one Claude Console organization. Each team's Messages API traffic must have its own budget, and a leaked key from one team must not reach the other team's resources. Which setup does this?
Workspaces are the isolation boundary. A key scoped to one workspace can reach only that workspace's resources, and each workspace can have its own spend and rate limits. Admin keys are for organization management, the Default Workspace option leaves both teams sharing one set of limits, and existing keys cannot be moved from one workspace to another.
“Use workspaces to separate different projects, environments, or teams while maintaining centralized billing and administration.”Source: platform.claude.com
Checkpoint 4 of 9· Exam question
A company has a support-bot team and a research team that share one Anthropic organization. Finance wants each team's spend and rate limits isolated, and a leak in one team's key must not affect the other. Which setup fits?
Correct answer: D — Create a workspace for each team in the Console and issue its keys there, with finance setting spend and rate limits on each workspace.
- A. Incorrect: separate keys in the default workspace still draw on the same spend and rate limits, so a leaked key can exhaust the other team's capacity. The user_id metadata only helps reporting and enforces no per-team limits.
- B. Incorrect: admin keys are for managing organization resources and cannot be used to call the Messages API, so the teams could not run inference with them. Usage reporting does not change that.
- C. Incorrect: personal keys all sit in the default workspace and share its spend and rate limits. Monthly rotation and grouping usage by key give finance reporting, not separate per-team limits, and a leak still affects the shared pool.
- D. Correct: workspaces partition keys, usage and limits within an organization. Each team gets its own spend and rate limits, and a leaked key exposes only that team's workspace.
3.Separate keys per environment, stored outside the code
Use a different key for development, testing and production. Separate keys let you see usage for each environment. They also mean a leaked dev key can be disabled without taking production down. Workspaces carry the same separation one level up. An organization can have a workspace for each environment, each with its own keys and limits.
Keep the key out of source and configuration files and load it from the environment. On a laptop, that can mean a .env file read by python-dotenv into ANTHROPIC_API_KEY, as long as .env is listed in .gitignore. In a cloud deployment, use the provider's secret manager to inject the key as an environment variable. Prefer encrypted secret storage there over dotenv files. When you hand a key to a third-party platform such as a CI/CD service or a web IDE, add it as an encrypted secret. Remember that the platform's developer can then reach your Console account.
As the number of keys grows, a key management system (KMS) keeps them in one place. A KMS gives you fine-grained control over who can view or use each key, an audit trail of every access and change, and rotation built in. The audit trail answers the first question after a suspected leak: who could have read this key?
Checkpoint 5 of 9· Match them up
Match each situation to the place this lesson recommends for keeping the Claude API key.
Tap a term, then the definition that fits it.
A dotenv file is acceptable on a laptop only if it is git-ignored. In the cloud, encrypted secret storage is preferred over dotenv files. Third-party platforms should get the key as an encrypted secret. A KMS adds the access control and audit trail needed to find out who could have read a key.
“In cloud environments, prefer encypted secret storage instead of dotenv files.”Source: support.claude.com
Sources2
4.Rotation, secret scanning and responding to a leak
Rotation limits how long a stolen key stays useful. Rotate on a fixed schedule, for example every 90 days: create a new key, move workloads to it, then deactivate the old one. Scheduled rotation protects you from leaks you never noticed. Once you know about a leak, waiting for the next rotation date leaves the key open to anyone who copied it.
Secret scanning catches leaks before they spread. Enable it in your source control provider, run a scanner such as Gitleaks over your repositories, and add scanning to CI/CD so a secret is caught before it is pushed to the main branch. Anthropic is also in GitHub's secret scanning partner program. If GitHub finds a Claude API key in a public repository, Anthropic automatically deactivates that key and emails the owner. A live service using a key that was pushed to a public repository can therefore fail without warning, which is another reason to replace the key quickly.
When a key may be compromised, revoke it first. On the API keys page in the Console, open the menu next to the key and choose Delete API key. Then create a new key, save it in a secrets manager rather than in version control, and deploy it to the service. Only after that should you clean up the commit and review usage for the time the key was exposed. Rewriting Git history does not take the key back from anyone who already copied it, and a spend limit only caps how much damage a stolen key can do. In a workspace's API Keys tab you can either disable or delete a key, and deleting is permanent.
Checkpoint 6 of 9· Put it in order
Someone on your team pushed the production Claude API key to a public GitHub repository an hour ago. Put the incident response steps in the order this lesson recommends.
- 1.Scrub the key from the commit history and review usage for the period the key was exposed
- 2.Deploy the new key to the production service through the secret store
- 3.Revoke the exposed key: on the Console API keys page, open the menu next to it and choose Delete API key
- 4.Save the new key in a secrets manager rather than in version control
- 5.Create a replacement key with Create key on the same page
Revoking comes first because anyone who copied the key can keep using it until it is deleted. Rewriting history or waiting for the next scheduled rotation does not take it back. Only after the replacement is stored and deployed do you clean up the commit and review usage.
“If you suspect that your API key may be compromised, we recommend revoking the key immediately.”Source: support.claude.com
Checkpoint 7 of 9· Exam question
An engineer discovers that a production Anthropic API key was committed to a public GitHub repository 20 minutes ago. The key is used by one live service. What should the team do first?
Correct answer: A — Revoke the exposed key in the Console and create a new one, deploy it to the service through its secret store, then scrub the commit and review usage logs.
- A. Correct: a key that sat in a public repository is compromised the moment it was pushed, and only revoking it stops others from using it. Issuing a new key and deploying it through the secret store restores the service, and the commit cleanup and log review follow.
- B. Incorrect: rewriting history and force-pushing does not invalidate the credential. The key was public for 20 minutes, long enough for scrapers, clones, forks or cached views to capture it, and it stays valid for whoever copied it. Only revoking it closes the exposure.
- C. Incorrect: the leaked key remains usable by anyone who saw it for up to 90 days if the team waits for the scheduled rotation. A pre-commit hook only prevents future leaks and does nothing about the key already exposed.
- D. Incorrect: a spend limit caps cost but does not stop others from using the key. Misuse up to the cap still costs money and can exhaust the limit, which would cause the live service's own requests to be rejected. The key itself has to be revoked.
5.Monitoring key usage and auditing keys
Monitoring catches the leaks that scanning missed. Check the Console's Logs and Usage pages regularly for each key's activity. Unexpected volume, unfamiliar models or traffic at odd hours are the first signs that a key is in someone else's hands. Spending controls serve as a backstop. Organizations on custom rate limits set spend limits on the Billing page and workspace rate limits on the Rate limits page. Standard organizations set auto-reload with a carefully chosen ceiling, which keeps service running while still capping unexpected usage.
For key audits at scale, use the Admin API. It lists keys with their status, expires_at (null for keys without an expiration), the principal each key acts as, and its scope. It can rename a key and set a key to inactive, but it cannot create keys. New keys are created in the Console. Listing the active keys in each workspace and comparing their expiry dates against your rotation policy is a routine audit.
client = anthropic.Anthropic()
api_keys = client.organization.api_keys.list(
limit=10, status="active", workspace_id="wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
)
# Automatically fetches more pages as needed, so `limit` sets the page size, not the total.
for api_key in api_keys:
print(f"{api_key.id}: {api_key.name} ({api_key.status})")This script needs an Admin API key or an org:admin token. Run it from an administration context, not from a workload that serves user traffic. Organization-level credentials should stay as tightly held as the keys they audit.
Checkpoint 8 of 9· Fill the gap
A security engineer is writing a routine audit that pulls every active key in one workspace so their expiry dates can be compared against the 90-day rotation policy. Which Admin API method completes the sample?
client = anthropic.Anthropic()
api_keys = client.organization.api_keys. ? (
limit=10, status="active", workspace_id="wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
)
# Automatically fetches more pages as needed, so `limit` sets the page size, not the total.
for api_key in api_keys:
print(f"{api_key.id}: {api_key.name} ({api_key.status})")An audit reads existing keys, so it uses list, filtered by status and workspace_id. The Admin API can read, rename and deactivate keys with update, but it cannot create them. New keys are created in the Console.
Source: platform.claude.comCheckpoint 9 of 9· Check yourself
Your organization is on standard rate limits, and secret scanning is already running in CI. Leadership wants a way to spot a key being misused and a cap on surprise spend if a leak gets past scanning. What should you set up?
Standard organizations cap unexpected usage with an auto-reload ceiling. Spend limits on the Billing page and workspace rate limits are for custom-rate-limit organizations. Reviewing Logs and Usage catches leaks that scanning missed. GitHub only scans public repositories, and Admin credentials must stay out of workloads that serve user traffic.
“For standard rate limit API orgs: Turn on and configure auto-reload on the Billing page”Source: support.claude.com
Sources
(9)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Web browsers are inherently less secure than server environments.”
↩︎ Why the key belongs on a server, never in the client“Any user with access to the browser can potentially inspect, extract, and misuse these credentials.”
↩︎ Exam trap 1“Any user with access to the browser can potentially inspect, extract, and misuse these credentials.”
↩︎ Prediction - 2.https://support.claude.com/en/articles/9767949-api-key-best-practices-keep-your-keys-safe-and-secureOfficial docs
“If someone needs access to the Claude API, they should obtain their own key.”
↩︎ Why the key belongs on a server, never in the client“If possible, use different API keys for development, testing, and production environments.”
↩︎ Separate keys per environment, stored outside the code“In cloud environments, prefer encypted secret storage instead of dotenv files.”
↩︎ Separate keys per environment, stored outside the code“Never include it directly in your code or configuration files.”
↩︎ Separate keys per environment, stored outside the code“Regularly rotate your API keys on a consistent schedule (for example, every 90 days) by creating new ones and deactivating old ones.”
↩︎ Rotation, secret scanning and responding to a leak“To prevent potential abuse, Anthropic automatically deactivates the exposed API key.”
↩︎ Rotation, secret scanning and responding to a leak“These limits act as a safeguard against unexpected usage due to leaked keys or errant scripts.”
↩︎ Monitoring key usage and auditing keys“If your API Key is compromised, this allows you to quickly disable just that use case and limit any potential damage.”
↩︎ Key concept“For standard rate limit API orgs: Turn on and configure auto-reload on the Billing page”
↩︎ Checkpoint - 3.
“The agent never sees the actual credentials”
↩︎ Why the key belongs on a server, never in the client - 4.
“API keys can be scoped to a single workspace. In this case, they can only access resources within that workspace.”
↩︎ Workspace-scoped keys versus Admin API keys“A workspace key (a legacy key without an owner) belongs to the workspace it was created in and always runs there.”
↩︎ Workspace-scoped keys versus Admin API keys“Use workspaces to separate different projects, environments, or teams while maintaining centralized billing and administration.”
↩︎ Checkpoint - 5.
“The full secret is shown only once.”
↩︎ Workspace-scoped keys versus Admin API keys“An Admin API key authenticates calls to the APIs that manage and report on your organization”
↩︎ Exam trap 2 - 6.https://support.claude.com/en/articles/9796807-creating-and-managing-workspaces-in-the-claude-consoleOfficial docs
“API keys are tied to the Workspace they're created in and cannot be moved between Workspaces.”
↩︎ Workspace-scoped keys versus Admin API keys“Deleting an API key is a permanent action and cannot be undone.”
↩︎ Rotation, secret scanning and responding to a leak - 7.
“Personal keys stop working when their user is removed from the organization.”
↩︎ Workspace-scoped keys versus Admin API keys“The Admin API can only read, rename, and change the status of existing keys.”
↩︎ Monitoring key usage and auditing keys“Service account keys stop working if their service account is archived, but continue to work even if the user that created them is removed.”
↩︎ Exam trap 4 - 8.https://support.claude.com/en/articles/8384961-what-should-i-do-if-i-suspect-my-api-key-has-been-compromisedOfficial docs
“make sure to save this key somewhere secure, such as a secrets management system and avoid keeping the key in version control.”
↩︎ Rotation, secret scanning and responding to a leak“If you suspect that your API key may be compromised, we recommend revoking the key immediately.”
↩︎ Exam trap 3“If you suspect that your API key may be compromised, we recommend revoking the key immediately.”
↩︎ Checkpoint
Also cited
- https://support.claude.com/en/articles/9767949-api-key-best-practices-keeping-your-keys-safe-and-secureOfficial docs
“Much like a credit card number, if someone obtains and uses your API key, they incur charges on your behalf.”
↩︎ Checkpoint“In cloud environments, prefer encypted secret storage instead of dotenv files.”
↩︎ Checkpoint