CertPrep
Domain 7 · Lesson 7.3 · 5 min read

Handling API Keys and Credentials

Exam skillAPI Key and Credential Handling

Handling Anthropic API keys and credentials correctly in development and production, including server-side proxying rather than client embedding, workspace-scoped keys versus admin keys, environment separation, rotation, and access monitoring, without exposing any key beyond its intended scope.

Keep every Anthropic API key inside its intended scope: call the API from a server-side proxy, never from clients; separate environments and projects into workspaces with their own keys and limits; reserve Admin API keys for administration; store keys in secret managers; rotate on a schedule and immediately after exposure; and monitor usage for misuse.

What you need to know

Where the key lives

PlaceVerdict
Browser JavaScript, mobile app bundle, local storageNever: anyone can extract it, encoded or split or not
Source code, config files in git, Docker imagesNever: history and copies keep it forever
System prompts or anything the model seesNever: context can leak
Environment variables injected at runtime from a secret managerYes
A server-side proxy that adds the key to requestsYes, and it is the pattern for clients and for agents that can run code

Scope keys with workspaces

  • One workspace per environment (development, staging, production) and, where useful, per team or product. A leaked development key does not touch production, and rotating one does not break another.
  • Set spend and rate limits per workspace, so a leaked key's damage is capped.
  • Developers experiment with keys in a development workspace, never the production key, never a teammate's key.

Admin keys are different

Admin API keys manage the organization: workspaces, members, API keys, usage reports. They are not for Messages API calls and must be held by very few people or services.

CI and workloads

Use workload identity federation to exchange the CI system's short-lived identity token for access, instead of storing a static key in pipeline settings.

Rotation and response

  • Rotate keys on a schedule, so rotation is routine rather than an emergency.
  • A key committed to a public repository is compromised even if deleted in the next commit: revoke or rotate immediately and review its usage.
  • Enable secret scanning in repositories.

Monitoring

Watch usage per key and workspace (for example, through the Usage and Cost API) for spikes or unexpected models and times. Log request IDs, never keys.

Customer-supplied keys

If customers bring their own keys: encrypt them at rest, use each only server-side for that customer's requests, never return or display them after saving, never log them, never use one customer's key for another.

In the exam

Items describe where a key is used or stored, or an incident, and ask for the correct handling. Pick server-side proxying, workspace separation with limits, secret managers, rotation, federation for CI and monitoring. Distractors encode or hide keys in clients, reuse production keys, use Admin keys for model calls, or treat a deleted commit as safe.

Check your understanding

Question 1

A React app plans to call Claude directly with the key in the bundle. Instead?

Show answer

Answer: A. Client code is visible; the backend keeps the key secret.

Question 2

What is an Admin API key for?

Show answer

Answer: B. It is for organization administration, not model calls.

Question 3

A key was committed to a public repo and removed in the next commit. What now?

Show answer

Answer: D. History keeps the key; treat it as compromised.

Apply it: Fix Bluestem's key handling

Exercise · about 20 minCase: Bluestem Lending

Bluestem uses one API key in development, staging, production and CI. A developer committed it to a public repository; rotating it broke production for an hour. Static keys in CI must end next quarter, and finance wants to know quickly if spending spikes.

  1. Respond to the leak.
  2. Redesign key scope across environments.
  3. Fix CI authentication.
  4. Set up monitoring and limits.
    Done when: a leak in one place cannot reach production or run up unlimited spend.
Check your work
Show model answer

1. Revoke the leaked key at once; issue new keys; review usage for the exposure window for unknown activity; enable secret scanning on all repositories.

2. Workspaces for development, staging and production, each with its own keys, rate limit and monthly spend limit; developers use development keys only; production keys live in the secret manager and are injected at runtime; rotation every 90 days per workspace, so rotating one never breaks another.

3. Workload identity federation from the CI provider to the staging workspace; no static key in pipeline settings.

4. A daily job reads usage per workspace through the Usage and Cost API and alerts on spend over 150% of the 7-day average or on unexpected models; Admin keys held by two platform engineers only.

Key termsWorkload identity federation

Sources