@trigger.dev/sdk 4.5.0-rc.6 → 4.5.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/dist/commonjs/v3/ai.d.ts +171 -5
  2. package/dist/commonjs/v3/ai.js +309 -22
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/chat-server.d.ts +8 -0
  5. package/dist/commonjs/v3/chat-server.js +32 -10
  6. package/dist/commonjs/v3/chat-server.js.map +1 -1
  7. package/dist/commonjs/v3/chat-server.test.js +51 -0
  8. package/dist/commonjs/v3/chat-server.test.js.map +1 -1
  9. package/dist/commonjs/v3/createStartSessionAction.test.js +30 -0
  10. package/dist/commonjs/v3/createStartSessionAction.test.js.map +1 -1
  11. package/dist/commonjs/v3/sessions.d.ts +3 -2
  12. package/dist/commonjs/v3/sessions.js +3 -2
  13. package/dist/commonjs/v3/sessions.js.map +1 -1
  14. package/dist/commonjs/version.js +1 -1
  15. package/dist/esm/v3/ai.d.ts +171 -5
  16. package/dist/esm/v3/ai.js +309 -22
  17. package/dist/esm/v3/ai.js.map +1 -1
  18. package/dist/esm/v3/chat-server.d.ts +8 -0
  19. package/dist/esm/v3/chat-server.js +32 -10
  20. package/dist/esm/v3/chat-server.js.map +1 -1
  21. package/dist/esm/v3/chat-server.test.js +51 -0
  22. package/dist/esm/v3/chat-server.test.js.map +1 -1
  23. package/dist/esm/v3/createStartSessionAction.test.js +30 -0
  24. package/dist/esm/v3/createStartSessionAction.test.js.map +1 -1
  25. package/dist/esm/v3/sessions.d.ts +3 -2
  26. package/dist/esm/v3/sessions.js +3 -2
  27. package/dist/esm/v3/sessions.js.map +1 -1
  28. package/dist/esm/version.js +1 -1
  29. package/docs/ai/prompts.mdx +430 -0
  30. package/docs/ai-chat/actions.mdx +115 -0
  31. package/docs/ai-chat/anatomy.mdx +71 -0
  32. package/docs/ai-chat/backend.mdx +817 -0
  33. package/docs/ai-chat/background-injection.mdx +221 -0
  34. package/docs/ai-chat/changelog.mdx +850 -0
  35. package/docs/ai-chat/chat-local.mdx +174 -0
  36. package/docs/ai-chat/client-protocol.mdx +1081 -0
  37. package/docs/ai-chat/compaction.mdx +411 -0
  38. package/docs/ai-chat/custom-agents.mdx +364 -0
  39. package/docs/ai-chat/error-handling.mdx +415 -0
  40. package/docs/ai-chat/fast-starts.mdx +672 -0
  41. package/docs/ai-chat/frontend.mdx +580 -0
  42. package/docs/ai-chat/how-it-works.mdx +230 -0
  43. package/docs/ai-chat/lifecycle-hooks.mdx +530 -0
  44. package/docs/ai-chat/mcp.mdx +101 -0
  45. package/docs/ai-chat/overview.mdx +90 -0
  46. package/docs/ai-chat/patterns/branching-conversations.mdx +284 -0
  47. package/docs/ai-chat/patterns/code-sandbox.mdx +126 -0
  48. package/docs/ai-chat/patterns/database-persistence.mdx +414 -0
  49. package/docs/ai-chat/patterns/human-in-the-loop.mdx +275 -0
  50. package/docs/ai-chat/patterns/large-payloads.mdx +169 -0
  51. package/docs/ai-chat/patterns/oom-resilience.mdx +120 -0
  52. package/docs/ai-chat/patterns/persistence-and-replay.mdx +211 -0
  53. package/docs/ai-chat/patterns/recovery-boot.mdx +230 -0
  54. package/docs/ai-chat/patterns/skills.mdx +221 -0
  55. package/docs/ai-chat/patterns/sub-agents.mdx +383 -0
  56. package/docs/ai-chat/patterns/tool-result-auditing.mdx +148 -0
  57. package/docs/ai-chat/patterns/trusted-edge-signals.mdx +337 -0
  58. package/docs/ai-chat/patterns/version-upgrades.mdx +172 -0
  59. package/docs/ai-chat/pending-messages.mdx +343 -0
  60. package/docs/ai-chat/prompt-caching.mdx +206 -0
  61. package/docs/ai-chat/quick-start.mdx +161 -0
  62. package/docs/ai-chat/reference.mdx +909 -0
  63. package/docs/ai-chat/server-chat.mdx +263 -0
  64. package/docs/ai-chat/sessions.mdx +333 -0
  65. package/docs/ai-chat/testing.mdx +682 -0
  66. package/docs/ai-chat/tools.mdx +191 -0
  67. package/docs/ai-chat/types.mdx +242 -0
  68. package/docs/ai-chat/upgrade-guide.mdx +515 -0
  69. package/docs/apikeys.mdx +54 -0
  70. package/docs/building-with-ai.mdx +261 -0
  71. package/docs/bulk-actions.mdx +49 -0
  72. package/docs/changelog.mdx +6 -0
  73. package/docs/cli-deploy-commands.mdx +9 -0
  74. package/docs/cli-dev-commands.mdx +9 -0
  75. package/docs/cli-dev.mdx +8 -0
  76. package/docs/cli-init-commands.mdx +58 -0
  77. package/docs/cli-introduction.mdx +25 -0
  78. package/docs/cli-list-profiles-commands.mdx +42 -0
  79. package/docs/cli-login-commands.mdx +33 -0
  80. package/docs/cli-logout-commands.mdx +33 -0
  81. package/docs/cli-preview-archive.mdx +59 -0
  82. package/docs/cli-promote-commands.mdx +9 -0
  83. package/docs/cli-switch.mdx +43 -0
  84. package/docs/cli-update-commands.mdx +42 -0
  85. package/docs/cli-whoami-commands.mdx +33 -0
  86. package/docs/community.mdx +6 -0
  87. package/docs/config/config-file.mdx +602 -0
  88. package/docs/config/extensions/additionalFiles.mdx +38 -0
  89. package/docs/config/extensions/additionalPackages.mdx +40 -0
  90. package/docs/config/extensions/aptGet.mdx +34 -0
  91. package/docs/config/extensions/audioWaveform.mdx +20 -0
  92. package/docs/config/extensions/custom.mdx +380 -0
  93. package/docs/config/extensions/emitDecoratorMetadata.mdx +29 -0
  94. package/docs/config/extensions/esbuildPlugin.mdx +31 -0
  95. package/docs/config/extensions/ffmpeg.mdx +45 -0
  96. package/docs/config/extensions/lightpanda.mdx +56 -0
  97. package/docs/config/extensions/overview.mdx +67 -0
  98. package/docs/config/extensions/playwright.mdx +195 -0
  99. package/docs/config/extensions/prismaExtension.mdx +1014 -0
  100. package/docs/config/extensions/puppeteer.mdx +30 -0
  101. package/docs/config/extensions/pythonExtension.mdx +182 -0
  102. package/docs/config/extensions/syncEnvVars.mdx +291 -0
  103. package/docs/context.mdx +235 -0
  104. package/docs/database-connections.mdx +213 -0
  105. package/docs/deploy-environment-variables.mdx +435 -0
  106. package/docs/deployment/atomic-deployment.mdx +172 -0
  107. package/docs/deployment/overview.mdx +257 -0
  108. package/docs/deployment/preview-branches.mdx +224 -0
  109. package/docs/errors-retrying.mdx +379 -0
  110. package/docs/github-actions.mdx +222 -0
  111. package/docs/github-integration.mdx +136 -0
  112. package/docs/github-repo.mdx +8 -0
  113. package/docs/help-email.mdx +6 -0
  114. package/docs/help-slack.mdx +11 -0
  115. package/docs/hidden-tasks.mdx +56 -0
  116. package/docs/how-it-works.mdx +454 -0
  117. package/docs/how-to-reduce-your-spend.mdx +217 -0
  118. package/docs/idempotency.mdx +504 -0
  119. package/docs/introduction.mdx +223 -0
  120. package/docs/limits.mdx +241 -0
  121. package/docs/logging.mdx +195 -0
  122. package/docs/machines.mdx +952 -0
  123. package/docs/manual-setup.mdx +632 -0
  124. package/docs/mcp-agent-rules.mdx +41 -0
  125. package/docs/mcp-introduction.mdx +385 -0
  126. package/docs/mcp-tools.mdx +273 -0
  127. package/docs/migrating-from-v3.mdx +334 -0
  128. package/docs/observability/dashboards.mdx +102 -0
  129. package/docs/observability/query.mdx +585 -0
  130. package/docs/open-source-contributing.mdx +16 -0
  131. package/docs/open-source-self-hosting.mdx +541 -0
  132. package/docs/private-networking/aws-console-setup.mdx +304 -0
  133. package/docs/private-networking/overview.mdx +144 -0
  134. package/docs/private-networking/troubleshooting.mdx +78 -0
  135. package/docs/queue-concurrency.mdx +354 -0
  136. package/docs/quick-start.mdx +97 -0
  137. package/docs/realtime/auth.mdx +208 -0
  138. package/docs/realtime/backend/overview.mdx +45 -0
  139. package/docs/realtime/backend/streams.mdx +418 -0
  140. package/docs/realtime/backend/subscribe.mdx +225 -0
  141. package/docs/realtime/how-it-works.mdx +94 -0
  142. package/docs/realtime/overview.mdx +63 -0
  143. package/docs/realtime/react-hooks/overview.mdx +73 -0
  144. package/docs/realtime/react-hooks/streams.mdx +449 -0
  145. package/docs/realtime/react-hooks/subscribe.mdx +674 -0
  146. package/docs/realtime/react-hooks/swr.mdx +87 -0
  147. package/docs/realtime/react-hooks/triggering.mdx +194 -0
  148. package/docs/realtime/react-hooks/use-wait-token.mdx +34 -0
  149. package/docs/realtime/run-object.mdx +174 -0
  150. package/docs/replaying.mdx +72 -0
  151. package/docs/request-feature.mdx +6 -0
  152. package/docs/roadmap.mdx +6 -0
  153. package/docs/run-tests.mdx +20 -0
  154. package/docs/run-usage.mdx +113 -0
  155. package/docs/runs/heartbeats.mdx +38 -0
  156. package/docs/runs/max-duration.mdx +139 -0
  157. package/docs/runs/metadata.mdx +734 -0
  158. package/docs/runs/priority.mdx +31 -0
  159. package/docs/runs.mdx +396 -0
  160. package/docs/self-hosting/docker.mdx +458 -0
  161. package/docs/self-hosting/env/supervisor.mdx +74 -0
  162. package/docs/self-hosting/env/webapp.mdx +276 -0
  163. package/docs/self-hosting/kubernetes.mdx +601 -0
  164. package/docs/self-hosting/overview.mdx +108 -0
  165. package/docs/skills.mdx +85 -0
  166. package/docs/tags.mdx +120 -0
  167. package/docs/tasks/overview.mdx +697 -0
  168. package/docs/tasks/scheduled.mdx +382 -0
  169. package/docs/tasks/schemaTask.mdx +413 -0
  170. package/docs/tasks/streams.mdx +884 -0
  171. package/docs/triggering.mdx +1320 -0
  172. package/docs/troubleshooting-alerts.mdx +385 -0
  173. package/docs/troubleshooting-debugging-in-vscode.mdx +8 -0
  174. package/docs/troubleshooting-github-issues.mdx +6 -0
  175. package/docs/troubleshooting-uptime-status.mdx +6 -0
  176. package/docs/troubleshooting.mdx +398 -0
  177. package/docs/upgrading-packages.mdx +80 -0
  178. package/docs/vercel-integration.mdx +207 -0
  179. package/docs/versioning.mdx +56 -0
  180. package/docs/video-walkthrough.mdx +23 -0
  181. package/docs/wait-for-token.mdx +540 -0
  182. package/docs/wait-for.mdx +42 -0
  183. package/docs/wait-until.mdx +53 -0
  184. package/docs/wait.mdx +18 -0
  185. package/docs/writing-tasks-introduction.mdx +33 -0
  186. package/package.json +8 -5
  187. package/skills/trigger-authoring-chat-agent/SKILL.md +296 -0
  188. package/skills/trigger-authoring-tasks/SKILL.md +254 -0
  189. package/skills/trigger-chat-agent-advanced/SKILL.md +368 -0
  190. package/skills/trigger-cost-savings/SKILL.md +116 -0
  191. package/skills/trigger-realtime-and-frontend/SKILL.md +276 -0
