Trigger functions
Trigger tasks from your backend:
Trigger tasks from inside another task:
Triggering from your backend
When triggering from your backend, set theTRIGGER_SECRET_KEY environment variable. You can find it on the API keys page in the dashboard.
If you are using Next.js Server Actions, take care with bundling.
tasks.trigger()
Triggers a single run without needing to import the task. Use a type-only import to get full type-checking:
Your backend
Your backend
tasks.batchTrigger()
Triggers multiple runs of a single task at once:
Your backend
Your backend
batch.trigger()
Triggers multiple different tasks at once:
Your backend
Triggering from inside another task
Use these functions when inside a task run. They allow waiting for results and avoid importing task code into your backend bundle.yourTask.trigger()
Triggers a single run and returns a handle:
/trigger/my-task.ts
If you need to call
trigger() in a loop, use batchTrigger() instead — it is more efficient and
can trigger up to 1,000 runs in a single call.yourTask.batchTrigger()
Triggers multiple runs of the same task:
/trigger/my-task.ts
yourTask.triggerAndWait()
Triggers a task and pauses the current run until the child task completes:
/trigger/parent.ts
.unwrap() to throw automatically if the child task fails:
/trigger/parent.ts
yourTask.batchTriggerAndWait()
Triggers multiple runs in parallel and waits for all of them to finish:
/trigger/parent.ts
batch.triggerAndWait()
Triggers multiple different tasks and waits for all results:
/trigger/parent.ts
batch.triggerByTask()
Like batch.trigger() but accepts task instances directly for better type inference:
/trigger/parent.ts
batch.triggerByTaskAndWait()
Like batch.triggerByTask() but waits for all runs to complete:
/trigger/parent.ts
Triggering from your frontend
If you want to trigger a task from a frontend application, use our React hooks.Options
All trigger functions accept an options object as the last argument.delay
Trigger now but run later:
ttl
Automatically expire a run if it has not started within the given time:
Dev runs automatically get a 10-minute TTL. On Trigger.dev Cloud, staging and production runs
receive a maximum TTL of 14 days.
idempotencyKey
Ensures a task is only triggered once with the same key — useful inside tasks that may be retried:
debounce
Consolidate multiple trigger calls into a single delayed run:
mode: "trailing" to execute with the last payload instead:
maxDelay to guarantee execution even with continuous triggers:
queue
Override the task’s default queue when triggering:
concurrencyKey
Create a separate queue for each value of the key — useful for per-user concurrency:
maxAttempts
Override the task’s retry limit for this specific run:
machine
Override the machine preset for this run:
region
Override the execution region for this run:
Streaming batch triggering
This feature requires SDK 4.3.1+.
AsyncIterable or ReadableStream to any batch trigger function to generate items lazily without loading them all into memory:
/trigger/my-task.ts
Handling batch trigger errors
When a batch trigger fails, the SDK throws aBatchTriggerError:
/trigger/parent-task.ts
Large payloads
Payloads must be under 10MB. Payloads over 512KB are automatically stored in object storage and downloaded when the task runs. Task outputs are limited to 100MB. For payloads above 10MB, upload to your own storage and pass a URL:/yourServer.ts