Skip to main content
Workload identity federation is in Private Preview. To turn it on for your organization, Contact us.
Workload identity federation lets a workload exchange the token its platform already issues, such as a GitHub Actions or Google Cloud token, for a Baseten access token that expires within 1 hour. Send the access token as a bearer token to inference endpoints and the Management API, so you don’t store a long-lived API key in CI or production.

How workload identity federation works

Tokens from an identity provider whose claims match a trust rule act as that rule’s service account. When a workload runs:
  1. The workload requests an OpenID Connect (OIDC) token from its platform.
  2. The workload sends that token and a trust rule ID to POST /v1/auth/token.
  3. Baseten checks the token’s signature, issuer, expiration, audience, and claims against the trust rule, then returns an access token for the rule’s service account.
  4. The workload calls Baseten with the access token until it expires, then exchanges a new platform token.
This page covers tokens coming into Baseten. To give Baseten workloads tokens for your cloud resources and Hugging Face repositories, see OpenID Connect (OIDC) authentication.

Prerequisites

  • The Organization Admin role to add an identity provider, and the Team Admin or Organization Admin role to create service accounts and trust rules. For more information, see Roles and permissions.
  • To set up through the Management API, an API key that belongs to a user with those roles. The workloads you set up don’t need an API key.

Add an identity provider

Add the platform your workload runs on as an identity provider. Baseten supports these providers: Use the Baseten provider to let a model running on Baseten call Baseten as a service account. The model sends its runtime OIDC token as the platform token, so set the trust rule’s audience to oidc.baseten.co. GitHub Actions, Google Cloud, and Baseten have one issuer, so add each of them once. For the other providers, add one identity provider for each account, tenant, or cluster issuer. To add an identity provider:
  1. Sign in to your workspace at app.baseten.co and open Organization settings, then choose the Workload identity tab.
  2. Choose Add identity provider.
  3. For Provider, select your platform.
  4. If the provider asks for an Issuer URL, enter your account’s, tenant’s, or cluster’s issuer.
  5. For Name, enter a name that’s unique in your organization, and optionally add a Description.
  6. Choose Add identity provider.
The provider appears in the list with its issuer URL.

Create a service account

A service account carries the permissions a workload gets. Give each workload its own service account with the smallest permission set it needs: To create a service account:
  1. Sign in to your workspace at app.baseten.co. For a team account, open the team’s settings page. For an API key management account, open Organization settings.
  2. Choose the Members tab, then under Service accounts, choose Create service account.
  3. For Name, enter a name that’s unique in your organization, such as models-ci, and optionally add a Description.
  4. For Permissions, select the permission the workload needs.
  5. Under Model access or Model API access, choose the models, environments, or Model APIs the account can use.
  6. Choose Create service account.
The account appears under Service accounts.

Create a trust rule

A trust rule names one identity provider and one service account. It accepts a token when the token’s aud matches the rule’s audience and the rule’s condition evaluates to true.

Write the condition

Write the condition as a Common Expression Language (CEL) expression over the token’s claims. It can use has, size, startsWith, endsWith, contains, and int. Baseten rejects a condition that doesn’t pin the token’s subject at least this narrowly, in a top-level && clause with ==, in, or startsWith: For example, this condition accepts tokens only from workflow runs on the main branch of acme/models. Find the owner’s numeric ID in any GitHub Actions token’s repository_owner_id claim, or run gh api users/acme --jq .id.
A prefix accepts every workload under it. For example, claims.sub.startsWith('repo:acme/') accepts runs from every repository that acme owns, including pull request runs. Pin the full subject, and require a branch or GitHub environment for service accounts that deploy or manage models.
To check a trust rule before you create it: Replace <identity_provider_id> with the provider’s ID. The check validates the condition and audience; it doesn’t test a token. Run the following command:
The response has "valid": true, or an error that explains what to change. To create a trust rule: Set the audience to the value your workload requests its platform token for. The examples on this page use https://api.baseten.co. For the Baseten provider, use oidc.baseten.co, the audience of a model’s runtime token. Set the maximum token lifetime between 60 and 3,600 seconds; choose the shortest that covers the work done with one token, such as one deploy job.
  1. Sign in to your workspace at app.baseten.co and open Organization settings, then choose the Workload identity tab and select the identity provider.
  2. Choose Create trust rule.
  3. For Name, enter a name that’s unique in your organization, and optionally add a Description.
  4. For Identity provider, select the provider. You can’t change it later.
  5. For Service account, select the account the tokens act as.
  6. For Condition, enter the CEL expression.
  7. For Audience, keep https://api.baseten.co or enter the audience your workload requests.
  8. For Max token lifetime, set the longest token the rule issues. The default is 1 hour.
  9. Choose Create trust rule.
