Skip to main content

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​

A model call with workload identityChecks issuer, subject, audience1prompt + dapr-api-token2signed identity tokenshort-lived access token3prompt + access tokencompletioncompletionYour appor agentDiagridconversation componentProvidertoken exchangeProvidermodel APIYour appor agentDiagridconversation componentProvidertoken exchangeProvidermodel API
A model call with workload identityYour app holds only its Diagrid API token. Diagrid exchanges a signed identity token for the provider's access token, then calls the model.

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.

ValueWhat it isWhere to get it
IssuerThe OIDC issuer of your regionSee below
SubjectThe SPIFFE ID of the app or agentSee below
AudienceA fixed value per providerGiven 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.

In the Claude Console, open Workload identity, select Connect workload and choose Custom OIDC. See Anthropic's guide for the screens.

  1. Set the issuer URL to the issuer from step 1.
  2. 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.
  3. 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.

note

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​

SymptomCauseFix
The provider rejects the issuer, or can't fetch its keysThe registered issuer differs from the token's iss claimRegister the exact issuer from step 1, with no trailing slash.
The provider reports that no rule matches the subjectThe subject differs from the app's SPIFFE ID, or the calling app is not the one you registeredCompare the rule with the output of diagrid app get. Add a rule for each app and each region.
The provider rejects the audienceThe audience in the rule differs from the one the component sendsUse the audience shown in the provider's steps, or set the component's audience field to match your rule.
The component fails to loadA required workload identity field is missingSet every required field listed in the component's reference.