Running Workflows
Workflows can be run from different environments. These examples demonstrate how to execute a workflow using a command line script or by calling the Mastra Client SDK from a client-side component.
From Mastra Client
In this example, a client-side request is made using the Mastra Client SDK. The inputData
matches the inputSchema
for the sequentialSteps example.
import { mastraClient } from "../../lib/mastra-client";
export const TestWorkflow = () => {
async function handleClick() {
const workflow = await mastraClient.getWorkflow("sequentialSteps");
const run = await workflow.createRunAsync();
const result = await workflow.startAsync({
runId: run.runId,
inputData: {
value: 10
}
});
console.log(JSON.stringify(result, null, 2));
}
return <button onClick={handleClick}>Test Workflow</button>;
};
See Mastra Client SDK for more information.
From the command line
In this example, a run script has been added to the src
directory. The inputData
matches the inputSchema
for the sequentialSteps example.
import { mastra } from "./mastra";
const run = await mastra.getWorkflow("sequentialSteps").createRunAsync();
const result = await run.start({
inputData: {
value: 10,
},
});
console.log(result);
Run the script
Run the workflow using the following command:
npx tsx src/test-run-workflow.ts
From curl
You can run a workflow by sending a POST
request to your Mastra application’s /start-async
endpoint. Include inputData
that matches the workflow’s inputSchema
.
curl -X POST http://localhost:4111/api/workflows/sequentialSteps/start-async \
-H "Content-Type: application/json" \
-d '{
"inputData": {
"value": 10
}
}' | jq
Example output
The output from this workflow run will look similar to the below:
{
"status": "success",
"steps": {
"input": {
"value": 10
},
"step-1": {
"payload": {
"value": 10
},
"startedAt": 1756823641918,
"status": "success",
"output": {
"value": 10
},
"endedAt": 1756823641918
},
"step-2": {
"payload": {
"value": 10
},
"startedAt": 1756823641918,
"status": "success",
"output": {
"value": 10
},
"endedAt": 1756823641918
}
},
"result": {
"value": 10
}
}