What you will be able to do
- Choose between API keys, Workload Identity Federation and App Attest for a given workload
- Tell which identity personal, service account and legacy workspace keys act as, and when each stops working
- Trace how Workload Identity Federation validates a workload's JWT and sets the scope and lifetime of the token it mints
- Use vaults to give agents end-user credentials without exposing the secret values
1.Three ways to authenticate to the Claude API
Every Claude API request has to prove who is calling. The API accepts three kinds of credential. They differ in how long the credential lives and in where the proof of identity comes from, not in what the caller can reach.
| Method | Credential | Best for |
|---|---|---|
| API key | Static sk-ant-api... secret sent as a bearer token | Local development, prototyping, scripts, and servers where you control secret storage |
| Workload Identity Federation | Short-lived bearer token exchanged from your identity provider's identity token | Production workloads on cloud platforms, CI/CD pipelines, and Kubernetes, where you want to eliminate static secrets |
| App Attest | Short-lived access token issued to a genuine, attested installation of your registered app | iOS and macOS apps that call the Claude API directly with no back end or proxy |
The guidance is to start with API keys: a personal key for your own development, a service account key for anything shared. Move to Workload Identity Federation once your workload already has a platform-issued identity to federate.
Sources1
2.Whose identity an API key acts as
When you create a key, you choose its type. The type decides which identity the key acts as and what ends its life. Personal keys and service account keys are identity-backed: every request acts as a user or service account that your organization manages. Remove that identity and the key stops working, so a key cannot outlive the person or workload it belongs to.
| Key type | Acts as | Stops working when |
|---|---|---|
| Personal key | You, the user, with your roles and permissions | You lose access to the organization or, for a single-workspace key, to that workspace |
| Service account key | A service account | The service account is archived or, for a single-workspace key, is removed from that workspace |
| Workspace key (legacy) | No one: it belongs to the workspace it was created in | It expires, is disabled or deleted, or its workspace is archived |
A shared personal key acts as one person and breaks the day they leave. CI and production services should therefore get a service account created by an organization admin. Scope matters as well. A key created for one workspace works only there. A key without a workspace scope must send anthropic-workspace-id on every request. If the header is missing, the API returns a 400 invalid_request_error. If the key's identity cannot access the named workspace, the API returns a 404, exactly as it would for a workspace that does not exist. The Admin API accepts personal or service account keys only when they are not scoped to a workspace.
client = Anthropic() # reads ANTHROPIC_API_KEY
# Required on every request for a multi-workspace key.
# Omit extra_headers for a single-workspace key.
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude"}],
extra_headers={"anthropic-workspace-id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"},
)A platform team configures a federation rule with `subject_prefix` set to `system:serviceaccount:prod:worker` and no `claims` or `condition` matchers. A JWT arrives from the cluster with `sub` equal to `system:serviceaccount:staging:worker-2`. Will this JWT be accepted by the rule, and why?
Correct answer: A — No, because the subject does not start with `system:serviceaccount:prod:worker`; the `staging` namespace fails the prefix match even though the trailing segment is similar.
- A. Correct. subject_prefix performs a literal prefix match on the sub claim; `system:serviceaccount:staging:worker-2` does not start with `system:serviceaccount:prod:worker`, so the match fails and the token exchange is denied.
- B. Incorrect. subject_prefix is a literal string prefix check, not a set-membership or reordering check across segments.
- C. Incorrect. There is no automatic fallback to audience matching; unset matchers simply are not evaluated, and the configured subject_prefix still applies and fails.
- D. Incorrect. A rule is valid with just one of subject_prefix, claims, or condition set; at least one, not at least two, is required.
Sources1
3.Workload Identity Federation: validating a workload's identity
Workload Identity Federation (WIF) replaces the stored static secret with a proof of identity the workload already holds: a signed JWT from your own identity provider. On most platforms that JWT is ambient, for example a Kubernetes projected service-account token or the GitHub Actions OIDC endpoint. Before any workload can federate, an admin, owner or primary owner configures three resources in the Claude Console.
| Resource | ID prefix | What it asserts |
|---|---|---|
| Service account | svac_ | A named, non-human identity in your organization, with no email, password or Console login |
| Federation issuer | fdis_ | JWTs signed by this OIDC provider may assert workload identity for the organization; the JWKS source is discovery, explicit_url or inline |
| Federation rule | fdrl_ | When a JWT from this issuer has matching claims, mint a token for this service account with this scope |
At runtime, the SDK posts the JWT to POST /v1/oauth/token using the RFC 7523 jwt-bearer grant. Anthropic checks the signature against the issuer's JWKS, then checks the claims against the rule's matchers: subject_prefix, an exact audience, exact claim values, or a CEL condition. Every matcher you configure has to pass. If they all do, Anthropic returns a short-lived sk-ant-oat01-... token that acts as the rule's service account, and the SDK re-runs the exchange before that token expires. The client names the rule to use by ID, and Anthropic never searches for another rule that might match.
from anthropic import Anthropic, WorkloadIdentityCredentials, IdentityTokenFile
client = Anthropic(
credentials=WorkloadIdentityCredentials(
identity_token_provider=IdentityTokenFile(
"/var/run/secrets/anthropic.com/token"
),
federation_rule_id="fdrl_...",
organization_id="00000000-0000-0000-0000-000000000000",
service_account_id="svac_...",
workspace_id="wrkspc_...",
),
)For production, Anthropic recommends the zero-argument Anthropic() form instead. Ship one container image everywhere and inject ANTHROPIC_FEDERATION_RULE_ID, ANTHROPIC_ORGANIZATION_ID, ANTHROPIC_SERVICE_ACCOUNT_ID, ANTHROPIC_WORKSPACE_ID and ANTHROPIC_IDENTITY_TOKEN_FILE separately for each environment.
Sources2
4.Approving access and verifying its level
A matched JWT is only the first check. Two more limit what the minted token can do. The first is workspace. At exchange time, the rule's workspace must be one the service account is a member of, and the token then follows that workspace's rate limits and usage attribution. Every service account belongs implicitly to the default workspace. Any other workspace needs an explicit membership. The second is the rule's authorization. Because one issuer can carry many rules, you can have a separate rule per team, namespace or permission level, each with its own scope and lifetime.
| Setting | Values | Effect |
|---|---|---|
| OAuth scope | workspace:developer (default) | The same access as a workspace API key |
| OAuth scope | workspace:manage_tunnels | Locked scope for rules created by the MCP tunnels create-tunnel modal |
| token_lifetime_seconds | 60 to 86400; API default 3600; Console wizard prefills 600 | How long the minted token stays valid |
Claude Code self-hosted environments have a similar verification step. Each session gets an sk-ant-cc- token that your own services can verify. Check the signature against Anthropic's JWKS, the issuer, the aud claim against your ccpool_... environment ID, the session_worker role and the expiry. The token proves which session and environment Anthropic issued it for. It does not prove which process presents it, because any tool or MCP server in the session can read it. So scope any credentials you derive from it to a single session, not to everything the session's creator is allowed to do.
A workload's identity provider issues JWTs with a 5-minute lifetime. The federation rule the workload uses sets `token_lifetime_seconds` to 3600. What is the actual maximum lifetime of the Anthropic access token minted from this exchange?
Correct answer: A — 10 minutes, because the minted token's lifetime is capped at the lesser of the rule's configured value and twice the remaining lifetime of the presented IdP JWT.
- A. Correct. The token lifetime is the lesser of the rule's token_lifetime_seconds (3600s here) and twice the remaining IdP JWT lifetime (2 x 300s = 600s), so the 600-second (10-minute) bound applies.
- B. Incorrect. The rule's configured lifetime is only one of two bounds; the upstream JWT's remaining lifetime can constrain it further, as it does here.
- C. Incorrect. The token is allowed to outlive the JWT by up to double its remaining lifetime, not clamped to an exact match.
- D. Incorrect. 60 seconds is only the protocol's floor when the computed bound would otherwise fall below it; here the computed bound (600s) is well above that floor.
5.Vaults: end-user credentials for managed agents
Agents often act for your end users against third-party services. Vaults let you register those credentials once, one vault per end user, and reference them by ID when you create a session. MCP credentials (mcp_oauth, static_bearer) are keyed by mcp_server_url and injected when the agent connects to that server. environment_variable credentials are keyed by secret_name and sit in the sandbox as an opaque placeholder, which is replaced with the real value at egress. All secret fields are write-only and never returned by the API.
session = client.beta.sessions.create(
agent=agent.id,
environment_id=environment.id,
vault_ids=[vault.id],
title="Alice's Slack digest",
)Credentials are not validated when you store them. A bad one shows up only during a session, as an authentication or downstream error. Rotation is simple: update the secret value, and because credentials are re-resolved periodically, running sessions pick up the change without a restart. To monitor credential health, subscribe to webhooks such as vault_credential.refresh_failed, then call mcp_oauth_validate to decide what to do next.
| status | Meaning | Next step |
|---|---|---|
| valid | The token works | No action needed |
| invalid | The grant is gone or the OAuth server rejected the refresh with a 4xx | Prompt the end user to re-authorize |
| unknown | A transient error (5xx, 429, or network failure) | Wait and retry |
Archive it. Archiving cascades to every credential and purges the secrets, but keeps the records for auditing. Future sessions that reference the vault fail, while sessions already running continue. Deleting is a hard delete that keeps no record.
Sources4
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.Removing a departing engineer from the organization shuts off every API key they created.Why is that wrong?
That holds for identity-backed personal keys. A legacy workspace key belongs to its workspace, though, and keeps working after its creator leaves. That is why identity-backed keys or WIF are preferred.
Covered in Whose identity an API key acts as
2.Once static keys are replaced with Workload Identity Federation, credential security is fully handled.Why is that wrong?
WIF removes static secrets, but it relies on the identity provider that signs the JWT. Pair it with the IdP's own controls, such as workload identity binding, conditional access and audit logging.
Covered in Workload Identity Federation: validating a workload's identity
3.Deleting a vault or credential is the correct way to offboard a user when you need to keep an audit record.Why is that wrong?
Delete is a hard delete that keeps no record. Archive purges the secret payload but keeps the record for auditing.
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“API keys and Workload Identity Federation grant the same access to Claude API endpoints.”
↩︎ Three ways to authenticate to the Claude API“Move to Workload Identity Federation when your workload already has a platform-issued identity you can federate.”
↩︎ Three ways to authenticate to the Claude API“This means that keys won't accidentally outlive the people or workloads that own them.”
↩︎ Whose identity an API key acts as“The Admin API accepts a personal key or service account key only if the key isn't scoped to a specific workspace.”
↩︎ Whose identity an API key acts as“regardless of whether its creator leaves the organization”
↩︎ Exam trap 1 - 2.
“all configured matchers must pass for the JWT to be accepted”
↩︎ Workload Identity Federation: validating a workload's identity“There is no implicit rule search.”
↩︎ Workload Identity Federation: validating a workload's identity“You need the admin, owner, or primary owner role in your Anthropic organization”
↩︎ Workload Identity Federation: validating a workload's identity“Anthropic checks that the federation rule's workspace matches one of the service account's workspace memberships”
↩︎ Approving access and verifying its level“The default is workspace:developer, which grants the same access as a workspace API key.”
↩︎ Approving access and verifying its level“federated authentication is only as strong as the upstream identity provider that signs the JWT”
↩︎ Exam trap 2 - 3.
“Scope credentials you derive from the token to what a single coding session should be able to do”
↩︎ Approving access and verifying its level - 4.
“The agent never sees the secret value.”
↩︎ Vaults: end-user credentials for managed agents“credential rotation, archival, or deletion propagates to running sessions without a restart”
↩︎ Vaults: end-user credentials for managed agents“Secrets are purged; records are retained for auditing.”
↩︎ Vaults: end-user credentials for managed agents“Use archive if you need an audit trail.”
↩︎ Exam trap 3