Skip to Content
ReferenceWorkflowsReference: Workflow.streamVNext() | Streaming | Workflows | Mastra Docs

streamVNext()

The streamVNext() method enables real-time streaming of responses from a workflow.

Usage

const run = await myWorkflow.createRunAsync(); // Add a stream to monitor execution const stream = run.streamVNext({ inputData: {...} }); for (const chunk of stream) { // do something with the chunk }

Protocol

start:

object
The workflow starts
object

example:

{ type: 'start', runId: '1', from: 'WORKFLOW', payload: { runId: '1' } }
Example message structure

step-start:

object
The start of a step
object

example:

{ type: 'step-start', runId: '1', from: 'WORKFLOW', payload: { id: 'fetch-weather' } }
Example message structure

step-output:

object
Custom output from a step
object

example:

{ type: 'step-output', runId: '1', from: 'WORKFLOW', payload: { stepName: 'my step', args: { ... }, stepCallId: 'uuid', startedAt: 1717000000000, status: 'running' } }
Example message structure

step-result:

object
The result of a step
object

example:

{ type: 'step-result', runId: '1', from: 'WORKFLOW', payload: { stepName: 'my step', result: { ... }, stepCallId: 'uuid', endedAt: 1717000000000, status: 'success', output: [Object] } }
Example message structure

finish:

object
The end of the workflow
object

example:

{ type: 'finish', runId: '1', from: 'WORKFLOW', payload: { totalUsage: { promptTokens: 100, completionTokens: 100, totalTokens: 200 } } }
Example message structure

Returns

PropertiesTable for Return Values

usage?:

Promise<object>
Total usage of the workflow, including sub agents/workflows as a step.
number

promptTokens?:

number
The number of prompt tokens used by the agent.
number

completionTokens?:

number
The number of completion tokens used by the agent.
number

totalTokens?:

number
The total number of tokens used by the agent.

status?:

Promise<string>
The status of the workflow run.

result?:

Promise<object>
The result of the workflow run.

Examples

Basic Streaming

const run = await myWorkflow.createRunAsync(); const stream = run.streamVNext({ inputData: {...} }); for await (const chunk of stream) { process.stdout.write(chunk); }

Structured Output Streaming

const run = await myWorkflow.createRunAsync(); const stream = run.streamVNext({ inputData: {...} }); const result = await stream.result; console.log("Final structured result:", result);