Skip to main content
Authenticate programmatic requests to Tensorlake with OpenID Connect (OIDC) workload tokens or project API keys, and use tl login for interactive CLI sessions. OIDC workload authentication exchanges short-lived identity tokens from GitHub Actions, Vercel, Kubernetes, or any HTTPS OIDC issuer for short-lived tl_wt_* Tensorlake tokens so you don’t store long-lived secrets in CI or cloud environments. API keys remain supported alongside OIDC for environments without an OIDC issuer.

Tensorlake account

You need a Tensorlake Cloud account to call the Python SDK, the @tensorlakeai/tensorlake npm package, the Rust SDK, the tl CLI, or the REST API. Create an account at Tensorlake Cloud.

Credential precedence

Tensorlake clients choose a credential by explicit configuration first, then environment variables, then saved CLI contexts. When multiple credentials exist in the same process, clients resolve them in this order:
  • Explicit API key: api_key / apiKey passed to a client constructor, --api-key, or TENSORLAKE_API_KEY
  • Explicit OIDC credentials: oidc_token / oidcToken, oidc_policy_id / oidcPolicyId, --oidc-token, --oidc-token-file, TENSORLAKE_OIDC_TOKEN, or TENSORLAKE_OIDC_TOKEN_FILE (in the tl CLI, --oidc-policy-id / TENSORLAKE_OIDC_POLICY_ID selects a trust policy without overriding a saved tl login context unless an OIDC token source is also present)
  • Ambient OIDC runtime: VERCEL_OIDC_TOKEN on Vercel, or ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN in GitHub Actions, paired with TENSORLAKE_PROJECT_ID or TENSORLAKE_OIDC_POLICY_ID
  • CLI login context: a 12-hour Personal Access Token (PAT) saved by tl login (tl CLI only; Python and TypeScript SDKs don’t read CLI login contexts)
If tl whoami shows a project you didn’t select with tl login, check your shell environment for TENSORLAKE_API_KEY or TENSORLAKE_OIDC_TOKEN.

OIDC workload authentication

OIDC workload authentication replaces static API keys in Continuous Integration (CI) pipelines and cloud backends with short-lived, project-scoped credentials. Your workload presents an external OIDC JSON Web Token (JWT) to Tensorlake, which verifies the signature against the issuer’s JSON Web Key Set (JWKS), checks your trust policy’s claim rules, and returns a short-lived tl_wt_* bearer token (60s to 3600s, default 900s).
Every exchanged OIDC workload token starts with tl_wt_* and is confined to a single project. Workload tokens work with Tensorlake’s Sandboxes API, sandbox proxy, and project-scoped platform routes, and cannot access organization-wide settings, billing, SSO configuration, or API key management.

How OIDC token exchange works

Each workload authenticates in two steps without storing static Tensorlake secrets:
1

Create a project trust policy

