@trigger.dev/sdk 4.7.2 → 4.7.4

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 (97) hide show
  1. package/dist/commonjs/v3/ai.d.ts +5 -0
  2. package/dist/commonjs/v3/ai.js +6 -2
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/chat-server.d.ts +7 -0
  5. package/dist/commonjs/v3/chat-server.js +3 -0
  6. package/dist/commonjs/v3/chat-server.js.map +1 -1
  7. package/dist/commonjs/v3/concurrencyLimits.d.ts +37 -7
  8. package/dist/commonjs/v3/concurrencyLimits.js +38 -70
  9. package/dist/commonjs/v3/concurrencyLimits.js.map +1 -1
  10. package/dist/commonjs/v3/index.d.ts +1 -1
  11. package/dist/commonjs/v3/index.js.map +1 -1
  12. package/dist/commonjs/v3/runs.d.ts +22 -1
  13. package/dist/commonjs/v3/runs.js +6 -3
  14. package/dist/commonjs/v3/runs.js.map +1 -1
  15. package/dist/commonjs/version.js +1 -1
  16. package/dist/esm/v3/ai.d.ts +5 -0
  17. package/dist/esm/v3/ai.js +6 -2
  18. package/dist/esm/v3/ai.js.map +1 -1
  19. package/dist/esm/v3/chat-server.d.ts +7 -0
  20. package/dist/esm/v3/chat-server.js +3 -0
  21. package/dist/esm/v3/chat-server.js.map +1 -1
  22. package/dist/esm/v3/concurrencyLimits.d.ts +37 -7
  23. package/dist/esm/v3/concurrencyLimits.js +38 -70
  24. package/dist/esm/v3/concurrencyLimits.js.map +1 -1
  25. package/dist/esm/v3/index.d.ts +1 -1
  26. package/dist/esm/v3/index.js.map +1 -1
  27. package/dist/esm/v3/runs.d.ts +22 -1
  28. package/dist/esm/v3/runs.js +6 -3
  29. package/dist/esm/v3/runs.js.map +1 -1
  30. package/dist/esm/version.js +1 -1
  31. package/docs/ai-chat/patterns/sub-agents.mdx +33 -0
  32. package/docs/apikeys.mdx +3 -3
  33. package/docs/billing-limits.mdx +1 -1
  34. package/docs/cli-env-commands.mdx +5 -4
  35. package/docs/cli-init-commands.mdx +27 -1
  36. package/docs/cli-login-commands.mdx +20 -0
  37. package/docs/cli-projects-commands.mdx +13 -1
  38. package/docs/cli-runs-commands.mdx +3 -2
  39. package/docs/cli-update-commands.mdx +9 -3
  40. package/docs/cli-whoami-commands.mdx +12 -0
  41. package/docs/concurrency.mdx +32 -0
  42. package/docs/config/extensions/audioWaveform.mdx +4 -1
  43. package/docs/config/extensions/overview.mdx +2 -0
  44. package/docs/config/extensions/prismaExtension.mdx +2 -3
  45. package/docs/config/extensions/puppeteer.mdx +3 -5
  46. package/docs/config/extensions/pythonExtension.mdx +9 -1
  47. package/docs/config/extensions/syncEnvVars.mdx +6 -0
  48. package/docs/deploy-environment-variables.mdx +1 -1
  49. package/docs/deployment/atomic-deployment.mdx +2 -0
  50. package/docs/deployment/dev-branches.mdx +5 -5
  51. package/docs/deployment/overview.mdx +8 -7
  52. package/docs/deployment/preview-branches.mdx +6 -3
  53. package/docs/errors-retrying.mdx +4 -4
  54. package/docs/how-it-works.mdx +5 -5
  55. package/docs/introduction.mdx +6 -0
  56. package/docs/limits.mdx +26 -8
  57. package/docs/logging.mdx +1 -1
  58. package/docs/machines.mdx +1 -1
  59. package/docs/mcp-introduction.mdx +8 -7
  60. package/docs/mcp-tools.mdx +15 -1
  61. package/docs/migrating-from-v3.mdx +1 -1
  62. package/docs/observability/dashboards.mdx +2 -0
  63. package/docs/observability/query.mdx +6 -2
  64. package/docs/private-networking/aws-console-setup.mdx +1 -1
  65. package/docs/private-networking/overview.mdx +1 -1
  66. package/docs/quick-start.mdx +3 -40
  67. package/docs/realtime/auth.mdx +1 -1
  68. package/docs/realtime/backend/input-streams.mdx +159 -0
  69. package/docs/realtime/backend/streams.mdx +25 -10
  70. package/docs/realtime/how-it-works.mdx +1 -1
  71. package/docs/realtime/react-hooks/overview.mdx +1 -1
  72. package/docs/realtime/react-hooks/streams.mdx +2 -2
  73. package/docs/realtime/react-hooks/subscribe.mdx +19 -3
  74. package/docs/realtime/react-hooks/triggering.mdx +2 -2
  75. package/docs/realtime/react-hooks/use-wait-token.mdx +1 -1
  76. package/docs/realtime/run-object.mdx +47 -24
  77. package/docs/replaying.mdx +26 -1
  78. package/docs/reports.mdx +4 -2
  79. package/docs/run-tests.mdx +2 -2
  80. package/docs/run-usage.mdx +3 -3
  81. package/docs/runs/heartbeats.mdx +2 -2
  82. package/docs/runs/list-best-practices.mdx +234 -0
  83. package/docs/runs/metadata.mdx +7 -10
  84. package/docs/runs.mdx +18 -8
  85. package/docs/self-hosting/env/supervisor.mdx +2 -1
  86. package/docs/self-hosting/env/webapp.mdx +6 -0
  87. package/docs/self-hosting/overview.mdx +26 -0
  88. package/docs/tags.mdx +6 -0
  89. package/docs/tasks/scheduled.mdx +11 -5
  90. package/docs/triggering.mdx +8 -0
  91. package/docs/troubleshooting-alerts.mdx +102 -3
  92. package/docs/troubleshooting.mdx +1 -1
  93. package/docs/upgrading-packages.mdx +3 -3
  94. package/docs/vercel-integration.mdx +13 -3
  95. package/docs/versioning.mdx +1 -1
  96. package/docs/wait-for-token.mdx +3 -3
  97. package/package.json +2 -2
