Workflow.createRun()

The .createRun() method initializes a new workflow run instance. It generates a unique run ID for tracking and returns a start function that begins workflow execution when called.

One reason to use .createRun() vs .execute() is to get a unique run ID for tracking, logging, or subscribing via .watch().

Usage

const { runId, start } = workflow.createRun();
 
const result = await start();

Returns

runId:

string
Unique identifier for tracking this workflow run

start:

() => Promise<WorkflowResult>
Function that begins workflow execution when called

Error Handling

The start function may throw validation errors if the workflow configuration is invalid:

try {
  const { runId, start } = workflow.createRun();
  await start({ triggerData: data });
} catch (error) {
  if (error instanceof ValidationError) {
    // Handle validation errors
    console.log(error.type); // 'circular_dependency' | 'no_terminal_path' | 'unreachable_step'
    console.log(error.details);
  }
}