Skip to content
API Reference
Add tools and services

Configure Anthropic

Set up credential brokering so workloads authenticate to Claude API with Keycard-issued tokens instead of static API keys

Configure Workload Identity Federation (WIF) between Keycard and Anthropic. Your applications get Keycard OIDC tokens that Anthropic exchanges for short-lived API credentials — no static API keys anywhere.

Before starting:

  1. Create the Anthropic resource

    In Keycard Console, navigate to Resources → Add Resource → Add Manually.

    Field Value
    Identifier https://api.anthropic.com
    Credential Provider Zone Provider
    Credential Lifetime 1h (under Advanced options)
  2. Create an application

    Navigate to Applications → Add Application.

    Field Value
    Name e.g. anthropic-workload
    Identifier e.g. anthropic-workload

    Note the Application Identifier. Keycard puts it in the sub and keycard_app_id claims of the tokens this Application requests for itself. It is not the ID in the browser URL.

  3. Link the resource

    Open the application → Dependencies → Add dependency → select https://api.anthropic.com.

  4. Create application credentials (local development only)

    Open the application → Application Credentials → Add credential → Client ID & Secret.

    Note the Client ID and Client Secret — the secret is shown once.

  5. Note your Issuer URL

    Copy your Issuer URL from Keycard Console under Settings → Connection. Anthropic needs this as the issuer URL.

  1. Create a service account

    In Anthropic Platform Console, go to Settings → Service accounts → Create service account.

    Field Value
    Name e.g. keycard-workload

    Note the service account ID (svac_...).

  2. Create a workspace

    The Default Workspace has no ID and can’t be used with WIF.

    Go to Settings → Workspaces → Create workspace.

    Field Value
    Name e.g. keycard-workloads

    Note the workspace ID (wrkspc_...) from the workspaces list.

  3. Link the service account to the workspace

    Select the workspace from the top navigation dropdown → Manage → Service accounts → Add service account → select the service account from step 1.

  4. Register Keycard as an issuer

    In Workload Identity Federation settings, on the Issuers tab → Create issuer.

    Field Value
    Name e.g. keycard-prod
    Issuer URL your Keycard Issuer URL, e.g. <keycard-issuer-url>
    JWKS source discovery
  5. Create a federation rule

    On the Rules tab → New Rule.

    Field Value
    Issuer Select your Keycard issuer
    Match → Subject prefix Your Keycard Application Identifier (the sub claim). Anthropic treats the value as an exact match unless it ends in *.
    Target Your service account
    Workspaces Select the workspace from step 2
    Scope workspace:developer
    Token lifetime 3600 seconds

    Note the rule ID (fdrl_...).

Get a Keycard OIDC token and pass it to the Anthropic SDK for automatic WIF exchange.

from keycardai.oauth import Client, BasicAuth
from anthropic import Anthropic, WorkloadIdentityCredentials
# 1. Get a Keycard OIDC token scoped to Anthropic.
with Client(
"<keycard-issuer-url>", # from Settings → Connection
auth=BasicAuth("<your-client-id>", "<your-client-secret>"),
) as kc:
token = kc.client_credentials_grant(
resource="https://api.anthropic.com",
)
# 2. Use it with the Anthropic SDK — WIF exchange happens automatically.
client = Anthropic(
credentials=WorkloadIdentityCredentials(
identity_token_provider=lambda: token.access_token,
federation_rule_id="<fdrl_...>",
organization_id="<anthropic-org-id>",
service_account_id="<svac_...>",
workspace_id="<wrkspc_...>",
),
)
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello from a Keycard workload"}],
)
print(message.content[0].text)

In Keycard Console — open Audit Log. Look for:

Event Description
credentials:issue OIDC token issued for https://api.anthropic.com

In Anthropic Platform Console — go to Settings → Workload identity → Authentication events. You should see the exchange with your zone’s issuer URL and matched federation rule.

Token exchange returns “service account not a member of workspace” The service account must be explicitly added to the workspace. Go to the workspace → Manage → Service accounts and add it.

“Invalid issuer” error The issuer URL in Anthropic must match the Keycard zone URL exactly, including the protocol (https://) and no trailing slash.

Federation rule doesn’t match Check that the Subject prefix in the rule matches your Keycard Application Identifier, not the ID in the browser URL. The sub claim in the Keycard-issued JWT contains the Identifier, and Anthropic treats the prefix as an exact, case-sensitive match unless it ends in *. A mismatch shows as match_subject_prefix in Anthropic’s authentication history.