Workflows SDK for TypeScript
Usage and symbol reference
The Render SDK for TypeScript provides support for:
- Defining tasks and flows in your workflow service
- Running functions as steps inside a flow
- Chaining additional task runs from within a task function
- Triggering and managing runs from TypeScript code outside the workflow
Install
From your TypeScript project directory:
(Or pnpm install, bun add, etc.)
If you already have the SDK installed, make sure you're using version 1.7.0 or later:
After installing, make sure @renderinc/sdk is listed as a dependency in your package.json file at version ^1.7.0 or later.
Defining tasks
The following symbols pertain to creating and registering tasks in your workflow service. For usage guidance, see Defining Tasks.
task(options, func)
Use task() to register a provided function (func) as a workflow task with the specified options.
On success: Returns a task definition. You can pass this value to ctx.run() to chain runs of this task within another task.
| Parameter | Description | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Function parameters | ||||||||||||||||||||||
|
Required. An object containing configuration details for the task. Only | |||||||||||||||||||||
|
Required. The function to register as a task. | |||||||||||||||||||||
|
Supported | ||||||||||||||||||||||
|
Required. The task's name. This affects the task's slug, which you use to reference the task when triggering runs. Use a name that is unique across all tasks and flows in the workflow. This value is not required to match the name of the function you provide as | |||||||||||||||||||||
|
An object containing retry settings for the task. See all supported settings below. If you omit this field, Render applies default task retry behavior. | |||||||||||||||||||||
|
The timeout for each execution attempt, in seconds. Must be between 30 seconds ( The default value is 2 hours. | |||||||||||||||||||||
|
The default compute plan to use for the task's runs. One of the following:
The default value is Providing | |||||||||||||||||||||
|
Retry settings | ||||||||||||||||||||||
|
Required if you provide The total number of attempts is up to | |||||||||||||||||||||
|
Required if you provide | |||||||||||||||||||||
|
The exponential backoff factor. After each retry, the previous delay is multiplied by this factor. For example, a factor of If you omit this field, the default value is | |||||||||||||||||||||
The TaskContext object
Every task function must accept a TaskContext object as its first positional argument. Render automatically provides this object to each run (you do not provide it as an input).
TaskContext.run(task, ...args)
Chains a run of the specified task on a separate instance.
On success: Returns a Promise that resolves with the chained run's return value.
Throws: RenderError, Error
It can also propagate ordinary errors if it cannot communicate with the task runtime.
| Parameter | Description |
|---|---|
|
Required. The |
|
All input arguments to pass to the task run, as positional arguments: |
TaskContext.metadata
An object containing identifiers for the current task run and its execution chain.
Added in SDK v1.2.0.
| Property | Description |
|---|---|
|
The ID of this task run. |
|
The ID of the root-level task run for this run's execution chain. If this run is the root-level run, this value is the same as |
|
The ID of the task run that chained this run. This value is |
Defining flows
The following symbols pertain to creating and registering flows in your workflow service. For usage guidance, see Defining Flows.
flow(options, func)
Use flow() to register a provided function (func) as a flow with the specified options.
On success: Returns a flow definition.
| Parameter | Description | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Function parameters | ||||||||||||||||||||||
|
Required. An object containing configuration details for the flow. Only | |||||||||||||||||||||
|
Required. The function to register as a flow. | |||||||||||||||||||||
|
Supported | ||||||||||||||||||||||
|
Required. The flow's name. This affects the flow's slug, which you use to reference the flow when triggering runs. Use a name that is unique across all tasks and flows in the workflow. This value is not required to match the name of the function you provide as | |||||||||||||||||||||
|
The timeout for each execution attempt, in seconds. Must be between 30 seconds ( The default value is 2 hours. | |||||||||||||||||||||
|
The default compute plan to use for the flow's runs. One of the following:
The default value is Providing | |||||||||||||||||||||
The FlowContext object
Every flow function receives a FlowContext as its first positional argument. Render provides this object automatically.
For usage guidance, see Configuring step behavior.
FlowContext.step(name, fn, args, options?)
Runs a plain function as a step inside the flow's process.
On success: Returns a Promise that resolves with the function's return value.
Throws: StepError, DeterminismError, FlowFailedError, WorkflowLimitError, RenderError
| Parameter | Description |
|---|---|
|
Function parameters | |
|
Required. The step's name. This value is not required to match the name of the function you provide as |
|
Required. The function to execute as a step. The function can return either a value or a Promise. The function's arguments and return value must be JSON-serializable. You must pass a plain function. You cannot pass a definition returned by |
|
Required if the function takes arguments. An array of positional argument values to pass to For functions that take zero arguments, you can omit this array or provide |
|
Optional configuration details for the step. See all supported options below. |
|
Supported | |
|
An object containing retry settings for this step. See all supported options below. If a step's return value fails JSON serialization, the step fails without retrying. If all attempts fail, If you omit this field, the step is attempted once. |
|
Retry settings | |
|
Required if you provide |
|
Required if you provide |
|
The multiplier applied to The default value is |
FlowContext.metadata
An object containing the current flow run's ID.
| Property | Description |
|---|---|
|
The ID of this flow run. Has the format |
Triggering runs
These methods and types are related to triggering and managing runs of tasks and flows from any TypeScript code outside the workflow itself (web apps, scripts, and so on).
For full usage guidance, see Triggering Task Runs.
The Render class
The Render class provides client methods for triggering and managing task runs and flow runs. Initialize a Render object to call the Task methods and Flow methods.
Constructor
Render(options)
Initializes a Render SDK client.
| Option | Description |
|---|---|
|
The API key to use for authentication. If omitted, the client automatically detects and uses the value of the |
Task methods
These methods are available on the workflows attribute of a Render object.
startTask(taskSlug, inputData, options?)
Kicks off a run of the registered task with the specified identifier, passing the specified arguments.
To instead run a task and wait for it to complete, use workflows.runTask.
On success: Returns a TaskRunResult object representing the started run. You can await the run's result by calling .get() on this object.
Throws: ClientError, ServerError, AbortError
| Parameter | Description |
|---|---|
|
Function parameters | |
|
Required. The slug indicating the task to run, available from your task's page in the Render Dashboard:
Always has the format |
|
Required. An array containing the task's input arguments. Elements are positional based on the task's function signature. For a task that takes zero arguments, provide an empty array, |
|
An object containing configuration options for the task run. All fields are optional. See all supported options below. |
|
Supported | |
|
An optional string used to prevent duplicate task runs. Added in SDK v1.2.0. For details, see Idempotency keys. |
|
An optional Canceling the client-side operation does not cancel the task run on Render. See Canceling operations with |
runTask(taskSlug, inputData, options?)
Starts the registered task with the specified identifier, waits for it to complete, and returns the result.
To instead kick off a run without waiting for it to complete, use workflows.startTask.
On success: Returns a TaskRunDetails object for the finished task run. A failed or canceled run is returned with its terminal status; the SDK does not throw a TaskRunError for that status.
Throws: ClientError, ServerError, AbortError, Error
| Parameter | Description |
|---|---|
|
Function parameters | |
|
Required. The slug indicating the task to run, available from your task's page in the Render Dashboard:
Always has the format |
|
Required. An array containing the task's input arguments. Elements are positional based on the task's function signature. For a task that takes zero arguments, provide an empty array, |
|
An object containing configuration options for the task run. All fields are optional. See all supported options below. |
|
Supported | |
|
An optional string used to prevent duplicate task runs. Added in SDK v1.2.0. For details, see Idempotency keys. |
|
An optional Canceling the client-side operation does not cancel the task run on Render. See Canceling operations with |
listTaskRuns(params)
Lists task runs that match optional filters.
On success: Returns an array of TaskRunWithCursor objects.
Throws: ClientError, ServerError
Supported fields on params include:
| Parameter | Description |
|---|---|
|
An integer specifying the maximum number of task runs to return. |
|
A cursor string for pagination. Use this to retrieve the next page of results. |
|
A list of task slugs to filter results by. Only task runs for these tasks are returned. |
|
A list of root task run IDs to filter results by. Only runs in these execution chains are returned. |
|
A list of workspace IDs to filter results by. Only task runs from these workspaces are returned. |
|
A list of workflow version IDs to filter results by. |
|
A list of workflow IDs to filter results by. |
getTaskRun(taskRunId)
Retrieves the details of the task run with the specified ID.
On success: Returns a TaskRunDetails object.
Throws: ClientError, ServerError
| Parameter | Description |
|---|---|
|
Required. The ID of the task run to retrieve. Has the format |
cancelTaskRun(taskRunId)
Cancels the root-level task run with the specified ID, along with all of its chained runs. This throws a ClientError if the root-level run is not found.
Runs that have already finished are left unchanged.
On success: Returns void.
Throws: ClientError, ServerError
| Parameter | Description |
|---|---|
|
Required. The ID of the root-level task run to cancel. Has the format |
taskRunEvents(taskRunIds, signal?, options?)
Streams completion events for one or more task runs via Server-Sent Events (SSE).
Returns an async iterator that yields a TaskRunDetails object each time a specified task run reaches a terminal status.
As shown below, break out of the iterator loop after receiving events for all requested runs. The iterator does not automatically finish when all runs complete.
Throws: AbortError, Error
| Parameter | Description |
|---|---|
|
Required. A list of task run IDs to stream events for. Each ID has the format |
|
Optional For details, see Canceling operations with |
|
Optional reconnection settings for stream connection failures. See all supported options below. |
|
Supported | |
|
The maximum number of reconnection attempts after a stream connection failure. The default value is |
|
The base delay before attempting the first reconnection, in milliseconds. The default value is |
|
The exponential backoff factor. After each reconnection attempt, the previous delay is multiplied by this factor, up to For example, a factor of The default value is |
|
The maximum delay between reconnection attempts, in milliseconds. The default value is |
Flow methods
These methods are available on the workflows attribute of a Render object.
startFlow(flowSlug, inputData, options?)
Kicks off a run of the registered flow with the specified identifier, passing the specified arguments.
To instead run a flow and wait for it to complete, use workflows.runFlow.
On success: Returns a FlowRun object representing the started run.
Throws: ClientError, ServerError, AbortError
| Parameter | Description |
|---|---|
|
Function parameters | |
|
Required. The slug indicating the flow to run, available from your flow's page in the Render Dashboard. Has the format |
|
Required. An array containing the flow's input arguments. Elements are positional based on the flow's function signature. For a flow that takes zero arguments, provide an empty array, |
|
An object containing configuration options for the flow run. All fields are optional. See all supported options below. |
|
Supported | |
|
An optional string used to prevent duplicate flow runs. For details, see Idempotency keys. |
|
An optional Canceling the client-side operation does not cancel the flow run on Render. See Canceling operations with |
runFlow(flowSlug, inputData, options?)
Starts the registered flow with the specified identifier, waits for it to complete, and returns the result.
To instead kick off a run without waiting for it to complete, use workflows.startFlow.
On success: Returns a FlowRunDetails object for the finished flow run. A failed or canceled run is returned with its terminal status; the SDK does not throw an error for that status.
Throws: ClientError, ServerError, AbortError, TypeError
| Parameter | Description |
|---|---|
|
Function parameters | |
|
Required. The slug indicating the flow to run, available from your flow's page in the Render Dashboard. Has the format |
|
Required. An array containing the flow's input arguments. Elements are positional based on the flow's function signature. For a flow that takes zero arguments, provide an empty array, |
|
An object containing configuration options for the flow run. All fields are optional. See all supported options below. |
|
Supported | |
|
An optional string used to prevent duplicate flow runs. For details, see Idempotency keys. |
|
An optional Canceling the client-side operation does not cancel the flow run on Render. See Canceling operations with |
listFlowRuns(params?, signal?)
Lists flow runs that match optional filters.
On success: Returns an array of FlowRunWithCursor objects.
Throws: ClientError, ServerError, AbortError
| Parameter | Description |
|---|---|
|
Function parameters | |
|
An object containing filters and pagination settings. All fields are optional. See all supported fields below. |
|
An optional |
|
Supported | |
|
An integer specifying the maximum number of flow runs to return. |
|
A cursor string for pagination. Use this to retrieve the next page of results. |
|
A list of flow slugs to filter results by. Only flow runs for these flows are returned. |
|
A list of flow definition IDs to filter results by. |
|
A list of flow run status values to filter results by. |
|
A list of workspace IDs to filter results by. Only flow runs from these workspaces are returned. |
|
A list of workflow version IDs to filter results by. |
|
A list of workflow IDs to filter results by. |
getFlowRun(flowRunId, signal?)
Retrieves the details of the flow run with the specified ID.
On success: Returns a FlowRunDetails object.
Throws: ClientError, ServerError, AbortError
| Parameter | Description |
|---|---|
|
Required. The ID of the flow run to retrieve. Has the format |
|
An optional |
cancelFlowRun(flowRunId, signal?)
Cancels the flow run with the specified ID.
On success: Returns void.
Throws: ClientError, ServerError, AbortError
| Parameter | Description |
|---|---|
|
Required. The ID of the flow run to cancel. Has the format |
|
An optional |
Task types
TaskAttempt
Represents one execution attempt of a particular task run. Returned in a TaskRun object's attempts array.
Each run's initial attempt has "attempt number" 0. If an attempt fails and the run retries, each retry creates a new attempt with an incremented number.
| Property | Description |
|---|---|
|
The ID of the task run this attempt belongs to. |
|
The zero-based "attempt number": |
|
The current status of this attempt, as a string. For possible values, see Run status. |
TaskAttemptDetails
Provides the full details of an individual attempt. Returned in the TaskRunDetails.attempts array.
Includes all of the same properties as a TaskAttempt object, plus:
| Property | Description |
|---|---|
|
The error message if the attempt failed. Otherwise, this value is the empty string. |
|
An array containing the attempt's return value, if it completed successfully. Otherwise, |
TaskRun
Summarizes the state of a task run. Obtained in one of the following ways:
- The
taskRunproperty of aTaskRunWithCursorreturned byworkflows.listTaskRuns
To get a run's full details including results, call workflows.getTaskRun with the run's ID to obtain a TaskRunDetails object.
| Property | Description |
|---|---|
|
The ID of the task run. Has the format |
|
The ID of the run's associated task. Has the format |
|
The current status of the task run, as a string. See Run status for possible values. |
|
The timestamp when the task run was first created and queued for execution. |
|
The timestamp when the task run finished (successfully or otherwise). Present only if |
|
The ID of this run's parent run, if this run was chained. For a root-level run, this value is the empty string. |
|
The "attempt number" of the parent task run that chained this run. If chained from the parent run's initial attempt, this value is This field is not present for root-level runs. |
|
The ID of the root task run in this run's execution chain. For a root-level run, this value matches |
|
The number of times the task run has retried so far. For a newly started run, this is typically |
|
An array of |
TaskRunDetails
Provides the full details of a task run. Obtained in one of the following ways:
-
Calling the
workflows.runTaskmethod: -
Calling
.get()on aTaskRunResultreturned byworkflows.startTask: -
Calling the
workflows.getTaskRunmethod: -
Iterating over events from the
workflows.taskRunEventsmethod
Includes all of the same properties as a TaskRun object, plus:
| Property | Description |
|---|---|
|
An array containing the task's return value(s). This value is |
|
The argument values that were passed to the task run, in one of the following formats:
The format matches whichever format the task input was originally provided in. |
|
The error message if the task run failed. Present only if |
|
An array of |
TaskRunResult
Represents a started task run before its completion.
You typically obtain a TaskRunResult from workflows.startTask, which kicks off a task run without waiting for it to finish.
| Member | Description |
|---|---|
|
The started task run's ID, available immediately. |
|
Waits for completion and returns a Subsequent calls to |
TaskRunWithCursor
Represents an item returned by workflows.listTaskRuns. It pairs a task run with the cursor for that item.
| Property | Description |
|---|---|
|
The |
|
The cursor associated with this item. Provide it as |
Flow types
FlowRun
Summarizes the state of a flow run. Obtained in one of the following ways:
- Calling the
workflows.startFlowmethod - The
flowRunproperty of aFlowRunWithCursorreturned byworkflows.listFlowRuns
To get a run's full details including results, call workflows.getFlowRun with the run's ID to obtain a FlowRunDetails object.
| Property | Description |
|---|---|
|
The ID of the flow run. Has the format |
|
The ID of the run's associated flow. Has the format |
|
The current status of the flow run, as a string. See Flow run status for possible values. |
|
The timestamp when the flow run was first created and queued for execution. |
|
The timestamp when the flow run finished (successfully or otherwise). Present only if |
FlowRunDetails
Provides the full details of a flow run. Obtained in one of the following ways:
-
Calling the
workflows.runFlowmethod: -
Calling the
workflows.getFlowRunmethod:
Includes all of the same properties as a FlowRun object, plus:
| Property | Description |
|---|---|
|
An array containing the flow's return value(s). This value is an empty array unless |
|
The argument values that were passed to the flow run, in one of the following formats:
The format matches whichever format the flow input was originally provided in. |
|
The error message if the flow run failed. Present only if |
|
Details for a determinism or limit error. See fields below. |
|
An array of objects representing each individual execution attempt for this run. See all supported fields below. |
|
| |
|
The zero-based "attempt number": |
|
The current status of this attempt, as a string. For possible values, see Flow run status. |
|
The timestamp when the attempt started executing. |
|
The timestamp when the attempt finished (successfully or otherwise). Present only if |
|
The error message if the attempt failed. Otherwise, this field is not present. |
|
| |
|
The error code: |
|
A description of the failure. |
|
The zero-based sequence number of the step that caused the determinism error. |
|
The zero-based "attempt number" associated with the determinism error. |
|
For determinism errors: |
|
Descriptions of the recorded and attempted calls for a determinism error. |
|
The applicable limit and the value that exceeded it. |
FlowRunStatus
The string enum for a flow run's status, with one of the following values.
A successful flow run has status succeeded (task runs use completed). The terminal statuses are succeeded, failed, and canceled.
| Value | Description |
|---|---|
|
The run has been queued but has not yet started executing. |
|
The run is currently executing. |
|
The run finished successfully. |
|
The run finished with an error. |
|
The run was canceled before it finished. |
FlowRunWithCursor
Represents an item returned by workflows.listFlowRuns. It pairs a flow run with the cursor for that item.
| Property | Description |
|---|---|
|
The |
|
The cursor associated with this item. Provide it as |
Run status
The status field on TaskRun, TaskRunDetails, TaskAttempt, and TaskAttemptDetails is a string with one of the following values.
The exact meaning of each value differs for a task attempt and a task run, as shown:
| Value | Task attempt | Task run |
|---|---|---|
|
The attempt has been queued but has not yet started executing. |
The run's current attempt is |
|
The attempt is currently executing. |
The run's current attempt is |
|
The attempt is waiting for the result of a chained run. |
The run's current attempt is |
|
The attempt finished successfully. |
The run finished successfully. |
|
The attempt finished with an error. |
All of the run's attempts have finished with an error and no retries remain. |
|
The run was canceled before this attempt finished. |
The run was canceled before it finished. |
Canceling operations with AbortSignal
The startTask, runTask, startFlow, and runFlow methods accept a signal field in their options object. The other flow client methods accept a signal as their final parameter. taskRunEvents accepts an AbortSignal as its second parameter. Use a signal to stop a method call that is no longer needed, such as a request that exceeds a frontend timeout.
When a signal is passed to startTask, it applies to both the initial HTTP request and any subsequent wait via TaskRunResult.get(). This means a single AbortController can cancel the full lifecycle of starting a task and waiting for its result.
Terminating a client-side method call does not cancel the corresponding run. Runs continue executing on Render until they complete, time out, or are canceled with workflows.cancelTaskRun or workflows.cancelFlowRun.
Error types
The Render SDK defines the custom error types below. In certain cases, the SDK also throws native JavaScript errors, such as errors from network requests or event streams.
Client and task errors
RenderError extends Error
The base class for ClientError and ServerError.
Also raised in the following cases:
- The client is missing an API token.
- A call to
ctx.run()references an unregistered task. - A chained task run fails.
- Flow registration includes a retry policy, or a step call has invalid parameters.
ClientError extends RenderError
Raised when a request to the Render API returns a 400-level error code.
Common causes include:
- Invalid API key
- Invalid task or flow identifier
- Invalid task or flow arguments
- Invalid action (for example, starting a run on a suspended workflow service)
ServerError extends RenderError
Raised when a request to the Render API returns a 500-level error code.
AbortError extends Error
Raised when an SDK operation is canceled with an AbortSignal.
Flow execution errors
These errors are raised during flow execution, such as during a call to ctx.step().
Import these errors from @renderinc/sdk/workflows.
StepError extends Error
Raised when all attempts of a step fail. If uncaught, this error fails the flow run.
For retry guidance, see Retry settings.
| Property | Description |
|---|---|
|
The original error message. |
|
The original error's name, such as |
|
Additional fields from the original error, when they can be serialized. |
DeterminismError extends RenderError
Raised when a step call does not match the recorded history during replay. This fails the flow run even if flow code catches the error.
When available, the details object contains the following:
| Property | Description |
|---|---|
|
The zero-based sequence number of the step that caused the determinism error. |
|
The zero-based "attempt number" associated with the recorded step. |
|
How the replay differs from the recorded history:
|
|
A description of the call recorded in the step history. |
|
A description of the call made during replay. |
FlowFailedError extends RenderError
Raised when the flow cannot continue, such as when a step operation is rejected. The flow run fails even if flow code catches the error.
WorkflowLimitError extends FlowFailedError
Raised when a step operation exceeds a workflow limit. The flow run fails even if flow code catches the error.
The reason identifies the limit. The limit and value properties are included when supplied by the runtime.
