Skip to main content
Use OpenRouter workload identity federation to exchange a Trigger.dev OIDC token for an OpenRouter access token. Your tasks call models with no OPENROUTER_API_KEY stored anywhere, and usage is billed to the API key the federation policy acts as, as if that key made the request.
Workload identity federation is available on OpenRouter’s Business and Enterprise plans, under Settings, Workload identity.
Follow the OIDC prerequisites, then go to the OIDC page for your environment and copy the issuer URL and subject.

Configure OpenRouter

An organization admin sets this up under Settings, Workload identity (set up trust):
  1. Add an issuer. Set Issuer URL to the issuer URL copied from the dashboard and leave JWKS URL empty: OpenRouter reads the keys from the issuer’s discovery document.
  2. Add a policy for that issuer:
    • Subject: the complete subject copied from the dashboard. It must match exactly.
    • Audience: any value, for example https://openrouter.ai. It’s required, and your task must request the same one.
    • Acts as API key: the workspace API key your tasks use today. A workspace key grants the inference scope.
Copy the policy’s id, shown under its name. Your task sends it with every exchange.

Call OpenRouter in your task

Exchange the OIDC token at OpenRouter’s token endpoint, then pass the access token as the API key to the OpenAI SDK pointed at OpenRouter’s base URL:
/trigger/openrouter-chat.ts
The access token never outlives the OIDC token it was exchanged for, which is five minutes for Trigger.dev tokens. For longer work, request a new OIDC token and exchange it again. A rejected exchange returns 400 with invalid_grant whichever claim failed, so compare the issuer, subject and audience with the policy when it does.

Remove the old credential

Once runs in every deployed environment authenticate this way, delete OPENROUTER_API_KEY from those environments on the Environment Variables page. The key itself stays: the policy acts as it. To stop anyone using it directly, create a new workspace key for the policy and delete the old one in OpenRouter. Local Development runs can’t mint OIDC tokens. Use your own OpenRouter API key there when ctx.environment.type === "DEVELOPMENT".