Skip to main content

Overview

Creates a single environment variable for a specific project and environment. When called from inside a task, the projectRef and env arguments can be omitted and are inferred from the task’s runtime context. To create or update multiple variables in one request, use the upload (bulk import) endpoint instead.

Endpoint

POST https://api.trigger.dev/api/v1/projects/{projectRef}/envvars/{env}

Path parameters

projectRef
string
required
The project reference (e.g. proj_yubjwjsfkxnylobaqvqz).
env
string
required
The target environment: dev, staging, prod, or preview.

Request body

name
string
required
The name of the environment variable (e.g. SLACK_API_KEY).
value
string
required
The value to assign.

Response

success
boolean
true when the variable was created successfully.

Examples

import { envvars } from "@trigger.dev/sdk";

await envvars.create("proj_yubjwjsfkxnylobaqvqz", "prod", {
  name: "SLACK_API_KEY",
  value: "slack_123456",
});

Response example

{
  "success": true
}
OperationEndpoint
List variablesGET /api/v1/projects/{projectRef}/envvars/{env}
Retrieve variableGET /api/v1/projects/{projectRef}/envvars/{env}/{name}
Update variablePUT /api/v1/projects/{projectRef}/envvars/{env}/{name}
Delete variableDELETE /api/v1/projects/{projectRef}/envvars/{env}/{name}
Bulk importPOST /api/v1/projects/{projectRef}/envvars/{env}/import

Preview branches

To create a variable scoped to a specific preview branch, include the x-trigger-branch header or set previewBranch in the SDK configuration.
import { configure, envvars } from "@trigger.dev/sdk";

configure({
  secretKey: process.env["TRIGGER_ACCESS_TOKEN"],
  previewBranch: "feature-xyz",
});

await envvars.create("proj_yubjwjsfkxnylobaqvqz", "preview", {
  name: "FEATURE_FLAG",
  value: "true",
});

Build docs developers (and LLMs) love