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.

Workflows API

The Workflows API provides methods to interact with and execute automated workflows in Mastra.

Getting All WorkflowsDirect link to Getting All Workflows

Retrieve a list of all available workflows:

const workflows = await mastraClient.listWorkflows();

Working with a Specific WorkflowDirect link to Working with a Specific Workflow

Get an instance of a specific workflow as defined by the const name:

src/mastra/workflows/test-workflow.ts
export const testWorkflow = createWorkflow({
id: "city-workflow",
});
const workflow = mastraClient.getWorkflow("testWorkflow");

Workflow MethodsDirect link to Workflow Methods

Get Workflow DetailsDirect link to Get Workflow Details

Retrieve detailed information about a workflow:

const details = await workflow.details();

Start workflow run asynchronouslyDirect link to Start workflow run asynchronously

Start a workflow run with inputData and await full run results:

const run = await workflow.createRunAsync();

const result = await run.startAsync({
inputData: {
city: "New York",
},
});

Resume Workflow run asynchronouslyDirect link to Resume Workflow run asynchronously

Resume a suspended workflow step and await full run result:

const run = await workflow.createRunAsync();

const result = await run.resumeAsync({
step: "step-id",
resumeData: { key: "value" },
});

Watch WorkflowDirect link to Watch Workflow

Watch workflow transitions:

try {
const workflow = mastraClient.getWorkflow("testWorkflow");

const run = await workflow.createRunAsync();

run.watch((record) => {
console.log(record);
});

const result = await run.start({
inputData: {
city: "New York",
},
});
} catch (e) {
console.error(e);
}

Resume WorkflowDirect link to Resume Workflow

Resume workflow run and watch workflow step transitions:

try {
const workflow = mastraClient.getWorkflow("testWorkflow");

const run = await workflow.createRunAsync({ runId: prevRunId });

run.watch((record) => {
console.log(record);
});

run.resume({
step: "step-id",
resumeData: { key: "value" },
});
} catch (e) {
console.error(e);
}

Stream WorkflowDirect link to Stream Workflow

Stream workflow execution for real-time updates:

try {
const workflow = mastraClient.getWorkflow("testWorkflow");

const run = await workflow.createRunAsync();

const stream = await run.stream({
inputData: {
city: "New York",
},
});

for await (const chunk of stream) {
console.log(JSON.stringify(chunk, null, 2));
}
} catch (e) {
console.error("Workflow error:", e);
}

Get Workflow Run resultDirect link to Get Workflow Run result

Get the result of a workflow run:

try {
const workflow = mastraClient.getWorkflow("testWorkflow");

const run = await workflow.createRunAsync();

// start the workflow run
const startResult = await run.start({
inputData: {
city: "New York",
},
});

const result = await workflow.runExecutionResult(run.runId);

console.log(result);
} catch (e) {
console.error(e);
}

This is useful when dealing with long running workflows. You can use this to poll the result of the workflow run.

Workflow run resultDirect link to Workflow run result

A workflow run result yields the following:

FieldTypeDescription
payload{currentStep?: {id: string, status: string, output?: Record<string, any>, payload?: Record<string, any>}, workflowState: {status: string, steps: Record<string, {status: string, output?: Record<string, any>, payload?: Record<string, any>}>}}The current step and workflow state of the run
eventTimestampDateThe timestamp of the event
runIdstringUnique identifier for this workflow run instance