Authenticate to LLM providers
Diagrid signs in to your LLM provider as the workload that makes the call. Every app and agent has an ID, and Diagrid proves that identity to the provider with a short-lived signed token. The provider returns its own short-lived access token, and Diagrid uses it for the model call.
This is workload identity federation, and it is the default way to connect a provider:
- Nothing to store or rotate. There is no API key in Diagrid, in your code or in your environment.
- Access is per workload. The provider grants access to one ID, so you can see and revoke each workload's access on its own.
- Tokens expire in minutes. A leaked token is useless soon after.
If your provider or plan doesn't support federation, use an API key.
How it works
Federation applies when Diagrid makes the provider call for you: through a conversation component, which is what Dapr Agents and the Conversation API use. When your own code calls the provider with its SDK, including through the LLM proxy, the SDK still needs the provider key.
Before you start
You need:
- A Diagrid project with the app or agent that calls the model. See Connect to Diagrid.
- The Diagrid CLI, logged in.
- Permission to manage workload identity or IAM settings in your provider account.
1. Get the values to register
The provider checks three values in the token Diagrid presents.
| Value | What it is | Where to get it |
|---|---|---|
| Issuer | The OIDC issuer of your region | See below |
| Subject | The SPIFFE ID of the app or agent | See below |
| Audience | A fixed value per provider | Given in each provider's steps |
Issuer. On Diagrid Cloud the issuer is:
https://oidc.r1.diagrid.io
In a BYOC or Enterprise Server region, read the issuer from the region:
diagrid region get <region> --output json | jq -r '.status.endpoints.oidc'
Subject. Read the SPIFFE ID of the app that uses the component:
diagrid app get <app> --project <project> --output json \
| jq -r '.status.appIds[0].status.regionIdentities[].spiffeId'
The value has the form spiffe://<region-trust-domain>/ns/<project-namespace>/<app-id>. For an agent, use diagrid agent get. A project in several regions prints one SPIFFE ID per region, each with its own issuer, so register each pair.
Register one rule for each app, with its full SPIFFE ID as the subject. Don't use a prefix or wildcard that covers the project: such a rule gives every app in the project access to the provider account, including apps you add later.
2. Register Diagrid with the provider and create the component
Pick your provider. Each tab sets up trust on the provider side, then creates the Diagrid component. --scopes limits the component to the app you registered.
- Anthropic
- OpenAI
- Azure OpenAI
- Amazon Bedrock
- Google Cloud
In the Claude Console, open Workload identity, select Connect workload and choose Custom OIDC. See Anthropic's guide for the screens.
- Set the issuer URL to the issuer from step 1.
- Create a federation rule with the subject set to the app's SPIFFE ID and the audience set to
https://api.anthropic.com. Map it to a service account. - Copy the federation rule ID, the service account ID and your organization ID.
diagrid component create llm-provider \
--type conversation.anthropic \
--project <project> \
--metadata federationRuleId=fdrl_01abc \
--metadata organizationId=00000000-0000-0000-0000-000000000000 \
--metadata serviceAccountId=svac_01abc \
--metadata model=claude-sonnet-4-6 \
--scopes <app>
Add --metadata workspaceId=<id> when the federation rule is enabled for more than one workspace. All fields are in the Anthropic component reference.
In the OpenAI organization settings, under Security, create a Workload Identity Provider. See OpenAI's guide.
- Set the OIDC issuer URL to the issuer from step 1 and the audience to
https://api.openai.com/v1. - Map the
subclaim, with the app's SPIFFE ID as its value, to a service account. - Copy the identity provider ID and the service account ID.
diagrid component create llm-provider \
--type conversation.openai \
--project <project> \
--metadata identityProviderId=idp_01abc \
--metadata serviceAccountId=svc_acct_01abc \
--metadata model=gpt-4o \
--scopes <app>
All fields are in the OpenAI component reference.
Azure OpenAI uses Microsoft Entra ID. You add a federated credential to an app registration, and Entra ID accepts the workload's token in place of a client secret.
- Create an app registration, or reuse the one for your project.
- Add a federated credential with the issuer from step 1, the app's SPIFFE ID as the subject and
api://AzureADTokenExchangeas the audience. - Grant the app registration the Cognitive Services OpenAI User role on the Azure OpenAI resource.
The Azure CLI commands for steps 1 and 2 are in Diagrid identity, which also covers the region setting that a self-managed region needs for this audience.
diagrid component create llm-provider \
--type conversation.openai \
--project <project> \
--metadata apiType=azure \
--metadata endpoint=https://<resource>.openai.azure.com/ \
--metadata apiVersion=2025-01-01-preview \
--metadata azureTenantId=<tenant-id> \
--metadata azureClientId=<application-client-id> \
--metadata azureAuthMethods=spiffe \
--metadata model=<deployment-name> \
--scopes <app>
Amazon Bedrock uses an IAM role that the workload assumes with its token.
-
In IAM, create an OpenID Connect identity provider with the issuer from step 1 as the provider URL and
sts.amazonaws.comas the audience. -
Create a role with this trust policy.
<issuer-host>is the issuer withouthttps://.{"Version": "2012-10-17","Statement": [{"Effect": "Allow","Principal": { "Federated": "arn:aws:iam::<account-id>:oidc-provider/<issuer-host>" },"Action": "sts:AssumeRoleWithWebIdentity","Condition": {"StringEquals": {"<issuer-host>:aud": "sts.amazonaws.com","<issuer-host>:sub": "<app SPIFFE ID>"}}}]} -
Grant the role permission to invoke the Bedrock models you use.
diagrid component create llm-provider \
--type conversation.aws.bedrock \
--project <project> \
--metadata region=us-east-1 \
--metadata assumeRoleArn=arn:aws:iam::<account-id>:role/<role-name> \
--metadata webIdentityAudience=sts.amazonaws.com \
--metadata model=<model-id> \
--scopes <app>
All fields are in the Amazon Bedrock component reference.
Google Cloud uses a workload identity pool. This works with endpoints that accept Google Cloud access tokens, such as the Vertex AI OpenAI-compatible endpoint. See Google's guide.
- Create a workload identity pool and an OIDC provider in it, with the issuer from step 1 as the issuer URI. Leave the allowed audiences empty, so the provider's resource name is the expected audience.
- Map
google.subjecttoassertion.sub. - Grant Vertex AI access to the principal
principal://iam.googleapis.com/projects/<project-number>/locations/global/workloadIdentityPools/<pool>/subject/<app SPIFFE ID>, directly or through a service account it can impersonate.
diagrid component create llm-provider \
--type conversation.googleai \
--project <project> \
--metadata workloadIdentityProvider=//iam.googleapis.com/projects/<project-number>/locations/global/workloadIdentityPools/<pool>/providers/<provider> \
--metadata endpoint=https://us-central1-aiplatform.googleapis.com/v1/projects/<gcp-project>/locations/us-central1/endpoints/openapi \
--metadata model=google/gemini-2.5-flash \
--scopes <app>
Add --metadata serviceAccountEmail=<email> to impersonate a service account. All fields are in the Google AI component reference.
The Anthropic steps were run end to end on Diagrid Cloud. The other providers follow each component's reference and the provider's own federation guide.
3. Check that it works
Send one prompt through the component with the app's endpoint and API token. diagrid dev run sets both; see Connect to Diagrid for other ways to get them.
curl -s "$DAPR_HTTP_ENDPOINT/v1.0-alpha2/conversation/llm-provider/converse" \
-H "dapr-api-token: $DAPR_API_TOKEN" \
-H "content-type: application/json" \
-d '{"inputs":[{"messages":[{"ofUser":{"content":[{"text":"Say hello"}]}}]}]}'
A completion in the response means the provider accepted the workload's identity. A Dapr Agents app uses the component by its name, so an agent that referenced llm-provider with an API key needs no code change.
Use an API key instead
Use a key when the provider has no federation support, for example DeepSeek, Mistral or Hugging Face. This example is for OpenAI:
diagrid component create llm-provider \
--type conversation.openai \
--project <project> \
--metadata key=<api-key> \
--metadata model=gpt-4o \
--scopes <app>
Diagrid stores the key as a secret, not in the component. You are responsible for rotating it. For another provider, use its component type and model from the components reference.
When you switch a component to workload identity, remove key before you check that it works. An Azure OpenAI component keeps using the key for as long as it is set. The other components ignore the key once the workload identity fields are set, so a leftover key is only a stored secret you no longer need.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| The provider rejects the issuer, or can't fetch its keys | The registered issuer differs from the token's iss claim | Register the exact issuer from step 1, with no trailing slash. |
| The provider reports that no rule matches the subject | The subject differs from the app's SPIFFE ID, or the calling app is not the one you registered | Compare the rule with the output of diagrid app get. Add a rule for each app and each region. |
| The provider rejects the audience | The audience in the rule differs from the one the component sends | Use the audience shown in the provider's steps, or set the component's audience field to match your rule. |
| The component fails to load | A required workload identity field is missing | Set every required field listed in the component's reference. |