CertSafari
    Anthropic Claude Certified Developer – Foundations (CCDV-F) - December 7 onwards· Lessons

    Domain 7 · Lesson 21/24

    Claude API key handling: proxying, workspaces, rotation and leaks

    API Key and Credential Handling

    16 min read
    2.67% of exam
    9 sources
    Published 18 Nov 2026
    Docs as of 18 Nov 2026

    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?

    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?

    Sources123

    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 types: what each acts as and what stops it working
    Key typeActs as / scopeStops working when
    Workspace key (legacy, no owner)Its workspace; principal is nullKeeps working when members are removed
    Personal keyThe user (user_actor); single workspace or organization scopeIts user is removed from the organization
    Service account keyThe 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 callsProvisioned 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.

    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?

    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?

    Sources4567

    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.

    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. 1.Scrub the key from the commit history and review usage for the period the key was exposed
    2. 2.Deploy the new key to the production service through the secret store
    3. 3.Revoke the exposed key: on the Console API keys page, open the menu next to it and choose Delete API key
    4. 4.Save the new key in a secrets manager rather than in version control
    5. 5.Create a replacement key with Create key on the same page

    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?

    Sources286

    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.

    Listing active API keys in one workspace with the Admin APIpython
    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})")

    Checkpoint 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?

    Sources27

    Sources

    (9)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 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. 2.
      “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. 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
    4. 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
    5. 6.
      “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
    6. 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
    7. 8.
      “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

    Ready to test yourself?

    Practise Anthropic Claude Certified Developer – Foundations (CCDV-F) - December 7 onwards in quiz mode.

    Spotted a mistake, or was something unclear? Tell us.