package/docs/limits.mdx CHANGED
@@ -43,7 +43,7 @@ You can request a higher rate limit from us if you're on a paid plan.
43
43
  The maximum number of runs that can be queued **per queue** (not across all queues in the environment). Each queue can hold up to its limit independently. When a queue hits its limit, new triggers to that queue are rejected.
44
44
 
45
45
  <Note>
46
- The limits below apply to [Trigger.dev Cloud](https://trigger.dev). If you self-host Trigger.dev, queue size limits are configurable via the `MAXIMUM_DEV_QUEUE_SIZE` and `MAXIMUM_DEPLOYED_QUEUE_SIZE` environment variables — see [Self-hosting environment variables](/self-hosting/env/webapp#run-engine).
46
+ The limits below apply to [Trigger.dev Cloud](https://trigger.dev). If you self-host Trigger.dev, queue size limits are configurable via the `MAXIMUM_DEV_QUEUE_SIZE` and `MAXIMUM_DEPLOYED_QUEUE_SIZE` environment variables — see [Self-hosting environment variables](/self-hosting/env/webapp).
47
47
  </Note>
48
48
 
49
49
  | Pricing tier | Development (per queue) | Staging / Production (per queue) |
@@ -60,7 +60,7 @@ On Trigger.dev Cloud, all runs have an enforced maximum TTL of 14 days. Runs wit
60
60
 
61
61
  There is no maximum on `delay`.
62
62
 
63
- If you self-host, you can configure a maximum TTL via the `RUN_ENGINE_DEFAULT_MAX_TTL` environment variable — see [Self-hosting environment variables](/self-hosting/env/webapp#run-engine).
63
+ If you self-host, you can configure a maximum TTL via the `RUN_ENGINE_DEFAULT_MAX_TTL` environment variable — see [Self-hosting environment variables](/self-hosting/env/webapp).
64
64
 
65
65
  ## Schedules
66
66
 
@@ -124,8 +124,6 @@ Payloads and outputs over 512KB are kept in object storage rather than inline. C
124
124
 
125
125
  A single batch can have a maximum of 1,000 items with SDK 4.3.1+. Prior versions are limited to 500 items.
126
126
 
127
- <SoftLimit />
128
-
129
127
  ## Batch trigger rate limits
130
128
 
131
129
  Batch triggering uses a token bucket algorithm to rate limit the number of runs you can trigger per environment. Each run in a batch consumes one token.
@@ -154,6 +152,26 @@ When you send a batch trigger, we convert it into individual runs. This limit co
154
152
  | Hobby | 10 concurrent batches |
155
153
  | Pro | 50 concurrent batches |
156
154
 
155
+ ## Webhook ingest rate limits
156
+
157
+ Each hosted webhook endpoint accepts a limited number of requests per 10 seconds. Requests over the limit get a `429` response with a `Retry-After` header, and providers that retry deliver them again after the window.
158
+
159
+ | Pricing tier | Requests per endpoint |
160
+ | :----------- | :-------------------- |
161
+ | Free | 100 every 10 sec |
162
+ | Hobby | 300 every 10 sec |
163
+ | Pro | 1,000 every 10 sec |
164
+ | Enterprise | Set per organization |
165
+
166
+ All of an environment's endpoints also share a per-environment limit, counted in tokens: a request costs one token for every 64 KiB of body, started, so a 10 KiB event costs one and a 1 MiB event costs 16. Requests over it get the same `429` with `Retry-After`.
167
+
168
+ | Pricing tier | Tokens per environment |
169
+ | :----------- | :--------------------- |
170
+ | Free | 300 every 10 sec |
171
+ | Hobby | 1,000 every 10 sec |
172
+ | Pro | 3,000 every 10 sec |
173
+ | Enterprise | Set per organization |
174
+
157
175
  ## Log retention
158
176
 
159
177
  | Pricing tier | Limit |
@@ -170,8 +188,8 @@ We limit the size of logs to prevent oversized data potentially causing issues.
170
188
 
171
189
  #### Attribute Limits
172
190
 
173
- - Span Attribute Count Limit: 256
174
- - Log Attribute Count Limit: 256
191
+ - Span Attribute Count Limit: 1024
192
+ - Log Attribute Count Limit: 1024
175
193
  - Span Attribute Value Length Limit: 131072 characters
176
194
  - Log Attribute Value Length Limit: 131072 characters
177
195
 
@@ -188,8 +206,8 @@ We limit the size of logs to prevent oversized data potentially causing issues.
188
206
 
189
207
  #### Attribute Clipping Behavior
190
208
 
191
- - Attributes exceeding the value length limit (1028 characters) are discarded.
192
- - If the total number of attributes exceeds 256, additional attributes are not included.
209
+ - Attributes exceeding the value length limit (131072 characters) are discarded.
210
+ - If the total number of attributes exceeds 1024, additional attributes are not included.
193
211
 
194
212
  #### Attribute Value Size Calculation
195
213
 
package/docs/logging.mdx CHANGED
@@ -159,7 +159,7 @@ Trigger.dev automatically collects the following metrics for deployed tasks. No
159
159
  | `nodejs.heap.total` | gauge | bytes | V8 heap total |
160
160
 
161
161
  <Note>
162
- In dev mode (`trigger dev`), only `process.*` and custom metrics are available.
162
+ In dev mode (`trigger dev`), the `process.*` and `nodejs.*` metrics above are collected, along with custom metrics.
163
163
  </Note>
164
164
 
165
165
  ### Context attributes
package/docs/machines.mdx CHANGED
@@ -11,7 +11,7 @@ import { task } from "@trigger.dev/sdk";
11
11
  export const heavyTask = task({
12
12
  id: "heavy-task",
13
13
  machine: "large-1x",
14
- run: async ({ payload, ctx }) => {
14
+ run: async (payload, { ctx }) => {
15
15
  //...
16
16
  },
17
17
  });
@@ -299,7 +299,7 @@ After adding the config, restart your client. You should see a server named **tr
299
299
 
300
300
  ## Authentication
301
301
 
302
- The `search_docs` tool works without authentication. All other tools require you to be logged in via the [Trigger.dev CLI](/cli-login-commands). The first time you use an authenticated tool, your MCP client will prompt you to log in.
302
+ The `search_docs` tool works without authentication, and so do the local-only tools `list_profiles`, `dev_server_status` and `stop_dev_server`. All other tools require you to be logged in via the [Trigger.dev CLI](/cli-login-commands). The first time you use an authenticated tool, your MCP client will prompt you to log in.
303
303
 
304
304
  <Accordion title="CLI Options">
305
305
 
@@ -310,7 +310,6 @@ The `install-mcp` command supports these options:
310
310
  - `-p, --project-ref <project ref>` — Scope the MCP server to a specific project
311
311
  - `-t, --tag <package tag>` — CLI package version to use (default: latest)
312
312
  - `--dev-only` — Restrict to the dev environment only
313
- - `--readonly` — Read-only mode. Hides write tools (`deploy`, `trigger_task`, `cancel_run`) so the AI cannot make changes to your account
314
313
  - `--yolo` — Install into all supported clients automatically
315
314
  - `--scope <scope>` — `user`, `project`, or `local`
316
315
  - `--client <clients...>` — Install into specific client(s)
@@ -341,17 +340,19 @@ Restrict to dev environment for a specific project:
341
340
  npx trigger.dev@latest install-mcp --dev-only --project-ref proj_abc123
342
341
  ```
343
342
 
344
- Read-only mode (prevents AI from deploying or triggering tasks):
343
+ To add these options to a manual config, append them to the `args` array:
345
344
 
346
- ```bash
347
- npx trigger.dev@latest install-mcp --readonly
345
+ ```json
346
+ {
347
+ "args": ["trigger.dev@latest", "mcp", "--dev-only", "--project-ref", "proj_abc123"]
348
+ }
348
349
  ```
349
350
 
350
- To add these options to a manual config, append them to the `args` array:
351
+ The `mcp` command also accepts `--readonly`, which hides the tools that write to your account (for example `deploy`, `trigger_task` and `cancel_run`) so the AI cannot make changes to it. It is only available as a manual config arg:
351
352
 
352
353
  ```json
353
354
  {
354
- "args": ["trigger.dev@latest", "mcp", "--dev-only", "--project-ref", "proj_abc123"]
355
+ "args": ["trigger.dev@latest", "mcp", "--readonly"]
355
356
  }
356
357
  ```
357
358
 
@@ -102,6 +102,20 @@ Cancel a running or queued run.
102
102
  - `"Cancel run run_abc123"`
103
103
  - `"Stop that task"`
104
104
 
105
+ ### replay_run
106
+
107
+ Replay a run as a new run of the same task, in the same environment. The new run reuses the original run's payload, metadata, tags, queue, concurrency key, and machine unless you override them. See [Replaying](/replaying) for how each option falls back.
108
+
109
+ **Parameters:**
110
+ - `runId` (required): The run to replay, starting with `run_`
111
+ - `payload`, `metadata`, `tags` (optional): Replace the original run's values
112
+ - `queue`, `concurrencyKey`, `machine`, `version`, `region`, `delay`, `ttl`, `idempotencyKey`, `maxAttempts`, `maxDuration`, `priority` (optional): Override the trigger options for the new run
113
+
114
+ **Example usage:**
115
+ - `"Replay run run_abc123"`
116
+ - `"Replay that failed run with userId set to user_456"`
117
+ - `"Replay run run_abc123 on a large-1x machine in 10 minutes"`
118
+
105
119
  ## Deployment Tools
106
120
 
107
121
  ### deploy
@@ -225,7 +239,7 @@ Check the status of the dev server and view recent output. Shows whether it is s
225
239
  - `"Are there any build errors?"`
226
240
 
227
241
  <Callout type="warning">
228
- The deploy and list_preview_branches tools are not available when the MCP server is running with the `--dev-only` flag. The `--readonly` flag hides deploy, trigger_task, and cancel_run.
242
+ The deploy and list_preview_branches tools are not available when the MCP server is running with the `--dev-only` flag. The `--readonly` flag hides deploy, trigger_task, cancel_run, and replay_run.
229
243
  </Callout>
230
244
 
231
245
  ## Agent Chat Tools
@@ -248,7 +248,7 @@ import { task } from "@trigger.dev/sdk";
248
248
 
249
249
  export const myTask = task({
250
250
  id: "my-task",
251
- onStart: ({ payload, ctx }) => {},
251
+ onStart: (payload, { ctx }) => {},
252
252
  run: async (payload, { ctx }) => {},
253
253
  });
254
254
  ```
@@ -98,5 +98,7 @@ There is a separate concurrency limits for metric widgets.
98
98
  | Limit | Details |
99
99
  | :------------------------ | :------------- |
100
100
  | Concurrent widget queries | 30 per project |
101
+ | Custom dashboards | Free 0, Hobby 1, Pro 5 per organization |
102
+ | Widgets per dashboard | Free 0, Hobby 10, Pro 20 |
101
103
 
102
104
  See [Limits](/limits) for details.
@@ -8,6 +8,7 @@ description: "Query allows you to write custom queries against your data using T
8
8
  - `runs`: contains all task run data including status, timing, costs, and task output. Run metadata (key-value set in your task) is not available on the Query page.
9
9
  - `metrics`: contains metrics data for your runs including CPU, memory, and your custom metrics
10
10
  - `llm_metrics`: contains LLM/AI metrics including token usage, costs, latency, and model performance data from GenAI spans
11
+ - `llm_models`: anonymized cross-tenant model performance aggregates (calls, cost, latency, throughput per model per minute); it has no tenant-specific data
11
12
 
12
13
  ### `metrics` table columns
13
14
 
@@ -24,6 +25,9 @@ description: "Query allows you to write custom queries against your data using T
24
25
  | `machine_name` | string | Machine preset (e.g., `small-1x`) |
25
26
  | `worker_version` | string | Worker version |
26
27
  | `environment_type` | string | `PRODUCTION`, `STAGING`, `DEVELOPMENT`, `PREVIEW` |
28
+ | `worker_id` | string | Worker ID that produced the metric |
29
+ | `environment` | string | Environment slug |
30
+ | `project` | string | Project ref, starting with `proj_` |
27
31
  | `attributes` | json | Raw JSON attributes for custom data |
28
32
 
29
33
  See [Logging, tracing & metrics](/logging#automatic-system-and-runtime-metrics) for the full list of automatically collected metrics and how to create custom metrics. You can visualize this data on [Dashboards](/observability/dashboards).
@@ -68,7 +72,7 @@ ORDER BY timeBucket
68
72
  LIMIT 1000
69
73
  ```
70
74
 
71
- Available format types: `bytes`, `percent`, `duration`, `durationSeconds`, `quantity`, `costInDollars`.
75
+ Available format types: `bytes`, `percent`, `duration`, `durationSeconds`, `quantity`, `costInDollars`, `decimalBytes`, `cost`.
72
76
 
73
77
  ## Using the Query dashboard
74
78
 
@@ -602,7 +606,7 @@ LIMIT 100
602
606
 
603
607
  We have several limits to prevent abuse and ensure performance:
604
608
 
605
- - **Concurrency limit**: We limit the number of concurrent queries per organization.
609
+ - **Concurrency limit**: We limit the number of concurrent queries per project.
606
610
  - **Row limit**: We limit the number of rows returned to 10k.
607
611
  - **Time restrictions**: We limit the time period you can query.
608
612
  - **Time/Memory limit**: We limit the memory a query can use and the time it can run for. As well as other limits like AST complexity.
@@ -250,7 +250,7 @@ By default, no one can connect to your endpoint service. You need to explicitly
250
250
 
251
251
  - **Friendly name**: a short, human-readable label for this connection.
252
252
  - **VPC Endpoint Service name**: paste the `com.amazonaws.vpce.<region>.vpce-svc-...` value from Step 4.
253
- - **Target region**: the AWS region your endpoint service lives in.
253
+ - **Target region**: the Trigger.dev region where the VPC Endpoint is created (pick one from the list, such as `us-east-1` or `eu-central-1`), normally the region your tasks run in. If it differs from the region your endpoint service lives in, enable cross-region access in Step 3.
254
254
 
255
255
  </Step>
256
256
  <Step title="Submit">
@@ -119,7 +119,7 @@ All three conditions must be true. No organization can route traffic to another
119
119
 
120
120
  ## Limits
121
121
 
122
- - **Two connections per organization.** This is a soft limit — get in touch if you need more.
122
+ - **Four connections per organization.** This is a soft limit — get in touch if you need more.
123
123
  - **All ports accepted.** Our security group allows all TCP ports from peered CIDRs. You control which ports are reachable through your NLB and target groups.
124
124
  - **Same-region or cross-region.** Connections work within the same region as your tasks or across regions (cross-region adds AWS-level cost and ~10-30ms latency).
125
125
 
@@ -8,48 +8,11 @@ import CliInitStep from "/snippets/step-cli-init.mdx";
8
8
  import CliDevStep from "/snippets/step-cli-dev.mdx";
9
9
  import CliRunTestStep from "/snippets/step-run-test.mdx";
10
10
  import CliViewRunStep from "/snippets/step-view-run.mdx";
11
+ import AgentSetupPrompt from "/snippets/agent-setup-prompt.mdx";
11
12
 
12
- ## Set up with AI
13
+ ## Copy the setup prompt
13
14
 
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. Create a named API key in my Development environment with **Trigger only** access. Set it as TRIGGER_SECRET_KEY in my .env file (or .env.local for Next.js).
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>
15
+ <AgentSetupPrompt />
53
16
 
54
17
  ## Manual setup
55
18
 
@@ -157,7 +157,7 @@ const { parts } = useRealtimeStream<{ url: string }>(runId, "frames", {
157
157
 
158
158
  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.
159
159
 
160
- 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.
160
+ Auto-generated tokens expire after 1 hour and have a read scope for the specific run(s) that were triggered. For a different expiration or scopes, create a token yourself with [`auth.createPublicToken`](#creating-public-access-tokens).
161
161
 
162
162
  See our [triggering documentation](/triggering) for detailed examples of how to trigger tasks and get auto-generated tokens.
163
163
 
@@ -0,0 +1,159 @@
1
+ ---
2
+ title: Input Streams
3
+ sidebarTitle: Input Streams
4
+ description: Send data into running tasks from your backend code
5
+ ---
6
+
7
+ The Input Streams API allows you to send data into running Trigger.dev tasks from your backend code. This enables bidirectional communication — while [output streams](/realtime/backend/streams) let you read data from tasks, input streams let you push data into them.
8
+
9
+ <Note>
10
+ To learn how to receive input stream data inside your tasks, see [Input
11
+ Streams](/tasks/streams#input-streams) in the Streams doc.
12
+ </Note>
13
+
14
+ <Tip>
15
+ Input streams are keyed by `runId` — they're correct for sending data to a specific live run. If you need a bidirectional channel that survives run boundaries (e.g. a chat that resumes tomorrow, an agent coordinated across many runs), look at [`chat.agent`](/ai-chat/overview): it's built on a durable Session row that owns its runs and exposes the same consumer-side API (`on` / `once` / `wait` / `waitWithIdleTimeout`) on its `.in` channel.
16
+ </Tip>
17
+
18
+ ## Sending data to a running task
19
+
20
+ ### Using defined input streams (Recommended)
21
+
22
+ The recommended approach is to use [defined input streams](/tasks/streams#defining-input-streams) for full type safety:
23
+
24
+ ```ts
25
+ import { cancelSignal, approval } from "./trigger/streams";
26
+
27
+ // Cancel a running AI stream
28
+ await cancelSignal.send(runId, { reason: "User clicked stop" });
29
+
30
+ // Approve a draft
31
+ await approval.send(runId, { approved: true, reviewer: "alice@example.com" });
32
+ ```
33
+
34
+ The `.send()` method is fully typed — the data parameter must match the generic type you defined on the input stream.
35
+
36
+ <Note>
37
+ `.send()` works the same regardless of how the task is listening — whether it uses `.wait()`
38
+ (suspending), `.once()` (non-suspending), or `.on()` (continuous). The sender doesn't need to know
39
+ how the task is consuming the data. See [Input Streams](/tasks/streams#input-streams) for details on each
40
+ receiving method.
41
+ </Note>
42
+
43
+ ## Practical examples
44
+
45
+ ### Cancel from a Next.js API route
46
+
47
+ ```ts app/api/cancel/route.ts
48
+ import { cancelStream } from "@/trigger/streams";
49
+
50
+ export async function POST(req: Request) {
51
+ const { runId } = await req.json();
52
+
53
+ await cancelStream.send(runId, { reason: "User clicked stop" });
54
+
55
+ return Response.json({ cancelled: true });
56
+ }
57
+ ```
58
+
59
+ ### Approval workflow API
60
+
61
+ ```ts app/api/approve/route.ts
62
+ import { approval } from "@/trigger/streams";
63
+
64
+ export async function POST(req: Request) {
65
+ const { runId, approved, reviewer } = await req.json();
66
+
67
+ await approval.send(runId, {
68
+ approved,
69
+ reviewer,
70
+ });
71
+
72
+ return Response.json({ success: true });
73
+ }
74
+ ```
75
+
76
+ ### Remix action handler
77
+
78
+ ```ts app/routes/api.approve.ts
79
+ import { json, type ActionFunctionArgs } from "@remix-run/node";
80
+ import { approval } from "~/trigger/streams";
81
+
82
+ export async function action({ request }: ActionFunctionArgs) {
83
+ const formData = await request.formData();
84
+ const runId = formData.get("runId") as string;
85
+ const approved = formData.get("approved") === "true";
86
+ const reviewer = formData.get("reviewer") as string;
87
+
88
+ await approval.send(runId, { approved, reviewer });
89
+
90
+ return json({ success: true });
91
+ }
92
+ ```
93
+
94
+ ### Express handler
95
+
96
+ ```ts
97
+ import express from "express";
98
+ import { cancelSignal } from "./trigger/streams";
99
+
100
+ const app = express();
101
+ app.use(express.json());
102
+
103
+ app.post("/api/cancel", async (req, res) => {
104
+ const { runId, reason } = req.body;
105
+
106
+ await cancelSignal.send(runId, { reason });
107
+
108
+ res.json({ cancelled: true });
109
+ });
110
+ ```
111
+
112
+ ### Sending from another task
113
+
114
+ You can send input stream data from one task to another running task:
115
+
116
+ ```ts
117
+ import { task } from "@trigger.dev/sdk";
118
+ import { approval } from "./streams";
119
+
120
+ export const reviewerTask = task({
121
+ id: "auto-reviewer",
122
+ run: async (payload: { targetRunId: string }) => {
123
+ // Perform automated review logic...
124
+ const isApproved = await performReview();
125
+
126
+ // Send approval to the waiting task
127
+ await approval.send(payload.targetRunId, {
128
+ approved: isApproved,
129
+ reviewer: "auto-reviewer",
130
+ });
131
+ },
132
+ });
133
+ ```
134
+
135
+ ## Error handling
136
+
137
+ The `.send()` method will throw if:
138
+
139
+ - The run has already completed, failed, or been canceled
140
+ - The payload exceeds the 1MB size limit
141
+ - The run ID is invalid
142
+
143
+ ```ts
144
+ import { cancelSignal } from "./trigger/streams";
145
+
146
+ try {
147
+ await cancelSignal.send(runId, { reason: "User clicked stop" });
148
+ } catch (error) {
149
+ console.error("Failed to send:", error);
150
+ // Handle the error — the run may have already completed
151
+ }
152
+ ```
153
+
154
+ ## Important notes
155
+
156
+ - Maximum payload size per `.send()` call is **1MB**
157
+ - You cannot send data to a completed, failed, or canceled run
158
+ - Data sent before a listener is registered inside the task is **buffered** and delivered when a listener attaches
159
+ - Input streams require the current streams implementation (v2 is the default in SDK 4.1.0+). See [Streams](/tasks/streams) for details.
@@ -90,18 +90,16 @@ async function consumeWithTimeout(runId: string) {
90
90
  timeoutInSeconds: 120, // Wait up to 2 minutes for data
91
91
  });
92
92
 
93
- try {
94
- for await (const chunk of stream) {
95
- console.log("Received chunk:", chunk);
96
- }
97
- } catch (error) {
98
- if (error.name === "TimeoutError") {
99
- console.log("Stream timed out");
100
- }
93
+ for await (const chunk of stream) {
94
+ console.log("Received chunk:", chunk);
101
95
  }
96
+
97
+ // The loop ends normally if no data arrives within the timeout
102
98
  }
103
99
  ```
104
100
 
101
+ If no data arrives within `timeoutInSeconds`, the stream closes and the `for await` loop ends without throwing an error. To detect a timeout, track whether you received the chunk you expected to be last.
102
+
105
103
  ### Start index
106
104
 
107
105
  Resume reading from a specific chunk index (useful for reconnection scenarios):
@@ -122,6 +120,25 @@ async function resumeStream(runId: string, lastChunkIndex: number) {
122
120
  }
123
121
  ```
124
122
 
123
+ ### Start from latest
124
+
125
+ Pass `from: "latest"` to start reading at the end of the stream instead of replaying its history. You may still receive the most recent existing chunk before new chunks arrive. The default is `"beginning"`, which replays the full history first. `from` is ignored when `startIndex` is set:
126
+
127
+ ```ts
128
+ import { streams } from "@trigger.dev/sdk";
129
+ import { aiStream } from "./trigger/streams";
130
+
131
+ async function watchLive(runId: string) {
132
+ const stream = await aiStream.read(runId, {
133
+ from: "latest", // Start at the end of the stream instead of replaying history
134
+ });
135
+
136
+ for await (const chunk of stream) {
137
+ console.log("Received chunk:", chunk);
138
+ }
139
+ }
140
+ ```
141
+
125
142
  ### Abort signal
126
143
 
127
144
  Use an `AbortSignal` to cancel stream reading:
@@ -181,8 +198,6 @@ async function advancedStreamConsumption(runId: string) {
181
198
  } catch (error) {
182
199
  if (error.name === "AbortError") {
183
200
  console.log("Stream was cancelled");
184
- } else if (error.name === "TimeoutError") {
185
- console.log("Stream timed out");
186
201
  } else {
187
202
  console.error("Stream error:", error);
188
203
  }
@@ -80,7 +80,7 @@ See our [run metadata docs](/runs/metadata) for more on how to write tasks that
80
80
 
81
81
  You can combine run metadata with the Realtime API to bridge the gap between your trigger.dev tasks and your applications in two ways:
82
82
 
83
- 1. Using our [React hooks](/realtime/react-hooks/subscribe#using-metadata) to subscribe to metadata updates and update your UI in real-time.
83
+ 1. Using our [React hooks](/realtime/react-hooks/subscribe#using-metadata-to-show-progress-in-your-ui) to subscribe to metadata updates and update your UI in real-time.
84
84
  2. Using our [backend functions](/realtime/backend) to subscribe to metadata updates in your backend.
85
85
 
86
86
  ## Limits
@@ -23,7 +23,7 @@ pnpm add @trigger.dev/react-hooks
23
23
  ```
24
24
 
25
25
  ```bash yarn
26
- yarn install @trigger.dev/react-hooks
26
+ yarn add @trigger.dev/react-hooks
27
27
  ```
28
28
 
29
29
  </CodeGroup>
@@ -466,7 +466,7 @@ function MyComponent({ runId, publicAccessToken }: { runId: string; publicAccess
466
466
 
467
467
  ### Throttling updates
468
468
 
469
- The `useRealtimeRunWithStreams` hook accepts an `experimental_throttleInMs` option to throttle the updates from the server. This can be useful if you are getting too many updates and want to reduce the number of updates.
469
+ The `useRealtimeRunWithStreams` hook accepts a `throttleInMs` option to throttle the updates from the server. This can be useful if you are getting too many updates and want to reduce the number of updates.
470
470
 
471
471
  ```tsx
472
472
  import { useRealtimeRunWithStreams } from "@trigger.dev/react-hooks";
@@ -480,7 +480,7 @@ export function MyComponent({
480
480
  }) {
481
481
  const { run, streams, error } = useRealtimeRunWithStreams(runId, {
482
482
  accessToken: publicAccessToken,
483
- experimental_throttleInMs: 1000, // Throttle updates to once per second
483
+ throttleInMs: 1000, // Throttle updates to once per second
484
484
  });
485
485
 
486
486
  if (error) return <div>Error: {error.message}</div>;
@@ -119,6 +119,15 @@ export function RunStatusBadge({
119
119
 
120
120
  You can skip any of: `payload`, `output`, `metadata`, `startedAt`, `delayUntil`, `queuedAt`, `expiredAt`, `completedAt`, `number`, `isTest`, `usageDurationMs`, `costInCents`, `baseCostInCents`, `ttl`, `payloadType`, `outputType`, `runTags`, `error`. The `useRealtimeRunsWithTag` hook also accepts a `skipColumns` option in the same way.
121
121
 
122
+ By default the hook stops subscribing once the run completes. Pass `stopOnCompletion: false` to keep receiving updates after completion, for example metadata updates from child runs.
123
+
124
+ ```tsx
125
+ const { run, error } = useRealtimeRun(runId, {
126
+ accessToken: publicAccessToken,
127
+ stopOnCompletion: false, // Keep receiving updates after the run completes
128
+ });
129
+ ```
130
+
122
131
  See our [run object reference](/realtime/run-object) for the complete schema and [How it Works documentation](/realtime/how-it-works) for more technical details.
123
132
 
124
133
  ### useRealtimeRunsWithTag
@@ -198,6 +207,14 @@ export function MyComponent({ tag }: { tag: string }) {
198
207
  }
199
208
  ```
200
209
 
210
+ You can also pass an array of tags, and use the `createdAt` option to only subscribe to runs created within a recent period. It accepts a duration string such as `"30m"` or `"1h"` and is applied when the subscription starts. The default and maximum lookback is 24 hours, so longer durations are capped at 24 hours.
211
+
212
+ ```tsx
213
+ const { runs, error } = useRealtimeRunsWithTag(["user:123", "report"], {
214
+ createdAt: "1h", // Only runs created in the last hour
215
+ });
216
+ ```
217
+
201
218
  ### useRealtimeBatch
202
219
 
203
220
  The `useRealtimeBatch` hook allows you to subscribe to a batch of runs by its the batch ID.
@@ -246,13 +263,12 @@ export function ProgressMonitor({
246
263
  runId: string;
247
264
  publicAccessToken: string;
248
265
  }) {
249
- const { run, error, isLoading } = useRealtimeRun(runId, {
266
+ const { run, error } = useRealtimeRun(runId, {
250
267
  accessToken: publicAccessToken,
251
268
  });
252
269
 
253
- if (isLoading) return <div>Loading run...</div>;
254
270
  if (error) return <div>Error: {error.message}</div>;
255
- if (!run) return <div>Run not found</div>;
271
+ if (!run) return <div>Loading run...</div>;
256
272
 
257
273
  const progress = run.metadata?.progress as
258
274
  | {
@@ -84,8 +84,8 @@ export function MyComponent({ publicAccessToken }: { publicAccessToken: string }
84
84
  accessToken: publicAccessToken, // 👈 this is the "trigger" token
85
85
  });
86
86
 
87
- // use the handle object to preserve type-safety 👇
88
- const { run, error: realtimeError } = useRealtimeRun(handle, {
87
+ // pass the run ID and the task type to preserve type-safety 👇
88
+ const { run, error: realtimeError } = useRealtimeRun<typeof myTask>(handle?.id, {
89
89
  accessToken: handle?.publicAccessToken,
90
90
  enabled: !!handle, // Only subscribe to the run if the handle is available
91
91
  });
@@ -15,7 +15,7 @@ const token = await wait.createToken({
15
15
 
16
16
  return {
17
17
  tokenId: token.id,
18
- publicToken: token.publicAccessToken, // An automatically generated public access token that expires in 1 hour
18
+ publicToken: token.publicAccessToken, // An automatically generated public access token that expires in 24 hours
19
19
  };
20
20
  ```
21
21