You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/apikeys.mdx
+32-55Lines changed: 32 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,15 @@
1
1
---
2
2
title: "API keys"
3
-
description: "Authenticate backend requests with environment-specific API keys and restrict additional keys to the access each integration needs."
3
+
description: "Authenticate backend requests with environment-specific API keys."
4
4
---
5
5
6
-
**API keys authenticate backend requests to a specific Trigger.dev project and environment.** Each environment has a root key, and you can create additional named keys for separate services and integrations.
6
+
**API keys authenticate backend requests to a specific Trigger.dev project and environment.** Each environment can have multiple keys, with optional scopes and restrictions attached.
7
7
8
8
<Warning>
9
9
API keys grant access to your Trigger.dev environment. Store them in a secret manager or backend
10
10
environment variable, never commit them to source control, and never expose them in frontend code.
|**Root key**| Full access to the environment | Available to copy from the dashboard | Regenerate it with a 24-hour grace period for the previous value |
20
-
|**Additional key**| Full or restricted access | Shown once when created, then stored as a hash and displayed only by its suffix | Set an optional expiration date or revoke it immediately |
21
-
22
-
Root keys use prefixes such as `tr_dev_`, `tr_stg_`, `tr_prod_`, and `tr_preview_`. Additional keys include `_sk_` after the environment, for example `tr_prod_sk_…`.
23
-
24
-
Use additional keys to give each backend service, deployment pipeline, or external integration its own credential. This lets you revoke one integration without rotating the environment's root key.
25
-
26
13
## Find your API keys
27
14
28
15
Open your project in the dashboard, select an environment, and open the **API keys** page.
@@ -38,12 +25,6 @@ API keys belong to one environment. A Development key cannot access Production,
38
25
39
26
Set `TRIGGER_SECRET_KEY` in your backend environment. The SDK reads it automatically for operations such as triggering tasks and retrieving runs.
40
27
41
-
```bash .env
42
-
TRIGGER_SECRET_KEY="tr_prod_…"
43
-
```
44
-
45
-
Additional keys use the same environment variable:
46
-
47
28
```bash .env
48
29
TRIGGER_SECRET_KEY="tr_prod_sk_…"
49
30
```
@@ -52,12 +33,13 @@ To configure the SDK in code, pass the key to `configure`:
Create a separate key for each service or integration that accesses Trigger.dev.
77
59
@@ -97,79 +79,74 @@ Create a separate key for each service or integration that accesses Trigger.dev.
97
79
</Step>
98
80
</Steps>
99
81
100
-
The dashboard displays the key's status, access, creator, creation time, and last-used time without storing or revealing its plaintext value.
101
-
102
82
## Access presets
103
83
104
-
Access presets define what an additional key can do. The dashboard shows which presets are available for your plan.
84
+
Access presets define what a key can do. Some presets require a paid plan. The dashboard shows which presets your organization can use — see [pricing](https://trigger.dev/pricing).
105
85
106
86
| Preset | Access |
107
87
| --- | --- |
108
88
|**Trigger only**| Trigger runs and batches for all or selected tasks. Trigger responses include scoped public access tokens for the runs and batches they create |
109
89
|**Task operator**| Trigger all or selected tasks and inspect or operate on their runs |
|**Environment operator**| Observe and operate on runs and queues, and trigger tasks |
90
+
|**Observer**| Read runs, tasks, batches, logs, traces, and queues |
91
+
|**Operator**| Observe and operate on runs and queues, and trigger tasks |
112
92
|**Deploy only**| Deploy new versions, read deployment status, and read environment variables |
113
-
|**Environment variables only**| Read and write environment variables in this environment |
114
-
|**No restrictions**| Full access to the environment, matching the root key |
115
-
116
-
**Trigger only** and **Task operator** can be restricted to selected tasks. Task restrictions use task identifiers, such as `send-email`, and continue to apply across deployments. A request involving multiple tasks succeeds only when the key can access every task in the request.
93
+
|**Variables only**| Read and write environment variables in this environment |
94
+
|**No restrictions**| Full access to the environment |
117
95
118
-
Access is fixed when you create a key. Changes to a preset do not alter existing keys. To change a key's access, revoke it and create a replacement.
96
+
**Trigger only** and **Task operator** can be restricted to selected tasks. Task restrictions use task identifiers, such as `send-email`. A request involving multiple tasks — such as a batch trigger — succeeds only when the key can access every task in the request, so a task-restricted key can batch-trigger only its selected tasks.
119
97
120
-
<Warning>
121
-
Streamed batch ingestion is not atomic. When using a task-restricted key, earlier items may be
122
-
accepted before a later item fails validation or authorization.
123
-
</Warning>
124
-
125
-
## Expire and revoke additional keys
98
+
## Expire and revoke keys
126
99
127
100
Set an expiration date when creating a key if the integration only needs temporary access. An expired key stops authenticating automatically.
128
101
129
102
Revoking a key takes effect immediately and cannot be reversed. Requests using the key fail, and the key can no longer create public access tokens. Create a replacement before revoking a key when you need to rotate it without interrupting the integration.
130
103
131
-
Removing a team member does not revoke additional keys they created. Review and revoke their keys separately when their access changes.
132
-
133
-
## Regenerate the root key
134
-
135
-
Regenerating the root key creates a new value immediately. The previous root key remains valid for 24 hours so you can update services without downtime, then stops authenticating.
136
-
137
-
Public access tokens signed with the previous root key remain valid until the earlier of their own expiration and the end of the 24-hour grace period. Additional-key revocation does not have a grace period.
104
+
Removing a team member does not revoke keys they created. Review and revoke their keys separately when their access changes.
138
105
139
106
## Create public access tokens
140
107
141
-
Additional keys can create scoped [Public Access Tokens](/realtime/auth) without receiving the environment's root key. Use `@trigger.dev/sdk` version 4.5.8 or later with additional keys.
108
+
Keys can create scoped [Public Access Tokens](/realtime/auth) without receiving the environment's root key. Use `@trigger.dev/sdk` version 4.5.8 or later with keys.
142
109
143
-
When an additional key calls `auth.createPublicToken()`:
110
+
When a key calls `auth.createPublicToken()`:
144
111
145
112
- The token must request at least one scope.
146
-
- Its scopes cannot exceed the additional key's access.
113
+
- Its scopes cannot exceed the key's access.
147
114
- It expires after 15 minutes by default.
148
115
- Its expiration cannot exceed 30 days.
149
116
- A numeric `expirationTime` is a Unix timestamp in seconds.
150
117
151
-
Revoking or expiring an additional key does not revoke tokens it already created. Those tokens remain valid until their own expiration, unless the environment's root key is regenerated first.
118
+
Revoking or expiring a key does not revoke tokens it already created. Those tokens remain valid until their own expiration, unless the environment's root key is regenerated first.
152
119
153
120
## Target Preview and Development branches
154
121
155
-
Preview and named Development branches use their parent environment's key set. Select the branch by setting `TRIGGER_PREVIEW_BRANCH` alongside the environment key:
122
+
Preview and named Development branches use their parent environment's keys. Select the branch by setting `TRIGGER_PREVIEW_BRANCH` alongside the environment key:
156
123
157
124
```bash .env
158
-
TRIGGER_SECRET_KEY="tr_preview_…"
125
+
TRIGGER_SECRET_KEY="tr_preview_sk_…"
159
126
TRIGGER_PREVIEW_BRANCH="feature/new-checkout"
160
127
```
161
128
162
129
The SDK sends the branch automatically. When calling the API directly, send the same value in the `x-trigger-branch` header.
163
130
131
+
## Root keys
132
+
133
+
<Warning>
134
+
Root keys are legacy, and are likely to be deprecated in the future. We recommend against using them.
135
+
</Warning>
136
+
137
+
Each environment has a single legacy root key. It can be regenerated, which creates a new value immediately. The previous root key remains valid for 24 hours so you can update services without downtime, then stops authenticating.
138
+
139
+
Public access tokens signed with the previous root key remain valid until the earlier of their own expiration and the end of the 24-hour grace period.
140
+
164
141
## Self-hosting
165
142
166
-
Self-hosted installations support multiple additional keys with **No restrictions**. The restricted access presets are available in Trigger.dev Cloud.
143
+
Self-hosted installations support multiple keys with **No restrictions**. The restricted access presets are available in Trigger.dev Cloud.
167
144
168
-
Keep your instance and SDK current before creating additional keys. Calling a public-token API with an additional key on a server that does not support server-minted tokens returns an upgrade error; use the root key until the server is upgraded.
145
+
Keep your instance and SDK current before creating keys. Calling a public-token API with a key on a server that does not support server-minted tokens returns an upgrade error; use the root key until the server is upgraded.
169
146
170
147
## Security recommendations
171
148
172
-
- Create one additional key per service or integration instead of sharing the root key.
149
+
- Create one key per service or integration instead of sharing keys.
173
150
- Choose the narrowest access preset and task selection that supports the integration.
174
151
- Store keys in a secret manager and inject them as backend environment variables.
175
152
- Set expiration dates for temporary integrations and deployment credentials.
- If `expirationTime` is a string, it will be treated as a time span
131
-
- If `expirationTime` is a number, it will be treated as a Unix timestamp
131
+
- If `expirationTime` is a number, it will be treated as a Unix timestamp in **seconds**
132
132
- If `expirationTime` is a `Date`, it will be treated as a date
133
133
134
+
The expiration cannot be more than 30 days from now.
135
+
134
136
The format used for a time span is the same as the [jose package](https://github.com/panva/jose), which is a number followed by a unit. Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability when adding to the current unix timestamp.
0 commit comments