Skip to main content

Installation

The management API is available through the same @trigger.dev/sdk package used in defining and triggering tasks. If you have already installed the package in your project, you can skip this step.

Usage

All v3 functionality is provided through the @trigger.dev/sdk/v3 module. You can import the entire module or individual resources as needed.

Authentication

There are two methods of authenticating with the management API: using a secret key associated with a specific environment in a project (secretKey), or using a personal access token (personalAccessToken). Both methods should only be used in a backend server, as they provide full access to the project.
Support for client-side authentication is coming soon to v3 but is not available at the time of writing.
Certain API functions work with both authentication methods, but require different arguments depending on the method used. For example, the runs.list function can be called using either a secretKey or a personalAccessToken, but the projectRef argument is required when using a personalAccessToken:
Consult the following table to see which endpoints support each authentication method.

Secret key

Secret key authentication scopes the API access to a specific environment in a project, and works with certain endpoints. You can read our API Keys guide for more information.

Personal Access Token (PAT)

A PAT is a token associated with a specific user, and gives access to all the orgs, projects, and environments that the user has access to. You can identify a PAT by the tr_pat_ prefix. Because a PAT does not scope access to a specific environment, you must provide the projectRef argument when using a PAT (and sometimes the environment as well). For example, when uploading environment variables using a PAT, you must provide the projectRef and environment arguments:

Handling errors

When the SDK method is unable to connect to the API server, or the API server returns a non-successful response, the SDK will throw an ApiError that you can catch and handle:

Retries

The SDK will automatically retry requests that fail due to network errors or server errors. By default, the SDK will retry requests up to 3 times, with an exponential backoff delay between retries. You can customize the retry behavior by passing a requestOptions option to the configure function:
All SDK functions also take a requestOptions parameter as the last argument, which can be used to customize the request options. You can use this to disable retries for a specific request:
When running inside a task, the SDK ignores customized retry options for certain functions (e.g., task.trigger, task.batchTrigger), and uses retry settings optimized for task execution.

Auto-pagination

All list endpoints in the management API support auto-pagination. You can use for await … of syntax to iterate through items across all pages:
You can also use helpers on the return value from any list method to get the next/previous page of results:

Advanced usage

Accessing raw HTTP responses

All API methods return a Promise subclass ApiPromise that includes helpers for accessing the underlying HTTP response: