Skip to main content
context.invoke() triggers another workflow run and pauses until the invoked workflow finishes. The calling workflow resumes once the invoked workflow either succeeds, fails, or is canceled.
Workflows can only invoke other workflows that were served together in the same serveMany route. For details, see Invoke other workflows.

Arguments

workflow
function
required
The workflow definition to invoke. Must be a workflow exposed under the same serveMany.
body
any
The payload to send to the invoked workflow. This value will be set as context.requestPayload in the invoked workflow.
headers
object
Optional HTTP headers to forward to the invoked workflow. This value will be set as context.headers in the invoked workflow.
workflowRunId
string
Override the workflow run ID for the invoked workflow. Defaults to a new ID if not specified.
retries
number
Number of retry attempts configuration of the invoked workflow. Defaults to 3. Retries use exponential backoff.
retryDelay
number|string
Delay between retries of the invoked workflow.
flowControl
object
Flow control configuration of the invoked workflow.See Flow Control for details.
stringifyBody
string
Whether to automatically stringify the body as JSON. Defaults to trueIf set to false, the body will be required to be a string and will be sent as-is.

Response

body
any
The response body returned by the invoked workflow.
isFailed
boolean
true if the invoked workflow completed with failure.
isCanceled
boolean
true if the invoked workflow was canceled before completion.

Usage

const { body, isFailed, isCanceled } = await context.invoke(
  "invoke another workflow",
  {
    workflow: anotherWorkflow,
    body: "test",
    header: {...}, // headers to pass to anotherWorkflow (optional)
    retries,       // number of retries (optional, default: 3)
    retryDelay,    // delay between retries (optional, uses exponential backoff by default)
    flowControl,   // flow control settings (optional)
    workflowRunId  // workflowRunId to set (optional)
  }
);