# Run.streamVNext() (Experimental)
[EN] Source: https://mastra.ai/reference/streaming/workflows/streamVNext

:::caution Experimental Feature
This is an experimental API that may change in future versions. The `streamVNext()` method will eventually replace the current `stream()` method. Use with caution in production environments.
:::

The `.streamVNext()` method enables real-time streaming of responses from a workflow. This enhanced streaming capability will eventually replace the current `stream()` method.

## Usage example

```typescript showLineNumbers copy
const run = await workflow.createRunAsync();

const stream = run.streamVNext({
  inputData: {
    value: "initial data",
  },
});
```

## Parameters

<PropertiesTable
  content={[
    {
      name: "inputData",
      type: "z.infer<TInput>",
      description: "Input data that matches the workflow's input schema",
      isOptional: true,
    },
    {
      name: "runtimeContext",
      type: "RuntimeContext",
      description: "Request Context data to use during workflow execution",
      isOptional: true,
    },
    {
      name: "tracingContext",
      type: "TracingContext",
      isOptional: true,
      description:
        "AI tracing context for creating child spans and adding metadata.",
      properties: [
        {
          parameters: [
            {
              name: "currentSpan",
              type: "AISpan",
              isOptional: true,
              description:
                "Current AI span for creating child spans and adding metadata.",
            },
          ],
        },
      ],
    },
    {
      name: "tracingOptions",
      type: "TracingOptions",
      isOptional: true,
      description: "Options for AI tracing configuration.",
      properties: [
        {
          parameters: [
            {
              name: "metadata",
              type: "Record<string, any>",
              isOptional: true,
              description: "Metadata to add to the root trace span.",
            },
          ],
        },
      ],
    },
    {
      name: "closeOnSuspend",
      type: "boolean",
      description:
        "Whether to close the stream when the workflow is suspended, or to keep the stream open until the workflow is finished (by success or error). Default value is true.",
      isOptional: true,
    },
  ]}
/>

## Returns

<PropertiesTable
  content={[
    {
      name: "stream",
      type: "MastraWorkflowStream<ChunkType>",
      description:
        "A custom stream that extends ReadableStream<ChunkType> with additional workflow-specific properties",
    },
    {
      name: "stream.status",
      type: "Promise<RunStatus>",
      description: "A promise that resolves to the current workflow run status",
    },
    {
      name: "stream.result",
      type: "Promise<WorkflowResult<TState, TOutput, TSteps>>",
      description: "A promise that resolves to the final workflow result",
    },
    {
      name: "stream.usage",
      type: "Promise<{ inputTokens: number; outputTokens: number; totalTokens: number, reasoningTokens?: number, cacheInputTokens?: number }>",
      description: "A promise that resolves to token usage statistics",
    },
    {
      name: "stream.traceId",
      type: "string",
      isOptional: true,
      description:
        "The trace ID associated with this execution when AI tracing is enabled.",
    },
  ]}
/>

## Extended usage example

```typescript showLineNumbers copy
const run = await workflow.createRunAsync();

const stream = run.streamVNext({
  inputData: {
    value: "initial data",
  },
});

const result = await stream.result;
```

## Stream Events

The stream emits various event types during workflow execution. Each event has a `type` field and a `payload` containing relevant data:

- **`workflow-start`**: Workflow execution begins
- **`workflow-step-start`**: A step begins execution
- **`workflow-step-output`**: Custom output from a step
- **`workflow-step-result`**: A step completes with results
- **`workflow-finish`**: Workflow execution completes with usage statistics

## Related

- [Workflows overview](/docs/workflows/overview#running-workflows)
- [Workflow.createRunAsync()](/reference/workflows/workflow-methods/create-run)
- [Run.resumeStreamVNext()](./resumeStreamVNext)


---
title: "Reference: LLM provider API keys (choose one or more) | Templates"
description: "Complete guide to creating, using, and contributing Mastra templates"
---