Skip to content

Anthropic

Anthropic’s Workload Identity Federation (WIF) allows workloads and AI agents to authenticate to the Claude API using short-lived OpenID Connect (OIDC) tokens instead of static API keys (sk-ant-...).

Every Cofide Connect trust zone writes an OIDC discovery document (/.well-known/openid-configuration) and JSON Web Key Set (JWKS) to Connect’s configured trust bundle storage, and sets the corresponding iss claim on JWT-SVIDs issued within the zone. Because Connect writes these documents and manages trust zone key rotation, you do not need to deploy or operate a standalone SPIRE OIDC Discovery Provider.

At runtime, cofide-sdk (the Cofide Python SDK) fetches a fresh JWT-SVID for the https://api.anthropic.com audience and exchanges it at https://api.anthropic.com/v1/oauth/token using the RFC 7523 jwt-bearer grant. Anthropic verifies the signature against the trust zone’s JWKS, evaluates the matching federation rule, and returns a short-lived access token (sk-ant-oat01-...) bound to an Anthropic service account. Before that access token expires, the SDK fetches a new JWT-SVID and repeats the exchange automatically.

sequenceDiagram
    participant A as Agent workload
    participant W as SPIFFE Workload API
    participant C as Anthropic
    participant B as Trust Bundle Store

    A->>W: Fetch JWT-SVID (aud = https://api.anthropic.com)
    W-->>A: JWT-SVID (iss = trust zone JWT issuer, sub = SPIFFE ID)
    A->>C: POST /v1/oauth/token (jwt-bearer assertion)
    C->>B: Fetch OIDC discovery and JWKS
    B-->>C: Public signing keys
    C-->>A: Short-lived access_token (sk-ant-oat01-...)
    A->>C: POST /v1/messages (Authorization: Bearer access_token)

Retrieve the JWT issuer URL for your trust zone using cofidectl:

Terminal window
cofidectl trust-zone get --name <trust-zone-name> -o json | jq -r '.trust_zone.jwt_issuer'

The same value appears in the JWT Issuer column when running cofidectl trust-zone get --name <trust-zone-name> without JSON formatting.

If your trust bundle storage is exposed publicly, you can verify that the OIDC discovery endpoint is reachable and returns valid metadata:

Terminal window
curl -s <jwt-issuer-url>/.well-known/openid-configuration | jq

The JWT issuer URL (for example, https://oidc-discovery.example.cofide.dev) is independent of the SPIFFE trust domain (spiffe://example.org). The issuer URL populates the iss claim in JWT-SVIDs and identifies where Anthropic fetches the public signing keys in discovery mode, whereas the trust domain forms the root of the workload’s SPIFFE ID in the sub claim.

In the Claude Console (Settings > Workload identity), WIF connects three resources: a federation issuer, a service account, and a federation rule. You can create them together through the Connect workload > Custom OIDC wizard or configure each resource individually as described below.

Open Settings > Workload identity > Issuers and click Create issuer:

  • Name: Enter a descriptive name (for example, cofide-prod).
  • Issuer URL: Enter the exact jwt_issuer URL retrieved above, including https:// and without a trailing slash.
  • JWKS source: Select OIDC Discovery when your trust bundle store is exposed over publicly trusted HTTPS, leaving the optional discovery base URL and CA certificate fields empty unless your endpoint uses a separate discovery URL or private CA. If your trust bundle store is not reachable from the public internet, select Inline JWKS instead and update the registered keys whenever SPIRE rotates JWT signing keys (see Anthropic’s JWKS source modes).
  • Enforce single-use tokens: Leave enabled. cofide-sdk requests a fresh JWT-SVID for each exchange, so every assertion carries a unique jti claim.

Copy the generated issuer ID (fdis_...).

Open Settings > Service accounts and click Create service account:

  • Enter a descriptive name (for example, customer-agent).
  • Add the service account to the workspace or workspaces it needs to access so usage, quotas, and audit logs are attributed to it.

Copy the generated service account ID (svac_...).

Open Settings > Workload identity > Federation rules and click Create rule:

  • Name: Enter a descriptive name (for example, cofide-customer-agent).
  • Issuer: Select the federation issuer created in step 1 (fdis_...).
  • Subject pattern (subject_prefix): Enter the workload’s SPIFFE ID (for example, spiffe://example.org/cluster/prod/ns/agents/sa/customer-agent). An exact SPIFFE ID without a trailing * restricts the rule to that single workload, while a trailing * (such as spiffe://example.org/cluster/prod/ns/agents/*) matches any workload under that path prefix. Use an exact SPIFFE ID unless every workload under the prefix should act as the same Anthropic service account.
  • Expected audience (audience): Set to https://api.anthropic.com. Always configure an explicit audience on the rule so Anthropic rejects JWT-SVIDs requested for other relying parties.
  • Target service account: Select the service account created in step 2 (svac_...).
  • Workspace: Select the workspace to scope minted tokens to.
  • OAuth scope: Choose workspace:inference when the workload only calls inference endpoints (/v1/messages and /v1/models), or workspace:developer if it also uses Files, Skills, or Managed Agents endpoints.
  • Token lifetime: Set the validity in seconds for the issued Anthropic access token (default 3600).

Record the following four identifiers for workload configuration:

  • Federation rule ID (fdrl_...)
  • Organization ID (the UUID shown under Settings > Organization)
  • Service account ID (svac_...)
  • Workspace ID (wrkspc_..., required when a rule applies to multiple or all workspaces)

Each Cofide Connect trust zone has its own signing keys and jwt_issuer URL. If your agents run across multiple trust zones, register each trust zone as a separate federation issuer in Anthropic and bind each federation rule to the corresponding issuer.

Authenticate a Python workload or agent with cofide-sdk

Section titled “Authenticate a Python workload or agent with cofide-sdk”

Install cofide-sdk with the anthropic extra to use Anthropic’s official Python SDK directly:

Terminal window
pip install "cofide-sdk[anthropic]"

For LangChain agents, install the langchain-anthropic extra (and langchain[mcp] when connecting to MCP tool servers):

Terminal window
pip install "cofide-sdk[langchain-anthropic]" "langchain[mcp]"

WorkloadIdentityManager() reads its configuration from environment variables using WorkloadIdentityConfig.from_env(), or accepts an explicit WorkloadIdentityConfig instance.

Variable Required Description
ANTHROPIC_WIF_FEDERATION_RULE_ID Yes Federation rule ID (fdrl_...).
ANTHROPIC_WIF_ORGANIZATION_ID Yes Anthropic organization UUID.
ANTHROPIC_WIF_SERVICE_ACCOUNT_ID Yes Target service account ID (svac_...).
ANTHROPIC_WIF_WORKSPACE_ID Conditional Target workspace ID (wrkspc_...), required when the federation rule spans multiple or all workspaces.
ANTHROPIC_WIF_AUDIENCE No JWT-SVID audience requested for the exchange (defaults to https://api.anthropic.com).
SPIFFE_ENDPOINT_SOCKET No SPIFFE Workload API socket URI (defaults to unix:///tmp/spire-agent/public/api.sock, and is set automatically by spiffe-enable).
COFIDE_SPIFFE_ID No Selects which SPIFFE ID to present when the Workload API issues more than one identity to the workload.
COFIDE_IDENTITY_TOKEN_SOURCE No Source for the workload’s ID tokens: spiffe (default), aws_sts, or static.
COFIDE_TOKEN_ENDPOINT No Credex OAuth token endpoint (for example, https://credex.example.com/token), required for MCP access token exchange and for OIDC-to-SPIFFE exchange when COFIDE_IDENTITY_TOKEN_SOURCE is not spiffe.

cofide-sdk reads ANTHROPIC_WIF_* variables (matching its AWS_WIF_* convention) and performs the /v1/oauth/token exchange itself, avoiding collision with the upstream Anthropic SDK’s own file-based ANTHROPIC_FEDERATION_RULE_ID and ANTHROPIC_IDENTITY_TOKEN_FILE credential resolution. All three required ANTHROPIC_WIF_* variables must be set together. When migrating away from static API keys, unset ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN in the workload environment.

Pass anthropic_token_provider(workload_identity_manager) as the credentials argument to anthropic.AsyncAnthropic:

import asyncio
import anthropic
from cofide_sdk import WorkloadIdentityManager
from cofide_sdk.integrations.federated_identity import anthropic_token_provider
async def main() -> None:
async with WorkloadIdentityManager() as workload_identity_manager:
client = anthropic.AsyncAnthropic(
credentials=anthropic_token_provider(workload_identity_manager),
)
message = await client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude"}],
)
print(message.content[0].text)
asyncio.run(main())

anthropic_token_provider is an asynchronous credentials provider and must be used with anthropic.AsyncAnthropic. Each time the Anthropic client needs to initialize or renew its bearer token, the provider fetches a fresh JWT-SVID and exchanges it at /v1/oauth/token.

cofide-sdk provides chat_anthropic and mcp_connection under cofide_sdk.integrations.langchain so an agent can authenticate both its model calls to Anthropic (via WIF) and its tool calls to MCP servers (via Credex token exchange). When COFIDE_TOKEN_ENDPOINT is configured, mcp_connection can also perform delegation on behalf of an end user using on_behalf_of:

import asyncio
from cofide_sdk import WorkloadIdentityManager
from cofide_sdk.integrations.langchain import chat_anthropic, mcp_connection
from langchain.agents import create_agent
from langchain.mcp import MCPAdapter
from langchain_core.messages import HumanMessage
async def answer_question(question: str, user_access_token: str) -> str:
async with WorkloadIdentityManager() as workload_identity_manager:
llm = chat_anthropic(
workload_identity_manager,
"claude-sonnet-5-5",
max_tokens=1024,
)
connections = {
"ledger": mcp_connection(
workload_identity_manager,
"https://ledger.example.com/mcp",
scope=["ledger.read"],
on_behalf_of=user_access_token,
),
}
async with MCPAdapter({"mcpServers": connections}) as adapter:
tools = await adapter.list_tools()
agent = create_agent(
llm,
tools,
system_prompt="Answer the user's question using the available tools.",
)
result = await agent.ainvoke(
{"messages": [HumanMessage(content=question)]}
)
return result["messages"][-1].text

Two constraints apply when using chat_anthropic and mcp_connection in production services:

  • Async calls only: chat_anthropic supports only async LangChain calls (ainvoke, astream). Calling synchronous .invoke() raises RuntimeError rather than falling back to an ambient API key.
  • Per-request delegation: In a multi-user service, share a single WorkloadIdentityManager and chat_anthropic model instance across the process lifetime, and build mcp_connection(..., on_behalf_of=...) per request or session so user tokens are never shared across callers.

When running on Kubernetes with spiffe-enable, add the spiffe.cofide.io/inject: "csi" annotation to inject the SPIFFE Workload API socket and SPIFFE_ENDPOINT_SOCKET automatically. Supply the Anthropic WIF identifiers as environment variables without mounting any API key secret:

apiVersion: apps/v1
kind: Deployment
metadata:
name: customer-agent
namespace: agents
spec:
replicas: 1
selector:
matchLabels:
app: customer-agent
template:
metadata:
labels:
app: customer-agent
annotations:
spiffe.cofide.io/inject: "csi"
spec:
serviceAccountName: customer-agent
containers:
- name: agent
image: my-registry.example.com/customer-agent:v1
env:
- name: ANTHROPIC_WIF_FEDERATION_RULE_ID
value: "fdrl_..."
- name: ANTHROPIC_WIF_ORGANIZATION_ID
value: "00000000-0000-0000-0000-000000000000"
- name: ANTHROPIC_WIF_SERVICE_ACCOUNT_ID
value: "svac_..."
- name: ANTHROPIC_WIF_WORKSPACE_ID
value: "wrkspc_..."

Workloads running in serverless or managed agent environments without a local SPIRE agent, such as AWS Bedrock AgentCore or AWS Lambda, can authenticate to Anthropic with the same application code by obtaining a JWT-SVID through Credex.

Set COFIDE_IDENTITY_TOKEN_SOURCE=aws_sts and COFIDE_TOKEN_ENDPOINT=https://credex.example.com/token alongside the ANTHROPIC_WIF_* variables, and configure an OIDC-to-SPIFFE exchange policy in Connect. On each renewal, WorkloadIdentityManager exchanges the workload’s AWS STS web identity token at Credex for a Cofide JWT-SVID and presents that JWT-SVID to Anthropic.

sequenceDiagram
    participant A as Agent workload
    participant P as Platform IdP (e.g. AWS STS)
    participant X as Credex
    participant C as Anthropic
    participant B as Trust Bundle Store

    A->>P: Obtain platform identity token
    P-->>A: Platform OIDC / STS token
    A->>X: POST /token (OIDC-to-SPIFFE, aud = https://api.anthropic.com)
    X-->>A: JWT-SVID (iss = trust zone JWT issuer, sub = SPIFFE ID)
    A->>C: POST /v1/oauth/token (jwt-bearer assertion)
    C->>B: Fetch OIDC discovery and JWKS
    B-->>C: Public signing keys
    C-->>A: Short-lived access_token (sk-ant-oat01-...)
    A->>C: POST /v1/messages (Authorization: Bearer access_token)

For applications written in languages other than Python, spiffe-helper can fetch JWT-SVIDs (jwt_audience = "https://api.anthropic.com") and write them to a memory-backed volume for Anthropic’s official SDKs to read via ANTHROPIC_IDENTITY_TOKEN_FILE. See Anthropic’s Use WIF with SPIFFE guide for language-specific examples.

Anthropic’s POST /v1/oauth/token endpoint returns an opaque 401 authentication_error (Authentication failed) whenever an assertion fails validation. To see the specific deny reason for a failed exchange, open the Authentication history tab under Settings > Workload identity in the Claude Console.

Symptom or result code Cause Resolution
jwt_issuer_mismatch The JWT-SVID iss claim does not match the registered Issuer URL byte for byte. Compare the trust zone’s jwt_issuer against the issuer URL in Anthropic, including https:// and any trailing slash.
match_subject_prefix or jwt_audience_mismatch The JWT-SVID sub or aud claim does not satisfy the federation rule. Confirm the SPIFFE ID matches subject_prefix (case-sensitive) and aud contains https://api.anthropic.com (or ANTHROPIC_WIF_AUDIENCE).
jwt_lifetime_too_long The incoming JWT-SVID lifetime (exp - iat) exceeds the federation issuer’s maximum accepted assertion lifetime. Increase the maximum token lifetime on the Anthropic federation issuer or lower the JWT-SVID TTL.
workspace_id_required The federation rule spans multiple or all workspaces and no workspace ID was sent. Set ANTHROPIC_WIF_WORKSPACE_ID to the target wrkspc_... ID.
HTTP 403 from /v1/* after exchange The minted token’s oauth_scope does not grant access to that Claude API endpoint. Update the federation rule’s oauth_scope (for example, from workspace:inference to workspace:developer).
WorkloadAPIError The workload cannot reach the SPIFFE Workload API socket or has not been attested. Verify SPIFFE_ENDPOINT_SOCKET is mounted and the workload matches a Connect attestation policy.

To inspect the claims inside the JWT-SVID your workload presents, fetch and decode a token from inside the attested workload container:

Terminal window
python3 -c '
import asyncio, base64, json
from cofide_sdk import WorkloadIdentityManager
async def inspect():
async with WorkloadIdentityManager() as mgr:
tok = (await mgr.spiffe_id_token("https://api.anthropic.com")).token
payload = tok.split(".")[1]
print(json.dumps(json.loads(base64.urlsafe_b64decode(payload + "==")), indent=2))
asyncio.run(inspect())
'

Confirm that iss equals the registered federation issuer URL, sub matches the federation rule’s subject_prefix, aud contains https://api.anthropic.com, and exp is in the future.