Workflow.createRun()
The .createRun() method creates a new workflow run instance, allowing you to execute the workflow with specific input data. This is the current API that returns a Run instance.
Usage exampleDirect link to Usage example
await workflow.createRun();
ParametersDirect link to Parameters
runId?:
string
Optional custom identifier for the workflow run
resourceId?:
string
Optional identifier to associate the workflow run with a specific resource (e.g., user ID, tenant ID). This value is persisted with the workflow run and can be used for filtering and querying runs.
disableScorers?:
boolean
Optional flag to disable scorers for this workflow run
ReturnsDirect link to Returns
run:
Run
A new workflow run instance that can be used to execute the workflow
Extended usage exampleDirect link to Extended usage example
const workflow = mastra.getWorkflow("workflow");
const run = await workflow.createRun();
const result = await run.start({
inputData: {
value: 10,
},
});
Using resourceIdDirect link to Using resourceId
The resourceId parameter associates a workflow run with a specific resource, such as a user or tenant. This is useful for multi-tenant applications or when you need to track which user initiated a workflow.
const workflow = mastra.getWorkflow("workflow");
// Create a run associated with a specific user
const run = await workflow.createRun({
resourceId: "user-123",
});
const result = await run.start({
inputData: {
value: 10,
},
});
// Later, retrieve the run and access the resourceId
const storedRun = await workflow.getWorkflowRunById(run.runId);
console.log(storedRun.resourceId); // "user-123"