Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

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().

UsageDirect link to Usage

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

const result = await start();

ReturnsDirect link to Returns

runId:

string
Unique identifier for tracking this workflow run

start:

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

watch:

(callback: (record: LegacyWorkflowResult) => void) => () => void
Function that accepts a callback function that will be called with each transition of the workflow run

resume:

({stepId: string, context: Record<string, any>}) => Promise<LegacyWorkflowResult>
Function that resumes a workflow run from a given step ID and context

resumeWithEvent:

(eventName: string, data: any) => Promise<LegacyWorkflowResult>
Function that resumes a workflow run from a given event name and data

Error HandlingDirect link to Error Handling

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

try {
const { runId, start, watch, resume, resumeWithEvent } = 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);
}
}

On this page