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.

Usage

const { runId, start } = workflow.createRun({ 
  triggerData: { inputValue: 42 },
  metadata: {
    requestId: "abc-123" 
  }
});
 
const result = await start();

Parameters

config?:

object
Configuration options for the workflow run

config

triggerData?:

Record<string, any>
Initial data passed to trigger the workflow execution

metadata?:

Record<string, any>
Additional metadata to associate with this run

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); 
  }
}

MIT 2025 © Nextra.