Skip to main content
There are currently four ways you can trigger any task from your own code: Additionally, scheduled tasks get automatically triggered on their schedule and webhooks when receiving a webhook.

From outside of a task

You can trigger any task from your backend code, using either trigger() or batchTrigger().
Do not trigger tasks directly from your frontend. If you do, you will leak your private Trigger.dev API key to the world.

trigger()

Triggers a single run of a task with the payload you pass in, and any options you specify. It does NOT wait for the result, you cannot do that from outside a task.

batchTrigger()

Triggers multiples runs of a task with the payloads you pass in, and any options you specify. It does NOT wait for the results, you cannot do that from outside a task.

From inside a task

You can trigger tasks from other tasks using trigger() or batchTrigger(). You can also trigger and wait for the result of triggered tasks using triggerAndWait() and batchTriggerAndWait(). This is a powerful way to build complex tasks.

trigger()

This works the same as from outside a task. You call it and you get a handle back, but it does not wait for the result.
/trigger/my-task.ts

batchTrigger()

This works the same as from outside a task. You call it and you get a handle back, but it does not wait for the results.
/trigger/my-task.ts

triggerAndWait()

This is where it gets interesting. You can trigger a task and then wait for the result. This is useful when you need to call a different task and then use the result to continue with your task.
/trigger/parent.ts

batchTriggerAndWait()

You can batch trigger a task and wait for all the results. This is useful for the fan-out pattern, where you need to call a task multiple times and then wait for all the results to continue with your task.
/trigger/nested.ts