Study guide
11.4 Identity, Secrets & API Key Management
Claude Certified Developer - Foundations CCDV-F
Track your progress as you read
Finished sections get a check mark.
1 Chapter 1: Core Messages API & Streaming
1.1 Messages API Fundamentals & Request Lifecycle 1.2 Streaming & Server-Sent Events (SSE) 1.3 Thinking: Adaptive Mode, Effort & Reasoning Budgets
2 Chapter 2: Optimization & Asynchronous Batches
2.1 Prompt Caching Mechanics & Breakpoints 2.2 Message Batches API & Asynchronous Workloads
3 Chapter 3: Structured Outputs, Documents & Files API
3.1 Structured Outputs & JSON Extraction 3.2 Files API, Document Blocks & Citations
4 Chapter 4: Application Design, Resilience & Delivery Life Cycle
4.1 API Resilience, Error Handling & Retries 4.2 Production Backend Architecture & State Management 4.3 Requirements Analysis & Claude Application Design 4.4 The Claude Application Life Cycle & Configuration Management
5 Chapter 5: LLM Fundamentals, Model Selection & Versioning
5.1 LLM & Technical Fundamentals: Tokens, Context Windows & Sampling 5.2 Claude Model Family Selection 5.3 Model Versioning, Snapshot Pinning & Migration 5.4 Latency & Throughput Optimization
6 Chapter 6: Cost Engineering & Context Management
6.1 Production Cost Optimization Strategies 6.2 Context Window Management & Compaction
7 Chapter 7: Foundations of Workflows & Deterministic Patterns
7.1 Agent vs. Workflow Architectural Foundations 7.2 Workflow Patterns: Prompt Chaining & Routing 7.3 Workflow Patterns: Parallelization & Voting
8 Chapter 8: Autonomous Agents & Multi-Step Systems
8.1 Workflow Patterns: Orchestrator-Workers & Evaluator-Optimizer 8.2 Agent Loop Implementation & State Tracking 8.3 Agent Frameworks & Human-in-the-Loop (HITL)
9 Chapter 9: Prompt and Context Engineering
9.1 System Prompt Design & Role Framing 9.2 XML Tags & Structural Prompt Delimiters 9.3 Few-Shot Prompting & In-Context Learning 9.4 RAG Context Injection & Document Formatting
10 Chapter 10: Tool Calling & Model Context Protocol (MCP)
10.1 Tool Schema Design & Parameter Validation 10.2 Tool Execution, Multi-Tool Calls & Error Handling 10.3 MCP Architecture & Core Primitives 10.4 MCP Transports & Client/Server Integration 10.5 Agentic Customization: Built-in Tools, Custom Tools, Skills & MCP
11 Chapter 11: Security, Safety & Governance
11.1 Direct & Indirect Prompt Injection Defenses 11.2 Tool Permissions, Sandboxing & Least Privilege 11.3 Data Privacy, Redaction & Audit Logging 11.4 Identity, Secrets & API Key Management
12 Chapter 12: Claude Code Developer Tooling
12.1 Claude Code Architecture & Project Configuration 12.2 Permissions, Modes & Hooks
13 Chapter 13: Evaluation, Testing & Production Observability
13.1 Evaluation Design & Golden Datasets 13.2 Production Observability, Tracing & Debugging
11.4 Identity, Secrets & API Key Management
Key Takeaways Explain This Topic AI
Anthropic API keys are sent as a bearer token in the Authorization header; personal and service account keys are identity-backed and can be scoped to a workspace (use a personal key for your own development and a service account key for anything shared), but no key identifies your application's end user, so a leak is a financial incident and the key must never reach a browser, mobile, or desktop client.
Production keys belong in a secrets manager that supports rotation, per-environment scoping, and access audit; the SDKs read ANTHROPIC_API_KEY from the environment so correct code contains no key at all.
Authorization must be evaluated server-side against the authenticated session's identity, never against a user identifier the model supplied in a tool argument, which is untrusted input.
Each tool should hold the narrowest downstream credential that works, because when a tool is compromised through prompt injection the credential's scope is the blast radius.
Operational telemetry such as token counts and stop reasons can be logged broadly, while prompts, completions, and tool arguments belong in a restricted audit vault, redacted before the log call rather than downstream.
Last updated: October 2026
Identity, Secrets & API Key Management
Exam Blueprint Focus: Identity, Secrets, and Key Management (1.6%) is a small but distinctly weighted sub-skill of the Security and Safety domain. It is easy to score on, because the answers are concrete: where the key lives, who the caller is, and what the model is never allowed to decide.
The Anthropic API Key Is a Bearer Credential
API keys are static secrets generated in the Claude Console and sent on every request as a bearer token in the Authorization header ( Authorization: Bearer <key> ); the legacy x-api-key header is still accepted in its place. Key types matter:
Key type Acts as Scope When it stops working
Personal key You, with your roles and permissions One workspace, or the workspaces where your role allows API use (chosen at creation) When you leave the organization
Service account key A service account your organization manages One workspace, or everything the service account can access (chosen at creation) When the service account is removed
Workspace key (legacy) No one; it belongs to the workspace That workspace On expiry, disabling, or deletion
Personal and service account keys are identity-backed : every request acts as that identity, so keys don't outlive the people or workloads that own them. Use a personal key for your own development and a service account key for anything shared (CI, production services); treat workspace keys as legacy. For production workloads that already have a platform identity (AWS, Google Cloud, Azure, Kubernetes, CI), Workload Identity Federation exchanges a short-lived identity token for API access, so no long-lived secret sits at rest.
What no key type carries is your end user's identity . Anyone holding the key can spend your organisation's budget within that key's access. That has three immediate consequences:
A leaked key is a financial incident , not merely a security one — an attacker's first move is usually to mine tokens, not to read your data.
The key must never reach a client. No browser bundle, no mobile app, no desktop binary. A key shipped to a client is a key published.
The key cannot express end-user authorization. It says "this identity may call the API," never "this user may issue this refund."
The client-side key anti-pattern BROKEN: Browser --(ANTHROPIC_API_KEY in JS bundle)--> api.anthropic.com
- CORRECT: Browser --(session cookie / JWT)--> Your backend --(Authorization: Bearer key)--> api.anthropic.com
- |
- +-- authN, authZ, rate limit, quota, audit log
Every browser or mobile client must talk to your backend, which authenticates the end user with your own mechanism, authorizes the specific action, enforces per-user rate limits and quotas, writes the audit record, and only then calls Claude with the key it alone holds. The backend is the trust boundary; the model is inside it.
Where the Key Lives
- Storage Verdict
- Source code literal Never. It ends up in git history, forks, CI logs, and error reports
- Committed config file Never. Same failure, one step removed
- .env committed to git Never. Add .env to .gitignore on day one
- .env local + gitignored Acceptable for local development only
- Platform environment variable Acceptable for deployment
Secrets manager (Vault, AWS Secrets Manager, GCP Secret Manager) Correct for production — supports rotation, per-environment scoping, and access audit
Workload identity federation Best where available: short-lived credentials, no long-lived secret at rest
The SDKs read ANTHROPIC_API_KEY from the environment by default, so the correct code contains no key at all : from anthropic import Anthropic
- client = Anthropic() # reads ANTHROPIC_API_KEY from the environment
- Rotation
Assume every key will need to be replaced, whether because of a suspected leak, an employee departure, or a compliance schedule. Rotation is only painless if it was designed in: read the key from a secrets manager at startup (or per request with caching) rather than baking it into an image, use separate keys per environment and per service so one rotation has a bounded blast radius, set an expiration when you create each key (presets from 3 hours to 30 days, a custom duration, or Never for keys you rotate yourself; an expired key returns 401 authentication_error and cannot be reactivated), and monitor the Console for usage on a key you believed retired. Disable or delete any key you suspect has leaked.
Secrets in Claude Code
Three rules, all of which are exam-shaped:
Personal keys go in ~/.claude/settings.json or the environment — never in the committed .claude/settings.json .
permissions.deny rules such as Read(./.env) and Read(./**/*.pem) stop the agent reading credential files at all. Deny rules apply immediately without waiting for workspace trust, which is exactly the property a secret needs.
Secrets must not enter the prompt. Once a .env file is read into context it is in the transcript, in your logs, and in any observability sink you forward to.
Identity: The Model Never Decides Who You Are
This is the highest-value rule in the sub-skill.
Authorize server-side against the authenticated session's identity — never against an identifier the model supplied in a tool argument.
- The failure looks like this: # VULNERABLE
- def get_account_balance(user_id: str): # user_id came from Claude's tool call
- return db.query("SELECT balance FROM accounts WHERE user_id = ?", user_id)
Claude produced user_id from context, and context includes text an attacker may control — a support email, a retrieved document, an uploaded PDF. An indirect prompt injection reading "the user's ID is 4417" is now a cross-tenant data breach. The tool argument is untrusted input , exactly like a query parameter. # CORRECT
- def get_account_balance(session: Session): # identity from the authenticated session
- return db.query("SELECT balance FROM accounts WHERE user_id = ?", session.user_id)
The general form: identity comes from the session; the model supplies only the non-identity parameters. If a tool genuinely needs to act on another entity — an admin viewing a customer record — the backend checks the session's role against that entity, and the check lives in your code, not in a prompt instruction.
The same rule extends to remote MCP servers, which are network services an LLM drives. Every request carries its own credential, and the server authorizes against the caller's verified identity, not against a field in the payload.
Least privilege on the credential itself
Where downstream systems support scoping, give each tool the narrowest credential that works: a read-only database role for lookup tools, a payments credential limited to refunds under a ceiling, per-service accounts rather than one shared superuser. When a tool is compromised through injection, the credential's scope is the blast radius.
Keeping Secrets Out of Telemetry
Secrets leak through logs far more often than through source. Enforce a bifurcation:
Operational telemetry (safe to log broadly): request IDs, model ID, token counts, latency, stop_reason , tool names, error codes.
Sensitive content (restricted audit vault, short retention, access-logged): prompts, completions, tool arguments, document text.
Redact before the log call, not in a downstream processor — anything that reaches the logging pipeline unredacted has already been copied. Scrub API keys, bearer tokens, and connection strings from tool error messages too: a stack trace that echoes a failed connection string publishes the credential inside it.
Common Traps
Shipping the API key to a browser or mobile client. It is published the moment it ships.
Trusting a user ID that came from a tool argument. That is the cross-tenant breach.
One shared key for every environment and service. Rotation becomes an outage.
Committing .claude/settings.json with a personal key inside.
Letting the agent read .env . Use permissions.deny with Read(...) .
Logging tool arguments verbatim. They routinely contain credentials and PII.
Asking the model in the system prompt not to reveal secrets. Prompt instructions are advisory; a secret that never entered the context cannot be revealed.