| title | API keys |
|---|---|
| description | How to authenticate with Trigger.dev so you can trigger tasks. |
When you trigger a task from your backend code, you need to set the TRIGGER_SECRET_KEY environment variable.
Each environment has its own secret key. You can find the value on the API keys page in the Trigger.dev dashboard:
For preview branches, you need to also set the `TRIGGER_PREVIEW_BRANCH` environment variable as well. You can find the value on the API keys page when you're on the preview branch.To automatically configure the SDK with your secret key, you can set the TRIGGER_SECRET_KEY environment variable. The SDK will automatically use this value when calling API methods (like trigger).
TRIGGER_SECRET_KEY="tr_dev_…"
TRIGGER_PREVIEW_BRANCH="my-branch" # Only needed for preview branchesYou can do the same if you are self-hosting and need to change the default URL by using TRIGGER_API_URL.
TRIGGER_API_URL="https://trigger.example.com"
TRIGGER_PREVIEW_BRANCH="my-branch" # Only needed for preview branchesThe default URL is https://api.trigger.dev.
If you prefer to manually configure the SDK, you can call the configure method:
import { configure } from "@trigger.dev/sdk/v3";
import { myTask } from "./trigger/myTasks";
configure({
secretKey: "tr_dev_1234", // WARNING: Never actually hardcode your secret key like this
previewBranch: "my-branch", // Only needed for preview branches
baseURL: "https://mytrigger.example.com", // Optional
});
async function triggerTask() {
await myTask.trigger({ userId: "1234" }); // This will use the secret key and base URL you configured
}