@upstash/workflow 1.4.0-rc → 1.5.0

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 (223) hide show
  1. package/README.md +9 -0
  2. package/astro.d.mts +18 -2
  3. package/astro.d.ts +18 -2
  4. package/astro.js +129 -29
  5. package/astro.mjs +1 -1
  6. package/{chunk-UH6O5IJY.mjs → chunk-J3PXPHSB.mjs} +129 -29
  7. package/cloudflare.d.mts +16 -2
  8. package/cloudflare.d.ts +16 -2
  9. package/cloudflare.js +129 -29
  10. package/cloudflare.mjs +1 -1
  11. package/docs/agents/examples.mdx +8 -0
  12. package/docs/agents/features.mdx +374 -0
  13. package/docs/agents/getting-started.mdx +139 -0
  14. package/docs/agents/overview.mdx +40 -0
  15. package/docs/agents/patterns/evaluator-optimizer.mdx +72 -0
  16. package/docs/agents/patterns/orchestrator-workers.mdx +95 -0
  17. package/docs/agents/patterns/parallelization.mdx +77 -0
  18. package/docs/agents/patterns/prompt-chaining.mdx +84 -0
  19. package/docs/basics/best-practices/at-least-one-step.mdx +57 -0
  20. package/docs/basics/best-practices/business-logic-in-steps.mdx +52 -0
  21. package/docs/basics/best-practices/deterministic-code.mdx +132 -0
  22. package/docs/basics/best-practices/idempotency.mdx +38 -0
  23. package/docs/basics/best-practices/nested-context-methods.mdx +38 -0
  24. package/docs/basics/best-practices/overview.mdx +35 -0
  25. package/docs/basics/best-practices/promise-any.mdx +9 -0
  26. package/docs/basics/best-practices/return-step-results.mdx +80 -0
  27. package/docs/basics/best-practices/workflow-limits.mdx +62 -0
  28. package/docs/basics/client/cancel.mdx +137 -0
  29. package/docs/basics/client/dlq/callback.mdx +21 -0
  30. package/docs/basics/client/dlq/delete.mdx +120 -0
  31. package/docs/basics/client/dlq/list.mdx +96 -0
  32. package/docs/basics/client/dlq/restart.mdx +164 -0
  33. package/docs/basics/client/dlq/resume.mdx +167 -0
  34. package/docs/basics/client/logs.mdx +139 -0
  35. package/docs/basics/client/notify.mdx +79 -0
  36. package/docs/basics/client/trigger.mdx +139 -0
  37. package/docs/basics/client/waiters.mdx +31 -0
  38. package/docs/basics/client.mdx +40 -0
  39. package/docs/basics/how.mdx +65 -0
  40. package/docs/basics/serve/advanced.mdx +435 -0
  41. package/docs/basics/serve.mdx +142 -0
  42. package/docs/changelog.mdx +174 -0
  43. package/docs/examples/allInOne.mdx +377 -0
  44. package/docs/examples/authWebhook.mdx +567 -0
  45. package/docs/examples/customRetry.mdx +309 -0
  46. package/docs/examples/customerOnboarding.mdx +230 -0
  47. package/docs/examples/dynamicWorkflow.mdx +203 -0
  48. package/docs/examples/eCommerceOrderFulfillment.mdx +281 -0
  49. package/docs/examples/imageProcessing.mdx +339 -0
  50. package/docs/examples/paymentRetry.mdx +438 -0
  51. package/docs/examples/waitForEvent.mdx +201 -0
  52. package/docs/features/dlq/callback.mdx +42 -0
  53. package/docs/features/dlq/delete.mdx +29 -0
  54. package/docs/features/dlq/restart.mdx +33 -0
  55. package/docs/features/dlq/resume.mdx +37 -0
  56. package/docs/features/dlq.mdx +39 -0
  57. package/docs/features/failure-callback.mdx +102 -0
  58. package/docs/features/failureFunction/advanced.mdx +36 -0
  59. package/docs/features/failureFunction/reliability.mdx +33 -0
  60. package/docs/features/flow-control/monitor.mdx +22 -0
  61. package/docs/features/flow-control/parallelism.mdx +45 -0
  62. package/docs/features/flow-control/rate-period.mdx +46 -0
  63. package/docs/features/flow-control.mdx +164 -0
  64. package/docs/features/invoke/serveMany.mdx +109 -0
  65. package/docs/features/invoke.mdx +39 -0
  66. package/docs/features/notify.mdx +127 -0
  67. package/docs/features/parallel-steps.mdx +41 -0
  68. package/docs/features/retries/prevent-retries.mdx +140 -0
  69. package/docs/features/retries.mdx +93 -0
  70. package/docs/features/wait-for-event.mdx +104 -0
  71. package/docs/features/wait.mdx +44 -0
  72. package/docs/features/webhooks.mdx +116 -0
  73. package/docs/getstarted.mdx +200 -0
  74. package/docs/howto/cancel.mdx +50 -0
  75. package/docs/howto/changes.mdx +33 -0
  76. package/docs/howto/configure.mdx +42 -0
  77. package/docs/howto/failures.mdx +185 -0
  78. package/docs/howto/get-token.mdx +18 -0
  79. package/docs/howto/local-development/development-server.mdx +130 -0
  80. package/docs/howto/local-development/local-tunnel.mdx +73 -0
  81. package/docs/howto/middlewares.mdx +263 -0
  82. package/docs/howto/migrations.mdx +335 -0
  83. package/docs/howto/multi-region.mdx +107 -0
  84. package/docs/howto/parallel-runs.mdx +52 -0
  85. package/docs/howto/readonly-token.mdx +19 -0
  86. package/docs/howto/realtime/basic.mdx +315 -0
  87. package/docs/howto/realtime/human-in-the-loop.mdx +454 -0
  88. package/docs/howto/redact-fields.mdx +61 -0
  89. package/docs/howto/retry-now.mdx +41 -0
  90. package/docs/howto/schedule.mdx +104 -0
  91. package/docs/howto/security.mdx +143 -0
  92. package/docs/howto/singleton.mdx +137 -0
  93. package/docs/howto/start.mdx +69 -0
  94. package/docs/howto/use-webhooks.mdx +256 -0
  95. package/docs/integrations/aisdk.mdx +316 -0
  96. package/docs/integrations/anthropic.mdx +51 -0
  97. package/docs/integrations/datadog.mdx +69 -0
  98. package/docs/integrations/openai.mdx +87 -0
  99. package/docs/integrations/prometheus.mdx +65 -0
  100. package/docs/integrations/resend.mdx +82 -0
  101. package/docs/llms-txt.mdx +4 -0
  102. package/docs/openapi.yaml +2944 -0
  103. package/docs/pricing.mdx +22 -0
  104. package/docs/quickstarts/astro.mdx +185 -0
  105. package/docs/quickstarts/cloudflare-workers.mdx +190 -0
  106. package/docs/quickstarts/express.mdx +190 -0
  107. package/docs/quickstarts/fastapi.mdx +282 -0
  108. package/docs/quickstarts/flask.mdx +282 -0
  109. package/docs/quickstarts/hono.mdx +221 -0
  110. package/docs/quickstarts/nextjs-fastapi.mdx +147 -0
  111. package/docs/quickstarts/nextjs-flask.mdx +147 -0
  112. package/docs/quickstarts/nuxt.mdx +169 -0
  113. package/docs/quickstarts/platforms.mdx +78 -0
  114. package/docs/quickstarts/solidjs.mdx +161 -0
  115. package/docs/quickstarts/svelte.mdx +170 -0
  116. package/docs/quickstarts/tanstack-start.mdx +205 -0
  117. package/docs/quickstarts/vercel-nextjs.mdx +233 -0
  118. package/docs/roadmap.mdx +8 -0
  119. package/docs/sdk/workflow-js.mdx +4 -0
  120. package/docs/sdk/workflow-py.mdx +4 -0
  121. package/docs/steps/api.mdx +64 -0
  122. package/docs/steps/call.mdx +183 -0
  123. package/docs/steps/cancel.mdx +25 -0
  124. package/docs/steps/createWebhook.mdx +40 -0
  125. package/docs/steps/invoke.mdx +100 -0
  126. package/docs/steps/notify.mdx +105 -0
  127. package/docs/steps/run.mdx +150 -0
  128. package/docs/steps/sleep.mdx +97 -0
  129. package/docs/steps/sleepUntil.mdx +88 -0
  130. package/docs/steps/waitForEvent.mdx +60 -0
  131. package/docs/steps/waitForWebhook.mdx +78 -0
  132. package/docs/steps.mdx +108 -0
  133. package/docs/troubleshooting/general.mdx +331 -0
  134. package/docs/troubleshooting/vercel.mdx +82 -0
  135. package/express.d.mts +18 -2
  136. package/express.d.ts +18 -2
  137. package/express.js +129 -29
  138. package/express.mjs +1 -1
  139. package/h3.d.mts +18 -2
  140. package/h3.d.ts +18 -2
  141. package/h3.js +129 -29
  142. package/h3.mjs +1 -1
  143. package/hono.d.mts +16 -2
  144. package/hono.d.ts +16 -2
  145. package/hono.js +129 -29
  146. package/hono.mjs +1 -1
  147. package/index.d.mts +49 -21
  148. package/index.d.ts +49 -21
  149. package/index.js +145 -41
  150. package/index.mjs +17 -13
  151. package/nextjs.d.mts +39 -2
  152. package/nextjs.d.ts +39 -2
  153. package/nextjs.js +129 -29
  154. package/nextjs.mjs +1 -1
  155. package/package.json +1 -1
  156. package/react-router.d.mts +15 -2
  157. package/react-router.d.ts +15 -2
  158. package/react-router.js +129 -29
  159. package/react-router.mjs +1 -1
  160. package/{serve-many-CbIV7145.d.mts → serve-many-BKukvLNl.d.mts} +1 -1
  161. package/{serve-many-BCtZg31b.d.ts → serve-many-CrLKQpuZ.d.ts} +1 -1
  162. package/solidjs.d.mts +9 -1
  163. package/solidjs.d.ts +9 -1
  164. package/solidjs.js +129 -29
  165. package/solidjs.mjs +1 -1
  166. package/src/platforms/astro.ts +84 -0
  167. package/src/platforms/cloudflare.ts +127 -0
  168. package/src/platforms/express.ts +147 -0
  169. package/src/platforms/h3.ts +105 -0
  170. package/src/platforms/hono.ts +103 -0
  171. package/src/platforms/nextjs.ts +193 -0
  172. package/src/platforms/react-router.ts +92 -0
  173. package/src/platforms/solidjs.ts +59 -0
  174. package/src/platforms/svelte.ts +99 -0
  175. package/src/platforms/tanstack.ts +96 -0
  176. package/src/src/client/dlq.ts +387 -0
  177. package/src/src/client/filter-types.ts +166 -0
  178. package/src/src/client/index.ts +350 -0
  179. package/src/src/client/types.ts +501 -0
  180. package/src/src/client/utils.ts +307 -0
  181. package/src/src/constants.ts +82 -0
  182. package/src/src/context/api/anthropic.ts +58 -0
  183. package/src/src/context/api/base.ts +52 -0
  184. package/src/src/context/api/index.ts +24 -0
  185. package/src/src/context/api/openai.ts +125 -0
  186. package/src/src/context/api/resend.ts +57 -0
  187. package/src/src/context/auto-executor.ts +707 -0
  188. package/src/src/context/context.ts +681 -0
  189. package/src/src/context/index.ts +1 -0
  190. package/src/src/context/provider.ts +37 -0
  191. package/src/src/context/steps.ts +965 -0
  192. package/src/src/error.ts +203 -0
  193. package/src/src/index.ts +13 -0
  194. package/src/src/middleware/default-callbacks.ts +20 -0
  195. package/src/src/middleware/index.ts +2 -0
  196. package/src/src/middleware/logging.ts +39 -0
  197. package/src/src/middleware/manager.ts +148 -0
  198. package/src/src/middleware/middleware.ts +46 -0
  199. package/src/src/middleware/types.ts +72 -0
  200. package/src/src/qstash/headers.ts +397 -0
  201. package/src/src/qstash/step-config.ts +268 -0
  202. package/src/src/qstash/submit-steps.ts +284 -0
  203. package/src/src/serve/authorization.ts +118 -0
  204. package/src/src/serve/index.ts +475 -0
  205. package/src/src/serve/multi-region/handlers.ts +225 -0
  206. package/src/src/serve/multi-region/utils.ts +88 -0
  207. package/src/src/serve/options.ts +241 -0
  208. package/src/src/serve/serve-many.ts +117 -0
  209. package/src/src/serve/utils.ts +11 -0
  210. package/src/src/types.ts +590 -0
  211. package/src/src/utils.ts +141 -0
  212. package/src/src/workflow-parser.ts +472 -0
  213. package/src/src/workflow-requests.ts +575 -0
  214. package/svelte.d.mts +16 -2
  215. package/svelte.d.ts +16 -2
  216. package/svelte.js +129 -29
  217. package/svelte.mjs +1 -1
  218. package/tanstack.d.mts +14 -2
  219. package/tanstack.d.ts +14 -2
  220. package/tanstack.js +129 -29
  221. package/tanstack.mjs +1 -1
  222. package/{types-ffLPVG5_.d.ts → types-CrgK5P6p.d.mts} +124 -24
  223. package/{types-ffLPVG5_.d.mts → types-CrgK5P6p.d.ts} +124 -24
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: "Restart"
3
+ ---
4
+
5
+ The **Restart** action allows you to re-execute a failed workflow run from the beginning.
6
+ All previous step results are discarded, and the workflow executes from scratch using the original configuration and initial payload.
7
+
8
+ This approach is ideal when:
9
+
10
+ - Previous step results are no longer relevant.
11
+ - The failure was caused by corrupted or inconsistent state.
12
+ - You need a completely fresh execution with updated or clean data.
13
+
14
+ <Frame caption="Restart a workflow run from DLQ">
15
+ <img src="/img/workflow/restart.png" alt="Restart a workflow run from the DLQ" />
16
+ </Frame>
17
+
18
+ You can perform this action programmatically as well:
19
+
20
+ <CodeGroup>
21
+ ```typescript TypeScript
22
+ import { Client } from "@upstash/workflow";
23
+
24
+ const client = new Client({ token: "<WORKFLOW_TOKEN>" });
25
+
26
+ await client.dlq.restart({
27
+ dlqId: "dlq-12345",
28
+ retries: 3,
29
+ });
30
+ ```
31
+ </CodeGroup>
32
+
33
+
@@ -0,0 +1,37 @@
1
+ ---
2
+ title: "Resume"
3
+ ---
4
+
5
+ The **Resume** action allows you to continue a failed workflow run from the exact point of failure, preserving all successfully completed steps and their results.
6
+
7
+ This approach is ideal when:
8
+
9
+ - The workflow has long-running or resource-intensive steps that have already succeeded.
10
+ - You want to preserve progress and avoid re-executing successful operations.
11
+ - The failure was a temporary issue that can now be resolved.
12
+
13
+ <Frame caption="You can retry the failure function of a workflow run if it has failed">
14
+ <img src="/img/workflow/resume.png" alt="Resume a workflow run from the DLQ" />
15
+ </Frame>
16
+
17
+ You can perform this action programmatically as well:
18
+
19
+ <CodeGroup>
20
+ ```typescript TypeScript
21
+ import { Client } from "@upstash/workflow";
22
+
23
+ const client = new Client({ token: "<WORKFLOW_TOKEN>" });
24
+
25
+ await client.dlq.resume({
26
+ dlqId: "dlq-12345",
27
+ retries: 3,
28
+ });
29
+ ```
30
+ </CodeGroup>
31
+
32
+ <Note>
33
+ You can modify workflow code as long as changes occur **after** the failed steps.
34
+ Changes to steps prior to the failure are not allowed and may break the workflow.
35
+
36
+ For more details, check out the [Handle workflow route code changes](/workflow/howto/changes) page.
37
+ </Note>
@@ -0,0 +1,39 @@
1
+ ---
2
+ title: Workflow DLQ Overview
3
+ sidebarTitle: "Overview"
4
+ ---
5
+
6
+ The Dead Letter Queue (DLQ) automatically captures failed workflow runs that have exhausted all retry attempts.
7
+
8
+ This ensures that no workflow execution is lost and provides multiple options for recovering from failures gracefully.
9
+
10
+ ## How it works?
11
+
12
+ When a workflow step fails and exhausts all configured retries, Upstash Workflow automatically moves the failed run to the DLQ.
13
+ This happens automatically without any additional configuration required.
14
+
15
+ <Frame caption="Failed workflow runs are automatically moved to the Dead Letter Queue">
16
+ <img src="/img/workflow/dlq.png" alt="Failed workflow runs are automatically moved to the Dead Letter Queue" />
17
+ </Frame>
18
+
19
+ The DLQ serves as a safety net, preserving failed workflow runs with their complete execution context.
20
+
21
+ <Note>
22
+ Dead Letter Queue entries have retention period based on your pricing plan:
23
+ - **Free**: 3 days
24
+ - **Pay-as-you-go**: 1 week
25
+ - **Fixed pricing**: Up to 3 months
26
+
27
+ After the retention duration expires, DLQ items are automatically removed and cannot be recovered.
28
+ </Note>
29
+
30
+ ## Recovery Actions
31
+
32
+ Once a workflow run is in the DLQ, you can take the following actions:
33
+
34
+ - **[Restart](/workflow/features/dlq/restart)** – trigger the workflow from the beginning.
35
+ - **[Resume](/workflow/features/dlq/resume)** – continue the workflow from the point of failure.
36
+ - **[Re-run Failure Function](/workflow/features/dlq/callback)** – execute the workflow's failure handling logic again.
37
+ - **[Delete](/workflow/features/dlq/delete)** – remove the DLQ entry if no action is required.
38
+
39
+ You can apply these actions in bulk to multiple DLQ entries. Check the individual action pages for more details.
@@ -0,0 +1,102 @@
1
+ ---
2
+ title: Workflow Failure Callback Overview
3
+ sidebarTitle: "Overview"
4
+ ---
5
+
6
+ When you define a workflow endpoint, you can attach a failure function to the workflow that allows you to execute custom logic when a workflow run fails after exhausting all retry attempts.
7
+
8
+ This feature ensures that you can perform cleanup operations, logging, alerting, or any other custom error handling logic before the failed workflow run is moved to the Dead Letter Queue (DLQ).
9
+
10
+ <Frame caption="Failure function is executed automatically when worklow run fails">
11
+ <img src="/img/workflow/failure_function.png" alt="Workflow failure function execution" />
12
+ </Frame>
13
+
14
+ The failure function automatically receives the workflow run context and the reason for the failure, so you can decide how to handle it.
15
+
16
+ <CodeGroup>
17
+ ```typescript TypeScript
18
+ import { serve } from "@upstash/workflow/nextjs";
19
+
20
+ export const { POST } = serve<string>(
21
+ async (context) => {
22
+ // Your workflow logic...
23
+ },
24
+ {
25
+ failureFunction: async ({
26
+ context,
27
+ failStatus,
28
+ failResponse,
29
+ failHeaders,
30
+ }) => {
31
+
32
+ // 👇 Log error to monitoring system
33
+ await logToSentry(...);
34
+
35
+ // 👇 Send alert to team
36
+ await sendSlackAlert(...);
37
+
38
+ // 👇 Perform cleanup operations
39
+ await cleanupWorkflowResources(...);
40
+ },
41
+ }
42
+ ```
43
+ );
44
+
45
+ </CodeGroup>
46
+
47
+ You cannot create new workflow steps inside the `failureFunction` using `context`.
48
+ The `context` provided here is only meant to expose workflow run properties (like URL, payload, and headers).
49
+ Think of the failure function as an individual `context.run` step. It executes once with the provided context but cannot define further steps.
50
+
51
+ <Info>
52
+ If you use a custom authorization method to secure your workflow endpoint, add authorization to the `failureFunction` too.
53
+ Otherwise, anyone could invoke your failure function with a request.
54
+
55
+ Read more here: [securing your workflow endpoint](/workflow/howto/security).
56
+ </Info>
57
+
58
+
59
+
60
+
61
+
62
+ ## Parameters
63
+
64
+ The `failureFunction` receives an object with the following parameters:
65
+
66
+ <ParamField body="context" type="object">
67
+ The workflow context object containing:
68
+
69
+ <Expandable>
70
+ <ParamField body="workflowRunId" type="string">
71
+ The ID of the failed workflow run
72
+ </ParamField>
73
+
74
+ <ParamField body="url" type="string">
75
+ The publicly accessible workflow endpoint URL
76
+ </ParamField>
77
+
78
+ <ParamField body="requestPayload" type="string">
79
+ The original request payload that triggered the workflow
80
+ </ParamField>
81
+
82
+ <ParamField body="headers" type="string">
83
+ The original request headers
84
+ </ParamField>
85
+
86
+ <ParamField body="env" type="string">
87
+ Environment variables
88
+ </ParamField>
89
+ </Expandable>
90
+ </ParamField>
91
+
92
+ <ParamField body="failStatus" type="number">
93
+ The HTTP status code returned by the failed workflow step.
94
+ </ParamField>
95
+
96
+ <ParamField body="failResponse" type="number">
97
+ The response body returned by the failed workflow step.
98
+ </ParamField>
99
+
100
+ <ParamField body="failHeaders" type="number">
101
+ The response headers returned by the failed workflow step.
102
+ </ParamField>
@@ -0,0 +1,36 @@
1
+ ---
2
+ title: "Advanced failureUrl Option"
3
+ ---
4
+
5
+ The `failureUrl` is an advanced option that sends failure callback to a different endpoint rather than to the workflow endpoint (failure function).
6
+ This approach is useful for handling failures on separate infrastructure.
7
+
8
+ <Tip>You can use either `failureFunction` or `failureUrl`, but not both. These options are mutually exclusive.</Tip>
9
+
10
+ For most users, **Failure Function** is the better choice because:
11
+ - It runs alongside your workflow and has access to the same context and dependencies
12
+ - Failure function requests are automatically retried on failure as well.
13
+ - You can manually retry failure function if it fails via DLQ.
14
+
15
+ If you think this advanced option fits your need, you can configure it by passing `failureUrl` configuration.
16
+
17
+ <CodeGroup>
18
+ ```typescript
19
+ import { Client } from "@upstash/workflow";
20
+
21
+ const client = new Client({ token: "<QSTASH_TOKEN>" })
22
+
23
+ const { workflowRunId } = await client.trigger({
24
+ url: "https://<YOUR_WORKFLOW_URL>/workflow"
25
+ failureUrl: "https://<YOUR_FAILURE_URL>/workflow-failure"
26
+ })
27
+ ```
28
+
29
+ ```python Python
30
+ @serve.post("/api/example", failure_url="https://<YOUR_FAILURE_URL>/workflow-failure")
31
+ async def example(context: AsyncWorkflowContext[str]) -> None:
32
+ # Your workflow logic...
33
+ pass
34
+ ```
35
+ </CodeGroup>
36
+
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: "Reliability of Failure Function"
3
+ ---
4
+
5
+ The failure function is executed whenever a workflow run fails.
6
+
7
+ In some cases, the failure function itself may throw an error.
8
+ When this happens, it will be retried according to the workflow run's retry configuration.
9
+ If all retry attempts also fail, the failure function execution is marked as failed.
10
+
11
+ You can view and filter workflow runs with failed failure function executions in the DLQ dashboard.
12
+
13
+ <Frame caption="You can filter DLQ entries by failure function state">
14
+ <img src="/img/workflow/failure_callback_state_filter.png" alt="Filter DLQ entries by failure function state" />
15
+ </Frame>
16
+
17
+ From the DLQ dashboard, you can retry the failure function.
18
+
19
+ <Frame caption="You can filter DLQ entries by failure function state">
20
+ <img src="/img/workflow/retry_failure_callback.png" alt="Retry a failed workflow callback" />
21
+ </Frame>
22
+
23
+ You can perform this action programmatically as well:
24
+
25
+ ```ts
26
+ import { Client } from "@upstash/workflow";
27
+
28
+ const client = new Client({ token: "<QSTASH_TOKEN>" });
29
+
30
+ const response = await client.dlq.retryFailureFunction({
31
+ dlqId: "dlq-12345" // The ID of the DLQ message to retry
32
+ });
33
+ ```
@@ -0,0 +1,22 @@
1
+ ---
2
+ title: "Monitor & Manage"
3
+ ---
4
+
5
+ You can monitor wait list size of your flow control key's from the console `FlowControl` tab. The console also allows you to pin, unpin, and reset rate for flow control keys directly.
6
+
7
+ <Frame>
8
+ <img src="/img/qstash/flowcontrol.png" alt="Flow control configuration in the Upstash Console" />
9
+ </Frame>
10
+
11
+ Also you can get the same info using the REST API.
12
+ - [List All Flow Control Keys](/workflow/api-reference/flow-control/list-flow-control-keys).
13
+ - [Single Flow Control Key](/workflow/api-reference/flow-control/get-flow-control-key).
14
+ - [Global Parallelism](/workflow/api-reference/flow-control/get-global-parallelism).
15
+
16
+ ## Manage
17
+
18
+ You can manage flow control keys by pausing/resuming delivery, pinning/unpinning configurations, and resetting rate counts.
19
+
20
+ These operations are available via the SDK, REST API, or directly from the **Flow Control** tab in the [Upstash Console](https://console.upstash.com).
21
+
22
+ Since Upstash Workflow uses QStash under the hood, flow control management is done through the QStash client. See the [QStash Flow Control Management API](/qstash/features/flowcontrol#management-api) for full details and code examples.
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: "Parallelism"
3
+ ---
4
+
5
+ The parallelism limit controls the maximum number of calls that can be executed concurrently.
6
+ Unlike rate limiting (which works per time window), parallelism enforces concurrency control with a token-based system.
7
+
8
+ ```typescript Configure Retry Attempt Count
9
+ import { Client } from "@upstash/workflow";
10
+
11
+ const client = new Client({ token: "<QSTASH_TOKEN>" })
12
+
13
+ const { workflowRunId } = await client.trigger({
14
+ url: "https://<YOUR_WORKFLOW_ENDPOINT>/<YOUR-WORKFLOW-ROUTE>",
15
+ flowControl: {
16
+ key: "user-signup",
17
+ parallelism: 10,
18
+ }
19
+ })
20
+ ```
21
+
22
+
23
+ **Example**:
24
+ If `parallelism = 3`, at most 3 requests can run concurrently.
25
+
26
+ When tokens are available, requests acquire one and start execution:
27
+ <Frame caption="A failing step is automatically retried three times">
28
+ <img src="/img/workflow/parallelism_1.png" alt="Workflow steps within the parallelism limit" />
29
+ </Frame>
30
+
31
+ When all tokens are in use, additional requests are not failed — they’re queued in a **waitlist**:
32
+ <Frame caption="A failing step is automatically retried three times">
33
+ <img src="/img/workflow/parallelism_2.png" alt="Workflow step waiting at the parallelism limit" />
34
+ </Frame>
35
+
36
+ The step in the waitlist will wait for a step to complete and hand off it's token to a pending request:
37
+
38
+ <Tip>
39
+ Token handoff does not guarantee strict ordering.
40
+ A later request in the waitlist may acquire a token before an earlier one.
41
+ </Tip>
42
+
43
+ <Frame caption="A failing step is automatically retried three times">
44
+ <img src="/img/workflow/parallelism_3.png" alt="Workflow step starts when capacity is available" />
45
+ </Frame>
@@ -0,0 +1,46 @@
1
+ ---
2
+ title: "Rate and Period"
3
+ ---
4
+
5
+ The rate specifies the maximum number of requests allowed in a given period (time window).
6
+
7
+ ```typescript Configure Retry Attempt Count
8
+ import { Client } from "@upstash/workflow";
9
+
10
+ const client = new Client({ token: "<QSTASH_TOKEN>" })
11
+
12
+ const { workflowRunId } = await client.trigger({
13
+ url: "https://<YOUR_WORKFLOW_ENDPOINT>/<YOUR-WORKFLOW-ROUTE>",
14
+ flowControl: {
15
+ key: "user-signup",
16
+ rate: 10,
17
+ period: 100,
18
+ }
19
+ })
20
+ ```
21
+
22
+
23
+ **Example**:
24
+ If `rate = 2` and `period = 1 minute`, then **a maximum of 2 steps** can be executed per minute.
25
+
26
+ The first 2 requests within the minute are executed immediately:
27
+
28
+ <Frame caption="Steps are executed within limit">
29
+ <img src="/img/workflow/rate_1.png" alt="Steps are executed within limit" />
30
+ </Frame>
31
+
32
+ The 3rd request in the same minute is not executed immediately:
33
+
34
+ <Frame caption="A new step cannot execute immediately">
35
+ <img src="/img/workflow/rate_2.png" alt="A new step cannot execute immediately" />
36
+ </Frame>
37
+
38
+ Instead of rejecting it, Workflow schedules the request in the next available time window:
39
+
40
+ <Frame caption="The new step is moved to the next time window">
41
+ <img src="/img/workflow/rate_3.png" alt="The new step is moved to the next time window" />
42
+ </Frame>
43
+
44
+ Note that step executions may take longer than the defined period.
45
+ The rate limit only controls how many steps are **started** within each time window,
46
+ it does not limit their execution duration.
@@ -0,0 +1,164 @@
1
+ ---
2
+ title: Workflow Flow Control Overview
3
+ sidebarTitle: "Overview"
4
+ ---
5
+
6
+ Flow Control allows you to limit how many workflow steps are executed by delaying and queuing their delivery.
7
+
8
+ This feature helps to:
9
+ - Manage resource consumption
10
+ - Prevent violations of external API rate limits
11
+ - Ensure workflows run within defined system constraints
12
+
13
+ ## How Flow Control Works
14
+
15
+ When defined limits are exceeded, Flow Control automatically queues and delays step executions instead of rejecting them.
16
+ This guarantees that all steps are eventually processed while staying within configured thresholds.
17
+
18
+ To configure Flow Control, you define a flow control key, a unique identifier used to group related steps under the same rate and parallelism limits.
19
+ The steps that has the same flow control key respect the same constraints.
20
+
21
+ There are two main parameters to configure:
22
+
23
+ - [Rate and Period](/workflow/features/flow-control/rate-period): Maximum number of steps that may start within a time window
24
+ - [Parallelism](/workflow/features/flow-control/parallelism): Maximum number of steps allowed to run concurrently
25
+
26
+ These parameters can be combined for fine‑grained control.
27
+ For example, you can allow up to 10 steps per minute but restrict concurrency
28
+ to 5 steps in parallel, ensuring more predictable load patterns.
29
+
30
+ ## Example
31
+
32
+ Suppose you have the following workflow:
33
+
34
+ ```typescript
35
+ export const { POST } = serve<{ topic: string }>(async (context) => {
36
+ const payload = context.requestPayload
37
+
38
+ await context.run("step-1", () => { ... });
39
+
40
+ await context.run("step-2", () => { ... });
41
+
42
+ await context.run("step-3", () => { ... });
43
+ })
44
+ ```
45
+
46
+ Now imagine you trigger **N workflow runs** for this workflow with the following configuration:
47
+
48
+ ```typescript
49
+ const { workflowRunId } = await client.trigger({
50
+ url: "https://<YOUR_WORKFLOW_ENDPOINT>/<YOUR-WORKFLOW-ROUTE>",
51
+ flowControl: {
52
+ key: "fw_example",
53
+ parallelism: 7,
54
+ rate: 3,
55
+ period: "1m",
56
+ }
57
+ })
58
+ ```
59
+
60
+ Without Flow Control, all workflow runs immediately execute their steps as soon as possible.
61
+ If the workflow calls an external API in a step, this would likely result in ~N concurrent requests being fired in a very short timeframe, potentially overloading services or breaching API limits.
62
+
63
+ <Frame caption="Workflow simplified by step types">
64
+ <img src="/img/workflow/flow_control_ex_3.png" alt="Flow-controlled workflow step types" />
65
+ </Frame>
66
+
67
+ With the configuration above:
68
+ - **Rate:** At most 3 steps per minute can start across all workflow runs.
69
+ - **Parallelism:** At most 7 steps can be running at the same time.
70
+
71
+ Steps that exceed these limits are automatically queued and executed later.
72
+
73
+ <Frame caption="Steps are enqueued for execution">
74
+ <img src="/img/workflow/flow_control_ex_2.png" alt="Workflow steps queued for execution" />
75
+ </Frame>
76
+
77
+ Note that each step above corresponds to a separate workflow run.
78
+ Because this workflow is sequential, each workflow run has only one pending step at a time.
79
+ In workflows with **parallel branches**, multiple steps from the same workflow run may appear in the schedule simultaneously.
80
+
81
+ Parallelism slots are consumed by running steps.
82
+ If no slots are available, new steps enter the **waitlist** until resources free up:
83
+
84
+ <Frame caption="Parallelism waitlist for the flow-control">
85
+ <img src="/img/workflow/flow_control_ex_1.png" alt="Workflow parallelism waitlist" />
86
+ </Frame>
87
+
88
+ ## Step-level Flow Control
89
+
90
+ The flow control configuration of a run applies to all of its steps. To limit a single `context.run` step more
91
+ strictly, pass a flow control configuration as the third argument of `context.run`:
92
+
93
+ ```typescript
94
+ export const { POST } = serve(async (context) => {
95
+ await context.run("prepare", () => { ... });
96
+
97
+ await context.run(
98
+ "charge customer",
99
+ () => chargeCustomer(),
100
+ {
101
+ flowControl: { key: "payment-provider", parallelism: 3 },
102
+ }
103
+ );
104
+
105
+ await context.run("notify", () => { ... });
106
+ });
107
+ ```
108
+
109
+ Only the `charge customer` step is bound by the `payment-provider` key. The other steps keep the configuration
110
+ the run was triggered with. Since the key is shared, at most 3 `charge customer` steps run at the same time
111
+ across all runs using that key, no matter how many runs are active.
112
+
113
+ Following the analogy above, this lets you enforce a parallelism limit on the "green" steps only.
114
+
115
+ The step-level configuration replaces the run's flow control for that step as a whole: a step with its own
116
+ flow control configuration does not also count against the run's flow control key.
117
+
118
+ <Note>
119
+ When the step with flow control is reached right after a `context.run`, `context.sleep` or
120
+ `context.sleepUntil` step, its configuration is attached to the request which delivers it, at no extra cost.
121
+ In other cases (for example, when it is the first step of a run or comes after a `context.call`),
122
+ the SDK publishes an additional hidden request to apply the configuration. This request is not shown in the
123
+ workflow logs.
124
+
125
+ Steps in a parallel group carry their own configuration and never need the extra request.
126
+ </Note>
127
+
128
+ `context.call` and `context.invoke` accept their own flow control configuration too:
129
+
130
+ - [context.call](/workflow/steps/call) – lets you run external HTTP requests under a separate key, so you can throttle third‑party API calls independently of your workflow logic.
131
+ - [context.invoke](/workflow/steps/invoke) – starts a new workflow run with its own flow control configuration.
132
+
133
+ Inside a step, `context.flowControl` returns the flow control configuration applied to the current delivery.
134
+
135
+
136
+ ## Configuration
137
+
138
+ You can configure flow control when starting a workflow run:
139
+
140
+ ```typescript Configure Retry Attempt Count
141
+ import { Client } from "@upstash/workflow";
142
+
143
+ const client = new Client({ token: "<QSTASH_TOKEN>" })
144
+
145
+ const { workflowRunId } = await client.trigger({
146
+ url: "https://<YOUR_WORKFLOW_ENDPOINT>/<YOUR-WORKFLOW-ROUTE>",
147
+ flowControl: {
148
+ key: "user-signup",
149
+ parallelism: 1,
150
+ rate: 10,
151
+ period: 100,
152
+ }
153
+ })
154
+ ```
155
+
156
+ All steps within a workflow run will adhere to the specified flow control configuration.
157
+
158
+ <Warning>
159
+ Keep in mind that rate/period and parallelism info are kept on each step separately.
160
+ If you change the rate/period or parallelism on a new deployment, the old fired ones will not be affected.
161
+ They will keep their flow control configuration.
162
+
163
+ During the period that old steps have not been delivered but there are also steps with new rates, Upstash Workflow will effectively allow the highest rate/period or highest parallelism. Eventually (after the old publishes are delivered), the new rate/period and parallelism will be used.
164
+ </Warning>
@@ -0,0 +1,109 @@
1
+ ---
2
+ title: "Using Serve Many"
3
+ ---
4
+
5
+ Normally, workflows are created with `serve()`, which exposes each workflow as its own HTTP endpoint.
6
+ If workflows were invoked only by their full URL, it would mean:
7
+
8
+ - You'd have to provide the URL explicitly like a trigger request
9
+ - You'd lose type safety for request and response payloads
10
+
11
+ To avoid these issues, Upstash Workflow lets you define workflows as objects and expose them under the same parent path.
12
+ This way, you can invoke a workflow simply by passing the object to `context.invoke`, with full type safety and no URLs required.
13
+
14
+ <Steps>
15
+ <Step title="Create workflow objects">
16
+ Use `createWorkflow()` to define workflows as objects.
17
+
18
+ It works just like `serve()`—accepting the same arguments—but does **not** expose the workflow directly as an HTTP endpoint.
19
+ Instead, it simply initializes a workflow object.
20
+
21
+ ```typescript
22
+ const workflowOne = createWorkflow(
23
+ // 👇 Request Payload Type
24
+ async (context: WorkflowContext<string>) => {
25
+
26
+ await context.sleep("wait 1 second", 1)
27
+
28
+ // 👇 Workflow Response Type
29
+ return { message: "This is the data returned by the workflow" };
30
+ }
31
+ );
32
+
33
+ const workflowTwo = createWorkflow(async (context) => {
34
+ // 👇 Invoke the workflow with type-safe call
35
+ const { body } = await context.invoke(
36
+ "invoke workflowOne",
37
+ {
38
+ workflow: workflowOne,
39
+ body: "user-1"
40
+ }
41
+ ),
42
+ });
43
+ ```
44
+ </Step>
45
+ <Step title="Expose multiple workflows under same endpoint">
46
+ Use `serveMany()` instead of `serve()` to expose multiple workflows on a single catch‑all route.
47
+
48
+ If one workflow is going to invoke another, both must be included in the same `serveMany` definition.
49
+ First step of using `serveMany` is to define a catch-all route.
50
+
51
+ ```typescript app/serve-many/[...any]/route.ts
52
+ export const { POST } = serveMany(
53
+ {
54
+ "workflow-one-route": workflowOne,
55
+ "workflow-two-route": workflowTwo,
56
+ }
57
+ )
58
+ ```
59
+
60
+ <Info>
61
+ In Next.js, a catch‑all route can be defined by creating a `route.ts` file inside a directory named with `[...]`, for example: `app/serve-many/[...any]/route.ts`.
62
+
63
+ For implementations of `serveMany` in other frameworks, you can refer to the projects available in the [`examples` directory of the workflow-js repository](https://github.com/upstash/workflow-js/tree/main/examples).
64
+ </Info>
65
+ </Step>
66
+ <Step title="Invoke by passing workflow object">
67
+ When invoking, pass the workflow object created with `createWorkflow()` (from step 1) as the argument to `context.invoke()`.
68
+ This removes the need to specify a URL explicitly and ensures the call is
69
+ fully type‑safe.
70
+
71
+ ```ts
72
+ const workflowTwo = createWorkflow(async (context) => {
73
+ // 👇 Invoke the workflow with type-safe call
74
+ const { body } = await context.invoke(
75
+ "invoke workflowOne",
76
+ {
77
+ // 👇 Pass the workflow object as argument
78
+ workflow: workflowOne,
79
+ body: "user-1",
80
+ // 👇 optionally label the invoked run; single string or array
81
+ label: ["team-a", "high-priority"],
82
+ }
83
+ ),
84
+ });
85
+ ```
86
+
87
+ </Step>
88
+
89
+ <Step title="Trigger">
90
+ In this example, both `workflowOne` and `workflowTwo` are exposed through `serveMany`, sharing the same parent path.
91
+
92
+ You can start `workflowOne` by sending a trigger request to:
93
+ `https://your-app/serve-many/workflow-one-route`.
94
+
95
+ ```typescript
96
+ import { Client } from "@upstash/workflow";
97
+
98
+ const client = new Client({ token: "<QSTASH_TOKEN>" })
99
+
100
+ const { workflowRunId } = await client.trigger({
101
+ // 👇 URL of workflow one
102
+ url: "https://your-app/serve-many/workflow-one-route"
103
+ })
104
+ ```
105
+
106
+ Route names are inferred from the keys you pass to `serveMany`.
107
+ For example, you can start `workflowTwo` by sending trigger request to: `https://your-app/serve-many/workflow-two-route`.
108
+ </Step>
109
+ </Steps>