An organization or project admin registers a trust policy on a Tensorlake project in the Tensorlake Dashboard (under the project’s API Keys page → OIDC Trust Policies) or through the Platform API. The policy pins the external HTTPS issuer, expected audience (default https://api.tensorlake.ai), at least one subject or claims match rule, a project role (member or project:admin), and a token Time to Live (TTL).
2

Exchange the OIDC JWT for a workload token

At runtime, your workload or Tensorlake SDK posts the external OIDC JWT and your projectId (or policyId) to POST /platform/v1/auth/oidc/token. Tensorlake validates the JWT and returns a short-lived tl_wt_* bearer token.
3

Send authenticated requests

Pass the returned tl_wt_* token in Authorization: Bearer headers. The Rust SDK and the Python and TypeScript Sandbox and Cloud clients exchange and refresh tokens automatically when ambient OIDC environment variables are present, and the tl CLI exchanges a fresh tl_wt_* token automatically at startup for each invocation. For standalone clients that still take a static bearer token (such as UsageClient, RepositoryClient, or FilesystemClient), pass an exchanged tl_wt_* token from exchange_oidc_token / exchangeOidcToken or OidcTokenManager.

Create an OIDC trust policy

Only a human organization or project admin signed in directly to the Tensorlake console can create, edit, or delete trust policies. API keys, PATs, workload tokens, and support impersonation sessions are refused. Every policy must constrain subject, at least one entry in claims, or both. Tensorlake rejects bare * wildcards and unconstrained policies so a policy can never trust an entire public issuer.

Create a policy in the Tensorlake Dashboard

1

Open your project’s API Keys page

Go to the Tensorlake Dashboard, select the target project, and open API Keys from the sidebar.
2

Add an OIDC trust policy

Scroll to OIDC Trust Policies and select New OIDC Policy. Pick a provider preset (GitHub Actions, Vercel, Kubernetes, or Custom OIDC), enter your issuer, audience, and subject or claims rules, choose the project role (Member or Project admin), and set the workload token TTL (60s–3600s, default 900s).
3

Copy the policy ID and quickstart snippet

After creating the policy, copy the generated oidc_pol_* policy ID and quickstart snippet for your workload environment. You can edit, disable, revoke active tokens, or delete policies from the same table at any time.

Create a policy over the Platform REST API

You can also create and manage trust policies programmatically from an authenticated admin console session. For GitHub Actions, match immutable numeric repository IDs so repository renames or transfers cannot hijack access:
This request returns the new trust policy with an id prefixed by oidc_pol_. Pass that id as policyId when managing policies with GET, PATCH, and DELETE on /platform/v1/organizations/{organizationId}/projects/{projectId}/oidc-trust-policies/{policyId}, or when disambiguating token exchange. For Vercel-hosted apps, set issuer to your team’s issuer URL (https://oidc.vercel.com/your_team_slug), set audience to match your Vercel token’s aud claim (https://vercel.com/your_team_slug for automatic VERCEL_OIDC_TOKEN), and match owner_id, project_id, and environment:
Each key in claims must match the verified JWT payload (logical AND across keys). When a claim rule holds an array of strings, any element in that array satisfies the rule (logical OR within the key).

Exchange an OIDC token over REST

Post the external OIDC JWT with either projectId or policyId to POST /platform/v1/auth/oidc/token. Specify policyId if more than one trust policy on the project matches the same token:
The endpoint responds with the short-lived workload token and its resolved scope:
Use the returned token as an Authorization: Bearer credential on any project-scoped API or Sandbox request until expiresAt.

Use OIDC in GitHub Actions

Grant id-token: write to the workflow job and set TENSORLAKE_PROJECT_ID (or TENSORLAKE_OIDC_POLICY_ID). The tl CLI, Python SDK, TypeScript SDK, and Rust SDK automatically request an OIDC JWT for audience https://api.tensorlake.ai and exchange it for a tl_wt_* token:
When TENSORLAKE_API_KEY is unset, run_in_sandbox.py calls Sandbox.create() with no credential arguments and authenticates through GitHub Actions OIDC.

Use OIDC on Vercel

Enable Vercel OIDC Federation on your Vercel project and set TENSORLAKE_PROJECT_ID in your Vercel project environment variables. Make sure your Tensorlake OIDC trust policy’s audience matches the aud claim on Vercel’s VERCEL_OIDC_TOKEN (https://vercel.com/<team-slug> by default). On Vercel Functions and builds, @tensorlakeai/tensorlake and the Python SDK detect VERCEL_OIDC_TOKEN automatically when TENSORLAKE_API_KEY is unset:
You can also exchange an OIDC token explicitly or cache refreshed tokens across requests with exchangeOidcToken or OidcTokenManager:

Use OIDC in Python and Kubernetes

The Python SDK (Sandbox, AsyncSandbox, SandboxClient, AsyncSandboxClient, and CloudClient) reads TENSORLAKE_OIDC_TOKEN, TENSORLAKE_OIDC_TOKEN_FILE (for Kubernetes projected ServiceAccount tokens), VERCEL_OIDC_TOKEN, and GitHub Actions OIDC automatically when api_key is omitted, and refreshes tokens in the Rust core 60s before expiry. You can also exchange an external JWT explicitly with exchange_oidc_token:
For custom REST callers or clients that accept only a static api_key (such as UsageClient or RepositoryClient), use OidcTokenManager to cache exchanged tl_wt_* tokens and refresh them 60s before expiry. In Rust (tensorlake crate), pass OidcAuthConfig to ClientBuilder::oidc_auth(...) for automatic middleware-based refresh.

Revoke active workload tokens

Active tl_wt_* tokens remain valid until expiresAt unless you revoke the trust policy. In the Tensorlake Dashboard (API Keys → OIDC Trust Policies), use the row actions to revoke active tokens, disable the policy, edit its trust rules, or delete it. Over the REST API, update the policy with PATCH and set "revokeExistingTokens": true, change any trust rule (issuer, audience, subject, claims, or scope), set "enabled": false, or delete the policy with DELETE. Tensorlake increments policyVersion (or removes the policy), immediately drops cached decisions on the handling pod, and rejects previously minted tokens across all replicas within 5s (the forward-auth cache TTL).

API keys

API keys are project-specific credentials for programmatic access when an OIDC issuer isn’t available, such as plain servers, Docker containers, or local scripts. Each API key belongs to a single project and inherits the project member permissions for that project.
API keys cannot have organization-level permissions by default, and every Tensorlake API key starts with tl_apiKey_*.

Create an API key

Create a project API key in the dashboard:
1

Open your project

Go to the Tensorlake Dashboard and select the target project.
2

Generate a key

Open the project’s API keys settings and create a new key. Copy the value once; Tensorlake shows a key only at creation.
Create API key

SDK and CLI authentication

Tensorlake’s user-facing clients accept project credentials as follows:
  • Python, TypeScript, and Rust SDKs: pass a project API key via TENSORLAKE_API_KEY, or configure OIDC workload authentication with TENSORLAKE_PROJECT_ID (or TENSORLAKE_OIDC_POLICY_ID)
  • REST API calls: send an API key (tl_apiKey_*) or an exchanged workload token (tl_wt_*) in the Authorization: Bearer header
  • tl CLI: run tl login on your workstation for interactive 12-hour PAT contexts, use OIDC flags (--oidc-token, --oidc-token-file, --oidc-policy-id) or ambient CI OIDC in pipelines, or set TENSORLAKE_API_KEY
Pick the CLI credential by where the command runs:
  • Your own machine: run tl login to save a context per project and switch projects without logging in again (see Switch Between Projects in the CLI)
  • CI or cloud runtime with OIDC: set TENSORLAKE_PROJECT_ID (and TENSORLAKE_OIDC_TOKEN_FILE on Kubernetes) so tl exchanges a short-lived tl_wt_* token automatically
  • Container or server without OIDC: set TENSORLAKE_API_KEY to a project API key
Browser applications connecting directly to an authenticated sandbox port are a separate case. The sandbox proxy accepts the signed-in Tensorlake Cloud session cookie together with the organization and project selected by the browser application. See Browser session authentication.

Tensorlake Python SDK

Pass an API key through TENSORLAKE_API_KEY or directly to Sandbox.create, or omit api_key when OIDC environment variables are configured.
your_app.py
This snippet creates a sandbox authenticated with the API key in TENSORLAKE_API_KEY.

TypeScript SDK

Install @tensorlakeai/tensorlake for Node.js 22+ and authenticate with either OIDC or TENSORLAKE_API_KEY.
This command installs the TypeScript SDK and exports an API key for the shell session.
This example creates a connected sandbox using TENSORLAKE_API_KEY. See Sandboxes for lifecycle examples.

REST API

Include your API key (tl_apiKey_*) or exchanged OIDC workload token (tl_wt_*) in the Authorization: Bearer header on every REST request.
This request calls the Sandboxes API using a Bearer credential. For human browser sign-in with enterprise identity providers, see Single Sign-On (SSO).

Frequently asked questions

Use OIDC workload authentication whenever your workload runs in GitHub Actions, Vercel, Kubernetes, or another OIDC-capable runtime so no long-lived Tensorlake secret sits in environment variables. Keep API keys for environments that don’t issue OIDC tokens.
Match immutable numeric claims (repository_owner_id and repository_id) in the policy’s claims object alongside your subject or environment rule, rather than relying only on mutable repository names.
Each trust policy sets tokenTtlSeconds between 60s and 3600s (default 900s, or 15 minutes). The Rust ClientBuilder (which also backs Python and TypeScript Sandbox clients) and OidcTokenManager refresh tokens automatically 60s before expiry.
No. Both project API keys and tl_wt_* OIDC workload tokens are confined to the single project where the key or trust policy was created. Create a separate trust policy or API key for each project.
Immediately delete the compromised API key from the Tensorlake Dashboard and generate a new one. Update every application using the old key right away.
A 401 means the credential is invalid, expired, revoked, or missing from the Authorization: Bearer header. For OIDC, verify that your trust policy is enabled, its issuer, audience, and claims match the external JWT, and the exchanged tl_wt_* token hasn’t expired or been revoked by a policy update.
API keys and OIDC workload tokens are for programmatic machine-to-machine access to a single project, while browser sessions authenticate people in the console. Only direct console admin sessions can manage SSO providers, OIDC trust policies, or organization billing.