Copy the rule’s ID. Your workload sends it during the exchange.

Exchange a token and call Baseten

Get a platform token

Request the platform token with the audience your trust rule expects:

Exchange the token

The exchange request authenticates with the platform token, so it doesn’t need an API key. To exchange a platform token for a Baseten access token: Replace <platform_token> with the platform token and <trust_rule_id> with the rule’s ID. In this request, audience is the trust rule’s ID, not the audience inside the platform token. access_token_lifetime_seconds is optional, can’t exceed the rule’s maximum, and defaults to it. Run the following command:
Response
To call a model with the access token: Replace <access_token> with the token from the response. Run the following command:
The access token has the service account’s permissions and works with the Management API and inference endpoints, including Model APIs. It can’t create sandbox tokens.

Deploy from GitHub Actions

This workflow deploys a model when you push to main, using the trust rule from the condition example. It stores the trust rule ID, which isn’t a secret, as a repository variable in place of an API key. To deploy a model from GitHub Actions:
  1. In your repository, add a variable named BASETEN_TRUST_RULE_ID with the trust rule’s ID. For more information, see GitHub’s variables documentation.
  2. Add the following workflow as .github/workflows/deploy.yml:
    .github/workflows/deploy.yml
  3. Push a commit to main. The run succeeds when the Push the model step finishes, because --wait fails the step if the deployment doesn’t become active.
id-token: write lets the job request a GitHub token; it grants no write access to the repository. The ::add-mask:: command keeps the access token out of the job log, and the Baseten CLI reads it from BASETEN_API_KEY. The Truss push GitHub Action doesn’t support workload identity federation. For other deploy options, see CI/CD.

Refresh tokens in long-running applications

A long-running application needs a new access token before the current one expires. This Python helper caches the access token and exchanges a fresh platform token when 80% of the token’s lifetime has passed.
baseten_token.py
Pass a function that returns a current platform token, and read the token file on every call, because the platform rotates it. For example, on Amazon EKS with a projected token mounted at /var/run/secrets/baseten/token, call a Model API through the OpenAI SDK:
Call client.with_options(api_key=token.get()) for each request so the client always sends a current token. The workload identity classes in the Anthropic and OpenAI SDKs exchange tokens with those providers, not with Baseten, so use this helper instead.

Stop creating API keys

After every workload authenticates with workload identity federation, stop new API keys from being created and revoke the keys your workloads used. Turning off key creation doesn’t affect existing keys; they keep working until they expire or you revoke them. To stop using API keys after you move to workload identity federation:
  1. Turn off API key creation for personal keys, team and API key management keys, or both.
  2. In the audit log, confirm that no workload has used a key since you moved to workload identity federation.
    Revoking a key immediately stops every workload that still sends it.
  3. Revoke keys across the organization that your workloads used.

Token lifetimes and limits

Access tokens use the same rate limits as API keys.

Troubleshoot token exchange

Every rejected exchange returns HTTP 400 with "error": "invalid_grant", whatever the cause, so the response doesn’t reveal which check failed. Check each condition in order:
  1. The request’s audience is the trust rule’s ID, not the platform token’s audience.
  2. The platform token’s iss matches the rule’s identity provider. For a provider with its own issuer, the issuer URL must match exactly, including any trailing slash.
  3. The platform token’s aud equals the rule’s audience.
  4. The token’s claims satisfy the condition. Decode the token on your own machine to compare its sub and other claims; don’t paste it into an online decoder.
  5. The platform token hasn’t expired and isn’t older than its platform’s limit.
  6. The rule’s service account is enabled. If it’s disabled, re-enable it, or update the service account with "disabled": false.
An invalid_request error means the request body is malformed, and unsupported_grant_type means grant_type isn’t the token exchange grant. To confirm the rule itself is valid, verify the trust rule.