@@ -0,0 +1,354 @@
1
+ ---
2
+ title: "Concurrency & Queues"
3
+ description: "Configure what you want to happen when there is more than one run at a time."
4
+ ---
5
+
6
+ When you trigger a task, it isn't executed immediately. Instead, the task [run](/runs) is placed into a queue for execution.
7
+
8
+ By default, each task gets its own queue and the concurrency is only limited by your environment concurrency limit. If you need more control (for example, to limit concurrency or share limits across multiple tasks), you can define a custom queue as described later.
9
+
10
+ Controlling concurrency is useful when you have a task that can't be run concurrently, or when you want to limit the number of runs to avoid overloading a resource.
11
+
12
+ It's important to note that only actively executing runs count towards concurrency limits. Runs that are delayed or waiting in a queue do not consume concurrency slots until they begin execution.
13
+
14
+ ## Default concurrency
15
+
16
+ By default, all tasks have an unbounded concurrency limit, limited only by the overall concurrency limits of your environment.
17
+
18
+ <Note>
19
+ Your environment has a base concurrency limit and a burstable limit (default burst factor of 2.0x
20
+ the base limit). Individual queues are limited by the base concurrency limit, not the burstable
21
+ limit. For example, if your base limit is 10, your environment can burst up to 20 concurrent runs,
22
+ but any single queue can have at most 10 concurrent runs. If you're a paying customer you can
23
+ request higher burst limits by [contacting us](https://www.trigger.dev/contact).
24
+ </Note>
25
+
26
+ ## Setting task concurrency
27
+
28
+ You can set the concurrency limit for a task by setting the `concurrencyLimit` property on the task's queue. This limits the number of runs that can be executing at any one time:
29
+
30
+ ```ts /trigger/one-at-a-time.ts
31
+ // This task will only run one at a time
32
+ export const oneAtATime = task({
33
+ id: "one-at-a-time",
34
+ queue: {
35
+ concurrencyLimit: 1,
36
+ },
37
+ run: async (payload) => {
38
+ //...
39
+ },
40
+ });
41
+ ```
42
+
43
+ This is useful if you need to control access to a shared resource, like a database or an API that has rate limits.
44
+
45
+ ## Sharing concurrency between tasks
46
+
47
+ As well as putting queue settings directly on a task, you can define a queue and reuse it across multiple tasks. This allows you to share the same concurrency limit:
48
+
49
+ ```ts /trigger/queue.ts
50
+ export const myQueue = queue({
51
+ name: "my-queue",
52
+ concurrencyLimit: 1,
53
+ });
54
+
55
+ export const task1 = task({
56
+ id: "task-1",
57
+ queue: myQueue,
58
+ run: async (payload: { message: string }) => {
59
+ // ...
60
+ },
61
+ });
62
+
63
+ export const task2 = task({
64
+ id: "task-2",
65
+ queue: myQueue,
66
+ run: async (payload: { message: string }) => {
67
+ // ...
68
+ },
69
+ });
70
+ ```
71
+
72
+ In this example, `task1` and `task2` share the same queue, so only one of them can run at a time.
73
+
74
+ ## Setting the queue when you trigger a run
75
+
76
+ When you trigger a task you can override the default queue. This is really useful if you sometimes have high priority runs.
77
+
78
+ The task and queue definition:
79
+
80
+ ```ts /trigger/override-concurrency.ts
81
+ const paidQueue = queue({
82
+ name: "paid-users",
83
+ concurrencyLimit: 10,
84
+ });
85
+
86
+ export const generatePullRequest = task({
87
+ id: "generate-pull-request",
88
+ queue: {
89
+ //normally when triggering this task it will be limited to 1 run at a time
90
+ concurrencyLimit: 1,
91
+ },
92
+ run: async (payload) => {
93
+ //todo generate a PR using OpenAI
94
+ },
95
+ });
96
+ ```
97
+
98
+ Triggering from your backend and overriding the queue:
99
+
100
+ ```ts app/api/push/route.ts
101
+ import { generatePullRequest } from "~/trigger/override-concurrency";
102
+
103
+ export async function POST(request: Request) {
104
+ const data = await request.json();
105
+
106
+ if (data.branch === "main") {
107
+ //trigger the task, with the paid users queue
108
+ const handle = await generatePullRequest.trigger(data, {
109
+ // Set the paid users queue
110
+ queue: "paid-users",
111
+ });
112
+
113
+ return Response.json(handle);
114
+ } else {
115
+ //triggered with the default queue (concurrency of 1)
116
+ const handle = await generatePullRequest.trigger(data);
117
+ return Response.json(handle);
118
+ }
119
+ }
120
+ ```
121
+
122
+ ## Concurrency keys and per-tenant queuing
123
+
124
+ If you're building an application where you want to run tasks for your users, you might want a separate queue for each of your users (or orgs, projects, etc.).
125
+
126
+ You can do this by using `concurrencyKey`. It creates a copy of the queue for each unique value of the key.
127
+
128
+ Your backend code:
129
+
130
+ ```ts app/api/pr/route.ts
131
+ import { generatePullRequest } from "~/trigger/override-concurrency";
132
+
133
+ export async function POST(request: Request) {
134
+ const data = await request.json();
135
+
136
+ if (data.isFreeUser) {
137
+ //the "free-users" queue has a concurrency limit of 1
138
+ const handle = await generatePullRequest.trigger(data, {
139
+ queue: "free-users",
140
+ //this creates a free-users queue for each user
141
+ concurrencyKey: data.userId,
142
+ });
143
+
144
+ //return a success response with the handle
145
+ return Response.json(handle);
146
+ } else {
147
+ //the "paid-users" queue has a concurrency limit of 10
148
+ const handle = await generatePullRequest.trigger(data, {
149
+ queue: "paid-users",
150
+ //this creates a paid-users queue for each user
151
+ concurrencyKey: data.userId,
152
+ });
153
+
154
+ //return a success response with the handle
155
+ return Response.json(handle);
156
+ }
157
+ }
158
+ ```
159
+
160
+ ## Concurrency and subtasks
161
+
162
+ When you trigger a task that has subtasks, the subtasks will not inherit the queue from the parent task. Unless otherwise specified, subtasks will run on their own queue
163
+
164
+ ```ts /trigger/subtasks.ts
165
+ export const parentTask = task({
166
+ id: "parent-task",
167
+ run: async (payload) => {
168
+ //trigger a subtask
169
+ await subtask.triggerAndWait(payload);
170
+ },
171
+ });
172
+
173
+ // This subtask will run on its own queue
174
+ export const subtask = task({
175
+ id: "subtask",
176
+ run: async (payload) => {
177
+ //...
178
+ },
179
+ });
180
+ ```
181
+
182
+ ## Waits and concurrency
183
+
184
+ With our [task checkpoint system](/how-it-works#the-checkpoint-resume-system), tasks can wait at various waitpoints (like waiting for subtasks to complete, delays, or external events). The way this system interacts with the concurrency system is important to understand.
185
+
186
+ Concurrency is only released when a run reaches a waitpoint and is checkpointed. When a run is checkpointed, it transitions to the `WAITING` state and releases its concurrency slot back to both the queue and the environment, allowing other runs to execute or resume.
187
+
188
+ This means that:
189
+
190
+ - Only actively executing runs count towards concurrency limits
191
+ - Runs in the `WAITING` state (checkpointed at waitpoints) do not consume concurrency slots
192
+ - You can have more runs in the `WAITING` state than your queue's concurrency limit
193
+ - When a waiting run resumes (e.g., when a subtask completes), it must re-acquire a concurrency slot
194
+
195
+ For example, if you have a queue with a `concurrencyLimit` of 1:
196
+
197
+ - You can only have exactly 1 run executing at a time
198
+ - You may have multiple runs in the `WAITING` state that belong to that queue
199
+ - When the executing run reaches a waitpoint and checkpoints, it releases its slot
200
+ - The next queued run can then begin execution
201
+
202
+ ### Waiting for a subtask on a different queue
203
+
204
+ When a parent task triggers and waits for a subtask on a different queue, the parent task will checkpoint and release its concurrency slot once it reaches the wait point. This prevents environment deadlocks where all concurrency slots would be occupied by waiting tasks.
205
+
206
+ ```ts /trigger/waiting.ts
207
+ export const parentTask = task({
208
+ id: "parent-task",
209
+ queue: {
210
+ concurrencyLimit: 1,
211
+ },
212
+ run: async (payload) => {
213
+ //trigger a subtask and wait for it to complete
214
+ await subtask.triggerAndWait(payload);
215
+ // The parent task checkpoints here and releases its concurrency slot
216
+ // allowing other tasks to execute while waiting
217
+ },
218
+ });
219
+
220
+ export const subtask = task({
221
+ id: "subtask",
222
+ run: async (payload) => {
223
+ //...
224
+ },
225
+ });
226
+ ```
227
+
228
+ When the parent task reaches the `triggerAndWait` call, it checkpoints and transitions to the `WAITING` state, releasing its concurrency slot back to both its queue and the environment. Once the subtask completes, the parent task will resume and re-acquire a concurrency slot.
229
+
230
+ ## Managing queues with the SDK
231
+
232
+ The SDK provides a `queues` namespace that allows you to manage queues programmatically. You can list, retrieve, pause, resume, and modify concurrency limits for queues.
233
+
234
+ <Note>
235
+ Import from `@trigger.dev/sdk`:
236
+ ```ts
237
+ import { queues } from "@trigger.dev/sdk";
238
+ ```
239
+ </Note>
240
+
241
+ ### Listing queues
242
+
243
+ You can list all queues in your environment with pagination support:
244
+
245
+ ```ts
246
+ import { queues } from "@trigger.dev/sdk";
247
+
248
+ // List all queues (returns paginated results)
249
+ const allQueues = await queues.list();
250
+
251
+ // With pagination options
252
+ const pagedQueues = await queues.list({
253
+ page: 1,
254
+ perPage: 20,
255
+ });
256
+ ```
257
+
258
+ ### Retrieving a queue
259
+
260
+ You can retrieve a specific queue by its ID, or by its type and name:
261
+
262
+ ```ts
263
+ import { queues } from "@trigger.dev/sdk";
264
+
265
+ // Using queue ID (starts with "queue_")
266
+ const queueById = await queues.retrieve("queue_1234");
267
+
268
+ // Using type and name for a task's default queue
269
+ const taskQueue = await queues.retrieve({
270
+ type: "task",
271
+ name: "my-task-id",
272
+ });
273
+
274
+ // Using type and name for a custom queue
275
+ const customQueue = await queues.retrieve({
276
+ type: "custom",
277
+ name: "my-custom-queue",
278
+ });
279
+ ```
280
+
281
+ The queue object contains useful information about the queue state:
282
+
283
+ ```ts
284
+ {
285
+ id: "queue_1234", // Queue ID
286
+ name: "my-task-id", // Queue name
287
+ type: "task", // "task" or "custom"
288
+ running: 5, // Currently executing runs
289
+ queued: 10, // Runs waiting to execute
290
+ paused: false, // Whether the queue is paused
291
+ concurrencyLimit: 10, // Current concurrency limit
292
+ concurrency: {
293
+ current: 10, // Effective limit
294
+ base: 10, // Default limit from code
295
+ override: null, // Override value (if set)
296
+ overriddenAt: null, // When override was applied
297
+ overriddenBy: null, // Who applied the override
298
+ }
299
+ }
300
+ ```
301
+
302
+ ### Pausing and resuming queues
303
+
304
+ You can pause a queue to prevent new runs from starting. Runs that are currently executing will continue to completion.
305
+
306
+ ```ts
307
+ import { queues } from "@trigger.dev/sdk";
308
+
309
+ // Pause a queue using its ID
310
+ await queues.pause("queue_1234");
311
+
312
+ // Or using type and name
313
+ await queues.pause({ type: "task", name: "my-task-id" });
314
+ await queues.pause({ type: "custom", name: "my-custom-queue" });
315
+ ```
316
+
317
+ To resume a paused queue and allow new runs to start:
318
+
319
+ ```ts
320
+ import { queues } from "@trigger.dev/sdk";
321
+
322
+ // Resume a queue using its ID
323
+ await queues.resume("queue_1234");
324
+
325
+ // Or using type and name
326
+ await queues.resume({ type: "task", name: "my-task-id" });
327
+ await queues.resume({ type: "custom", name: "my-custom-queue" });
328
+ ```
329
+
330
+ ### Overriding concurrency limits
331
+
332
+ You can temporarily override a queue's concurrency limit. This is useful for scaling up or down based on demand:
333
+
334
+ ```ts
335
+ import { queues } from "@trigger.dev/sdk";
336
+
337
+ // Set concurrency limit to 5
338
+ await queues.overrideConcurrencyLimit("queue_1234", 5);
339
+
340
+ // Or using type and name
341
+ await queues.overrideConcurrencyLimit({ type: "task", name: "my-task-id" }, 20);
342
+ ```
343
+
344
+ To reset the concurrency limit back to the base value defined in your code:
345
+
346
+ ```ts
347
+ import { queues } from "@trigger.dev/sdk";
348
+
349
+ // Reset concurrency limit to the base value
350
+ await queues.resetConcurrencyLimit("queue_1234");
351
+
352
+ // Or using type and name
353
+ await queues.resetConcurrencyLimit({ type: "task", name: "my-task-id" });
354
+ ```
@@ -0,0 +1,97 @@
1
+ ---
2
+ title: "Quick start: add Trigger.dev to your project"
3
+ sidebarTitle: "Quick start"
4
+ description: "Set up Trigger.dev in your existing project in under 3 minutes. Install the SDK, create your first background task, and trigger it from your code."
5
+ ---
6
+
7
+ import CliInitStep from "/snippets/step-cli-init.mdx";
8
+ import CliDevStep from "/snippets/step-cli-dev.mdx";
9
+ import CliRunTestStep from "/snippets/step-run-test.mdx";
10
+ import CliViewRunStep from "/snippets/step-view-run.mdx";
11
+
12
+ ## Set up with AI
13
+
14
+ Using an AI coding assistant? Copy this prompt and paste it into Claude Code, Cursor, Copilot, Windsurf, or any AI tool. It'll handle the setup for you.
15
+
16
+ <Accordion title="Copy the setup prompt">
17
+
18
+ ```text
19
+ Help me add Trigger.dev to this project.
20
+
21
+ ## What to do
22
+
23
+ 1. I need a Trigger.dev account. If I don't have one, point me to https://cloud.trigger.dev to sign up. Wait for me to confirm.
24
+ 2. Run `npx trigger.dev@latest init` in the project root.
25
+ - When it asks about the MCP server, recommend I install it (best DX: gives you direct access to Trigger.dev docs, deploys, and run monitoring).
26
+ - Install the "Hello World" example task when prompted.
27
+ 3. Run `npx trigger.dev@latest dev` to start the dev server.
28
+ 4. Once the dev server is running, test the example task from the Trigger.dev dashboard.
29
+ 5. Set TRIGGER_SECRET_KEY in my .env file (or .env.local for Next.js). I can find it on the API Keys page in the dashboard.
30
+ 6. Ask me what framework I'm using and show me how to trigger the task from my backend code.
31
+
32
+ If I've already run init and want the MCP server, run: npx trigger.dev@latest install-mcp
33
+
34
+ ## Critical rules
35
+
36
+ - ALWAYS import from `@trigger.dev/sdk`. NEVER import from `@trigger.dev/sdk/v3`.
37
+ - NEVER use `client.defineJob()` — that's the deprecated v2 API.
38
+ - Use type-only imports when triggering from backend code to avoid bundling task code:
39
+
40
+ import type { myTask } from "./trigger/example";
41
+ import { tasks } from "@trigger.dev/sdk";
42
+
43
+ const handle = await tasks.trigger<typeof myTask>("hello-world", { message: "Hello from my app!" });
44
+
45
+ ## When done, point me to
46
+
47
+ - Writing tasks: https://trigger.dev/docs/tasks/overview
48
+ - Real-time updates: https://trigger.dev/docs/realtime/overview
49
+ - AI tooling: https://trigger.dev/docs/building-with-ai
50
+ ```
51
+
52
+ </Accordion>
53
+
54
+ ## Manual setup
55
+
56
+ <Steps titleSize="h3">
57
+
58
+ <Step title="Create a Trigger.dev account">
59
+
60
+ Sign up at [Trigger.dev Cloud](https://cloud.trigger.dev) (or [self-host](/open-source-self-hosting)). The onboarding flow will guide you through creating your first organization and project.
61
+
62
+ </Step>
63
+
64
+ <CliInitStep />
65
+ <CliDevStep />
66
+ <CliRunTestStep />
67
+ <CliViewRunStep />
68
+
69
+ </Steps>
70
+
71
+ ## Triggering tasks from your app
72
+
73
+ The test page in the dashboard is great for verifying your task works. To trigger tasks from your own code, you'll need to set the `TRIGGER_SECRET_KEY` environment variable. Grab it from the API Keys page in the dashboard and add it to your `.env` file.
74
+
75
+ ```bash .env
76
+ TRIGGER_SECRET_KEY=tr_dev_...
77
+ ```
78
+
79
+ See [Triggering](/triggering) for the full guide, or jump straight to framework-specific setup for [Next.js](/guides/frameworks/nextjs), [Remix](/guides/frameworks/remix), or [Node.js](/guides/frameworks/nodejs).
80
+
81
+ ## Next steps
82
+
83
+ <CardGroup cols={2}>
84
+ <Card title="Building with AI" icon="brain" href="/building-with-ai">
85
+ Build Trigger.dev projects using AI coding assistants
86
+ </Card>
87
+ <Card title="How to trigger your tasks" icon="bolt" href="/triggering">
88
+ Trigger tasks from your backend code
89
+ </Card>
90
+ <Card title="Writing tasks" icon="wand-magic-sparkles" href="/tasks/overview">
91
+ Task options, lifecycle hooks, retries, and queues
92
+ </Card>
93
+ <Card title="Guides and example projects" icon="books" href="/guides/introduction">
94
+ Framework guides and working example repos
95
+ </Card>
96
+
97
+ </CardGroup>
@@ -0,0 +1,208 @@
1
+ ---
2
+ title: Realtime authentication
3
+ sidebarTitle: Realtime auth
4
+ description: Authenticating real-time API requests with Public Access Tokens or Trigger Tokens
5
+ ---
6
+
7
+ To use the Realtime API, you need to authenticate your requests with Public Access Tokens or Trigger Tokens. These tokens provide secure, scoped access to your runs and can be used in both frontend and backend applications.
8
+
9
+ ## Token Types
10
+
11
+ There are two types of tokens you can use with the Realtime API:
12
+
13
+ - **[Public Access Tokens](#public-access-tokens-for-subscribing-to-runs)** - Used to read and subscribe to run data. Can be used in both the frontend and backend.
14
+ - **[Trigger Tokens](#trigger-tokens-for-frontend-triggering-only)** - Used to trigger tasks from your frontend. These are more secure, single-use tokens that can only be used in the frontend.
15
+
16
+ ## Public Access Tokens (for subscribing to runs)
17
+
18
+ Use Public Access Tokens to subscribe to runs and receive real-time updates in your frontend or backend.
19
+
20
+ ### Creating Public Access Tokens
21
+
22
+ You can create a Public Access Token using the `auth.createPublicToken` function in your **backend** code:
23
+
24
+ ```tsx
25
+ // Somewhere in your backend code
26
+ import { auth } from "@trigger.dev/sdk";
27
+
28
+ const publicToken = await auth.createPublicToken(); // 👈 this public access token has no permissions, so is pretty useless!
29
+ ```
30
+
31
+ ### Scopes
32
+
33
+ By default a Public Access Token has no permissions. You must specify the scopes you need when creating a Public Access Token:
34
+
35
+ ```ts
36
+ import { auth } from "@trigger.dev/sdk";
37
+
38
+ const publicToken = await auth.createPublicToken({
39
+ scopes: {
40
+ read: {
41
+ runs: true, // ❌ this token can read all runs, possibly useful for debugging/testing
42
+ },
43
+ },
44
+ });
45
+ ```
46
+
47
+ This will allow the token to read all runs, which is probably not what you want. You can specify only certain runs by passing an array of run IDs:
48
+
49
+ ```ts
50
+ import { auth } from "@trigger.dev/sdk";
51
+
52
+ const publicToken = await auth.createPublicToken({
53
+ scopes: {
54
+ read: {
55
+ runs: ["run_1234", "run_5678"], // ✅ this token can read only these runs
56
+ },
57
+ },
58
+ });
59
+ ```
60
+
61
+ You can scope the token to only read certain tasks:
62
+
63
+ ```ts
64
+ import { auth } from "@trigger.dev/sdk";
65
+
66
+ const publicToken = await auth.createPublicToken({
67
+ scopes: {
68
+ read: {
69
+ tasks: ["my-task-1", "my-task-2"], // 👈 this token can read all runs of these tasks
70
+ },
71
+ },
72
+ });
73
+ ```
74
+
75
+ Or tags:
76
+
77
+ ```ts
78
+ import { auth } from "@trigger.dev/sdk";
79
+
80
+ const publicToken = await auth.createPublicToken({
81
+ scopes: {
82
+ read: {
83
+ tags: ["my-tag-1", "my-tag-2"], // 👈 this token can read all runs with these tags
84
+ },
85
+ },
86
+ });
87
+ ```
88
+
89
+ Or a specific batch of runs:
90
+
91
+ ```ts
92
+ import { auth } from "@trigger.dev/sdk";
93
+
94
+ const publicToken = await auth.createPublicToken({
95
+ scopes: {
96
+ read: {
97
+ batch: "batch_1234", // 👈 this token can read all runs in this batch
98
+ },
99
+ },
100
+ });
101
+ ```
102
+
103
+ You can also combine scopes. For example, to read runs with specific tags and for specific tasks:
104
+
105
+ ```ts
106
+ import { auth } from "@trigger.dev/sdk";
107
+
108
+ const publicToken = await auth.createPublicToken({
109
+ scopes: {
110
+ read: {
111
+ tasks: ["my-task-1", "my-task-2"],
112
+ tags: ["my-tag-1", "my-tag-2"],
113
+ },
114
+ },
115
+ });
116
+ ```
117
+
118
+ ### Expiration
119
+
120
+ By default, Public Access Token's expire after 15 minutes. You can specify a different expiration time when creating a Public Access Token:
121
+
122
+ ```ts
123
+ import { auth } from "@trigger.dev/sdk";
124
+
125
+ const publicToken = await auth.createPublicToken({
126
+ expirationTime: "1hr",
127
+ });
128
+ ```
129
+
130
+ - 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
132
+ - If `expirationTime` is a `Date`, it will be treated as a date
133
+
134
+ 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.
135
+
136
+ ### Auto-generated tokens
137
+
138
+ When you [trigger tasks](/triggering) from your backend, the `handle` received includes a `publicAccessToken` field. This token can be used to authenticate real-time requests in your frontend application.
139
+
140
+ By default, auto-generated tokens expire after 15 minutes and have a read scope for the specific run(s) that were triggered. You can customize the expiration by passing a `publicTokenOptions` object to the trigger function.
141
+
142
+ See our [triggering documentation](/triggering) for detailed examples of how to trigger tasks and get auto-generated tokens.
143
+
144
+ <Note>
145
+ **Where should I create tokens?** The standard pattern is to create tokens in your backend code (API route, server action) after triggering a task, then pass the token to your frontend. The `handle.publicAccessToken` returned by `tasks.trigger()` already does this for you. You rarely need to create tokens inside a task itself.
146
+ </Note>
147
+
148
+ ### Subscribing to runs with Public Access Tokens
149
+
150
+ Once you have a Public Access Token, you can use it to authenticate requests to the Realtime API in both backend and frontend applications.
151
+
152
+ **Backend usage:** See our [backend documentation](/realtime/backend) for examples of what you can do with Realtime in your backend once you have authenticated with a token.
153
+
154
+ **Frontend usage:** See our [React hooks documentation](/realtime/react-hooks) for examples of using tokens with frontend components.
155
+
156
+ ## Trigger Tokens (for frontend triggering only)
157
+
158
+ For triggering tasks from your frontend, you need special "trigger" tokens. These tokens can only be used once to trigger a task and are more secure than regular Public Access Tokens.
159
+
160
+ ### Creating Trigger Tokens
161
+
162
+ ```ts
163
+ import { auth } from "@trigger.dev/sdk";
164
+
165
+ // Somewhere in your backend code
166
+ const triggerToken = await auth.createTriggerPublicToken("my-task");
167
+ ```
168
+
169
+ ### Multiple tasks
170
+
171
+ You can pass multiple tasks to create a token that can trigger multiple tasks:
172
+
173
+ ```ts
174
+ import { auth } from "@trigger.dev/sdk";
175
+
176
+ // Somewhere in your backend code
177
+ const triggerToken = await auth.createTriggerPublicToken(["my-task-1", "my-task-2"]);
178
+ ```
179
+
180
+ ### Multiple use
181
+
182
+ You can also create tokens that can be used multiple times:
183
+
184
+ ```ts
185
+ import { auth } from "@trigger.dev/sdk";
186
+
187
+ // Somewhere in your backend code
188
+ const triggerToken = await auth.createTriggerPublicToken("my-task", {
189
+ multipleUse: true, // ❌ Use this with caution!
190
+ });
191
+ ```
192
+
193
+ ### Expiration
194
+
195
+ These tokens also expire, with the default expiration time being 15 minutes. You can specify a custom expiration time:
196
+
197
+ ```ts
198
+ import { auth } from "@trigger.dev/sdk";
199
+
200
+ // Somewhere in your backend code
201
+ const triggerToken = await auth.createTriggerPublicToken("my-task", {
202
+ expirationTime: "24hr",
203
+ });
204
+ ```
205
+
206
+ ### Triggering tasks from the frontend with Trigger Tokens
207
+
208
+ Check out our [React hooks documentation](/realtime/react-hooks) for examples of how to use Trigger Tokens in your frontend applications.