Streams
Stream methods live on world.streams (the streams sub-object of the World instance returned by await getWorld()). Use them to write chunks, read streams, and manage stream lifecycle outside of the standard getWritable() pattern.
For most streaming use cases, use getWritable() inside steps. Direct stream methods are for advanced scenarios like building custom stream consumers or managing streams from outside a workflow.
Import
Methods
write()
Write a data chunk to a named stream.
Parameters:
| Parameter | Type | Description |
|---|---|---|
runId | string | The workflow run ID |
name | string | The stream name |
chunk | string | Uint8Array | Data to write |
writeMulti()
Write multiple chunks in a single operation. Optional optimization: not all World implementations support it. Falls back to sequential write() calls if unavailable.
Parameters:
| Parameter | Type | Description |
|---|---|---|
runId | string | The workflow run ID |
name | string | The stream name |
chunks | (string | Uint8Array)[] | Chunks to write, in order |
get()
Read data from a named stream as a live ReadableStream that waits for new chunks in real time.
Parameters:
| Parameter | Type | Description |
|---|---|---|
runId | string | The workflow run ID |
name | string | The stream name |
startIndex | number | Optional. Positive values skip chunks from the start (0-based). Negative values read from the tail (e.g. -3 starts 3 chunks from the end). Clamped to 0. |
Returns: ReadableStream<Uint8Array>
close()
Close a stream when done writing.
Parameters:
| Parameter | Type | Description |
|---|---|---|
runId | string | The workflow run ID |
name | string | The stream name |
list()
List all stream names associated with a workflow run.
Parameters:
| Parameter | Type | Description |
|---|---|---|
runId | string | The workflow run ID |
Returns: string[]
getChunks()
Fetch stream chunks with cursor-based pagination. Unlike get() (which returns a live ReadableStream), this returns a snapshot of currently available chunks.
Parameters:
| Parameter | Type | Description |
|---|---|---|
runId | string | The workflow run ID |
name | string | The stream name |
options.limit | number | Max chunks per page (default: 100, max: 1000) |
options.cursor | string | Cursor from a previous response |
Returns: StreamChunksResponse
| Field | Type | Description |
|---|---|---|
data | StreamChunk[] | Chunks in index order. Each has index (0-based) and data (Uint8Array). |
cursor | string | null | Cursor for the next page |
hasMore | boolean | Whether more pages of already-written chunks exist |
done | boolean | Whether the stream is fully closed. When false, new chunks may appear in future requests even after hasMore is false. |
getInfo()
Retrieve lightweight metadata about a stream without fetching chunks.
Parameters:
| Parameter | Type | Description |
|---|---|---|
runId | string | The workflow run ID |
name | string | The stream name |
Returns: StreamInfoResponse
| Field | Type | Description |
|---|---|---|
tailIndex | number | Index of the last known chunk (0-based). -1 when no chunks have been written. |
done | boolean | Whether the stream is fully complete (closed). |
Examples
Read a stream as a response
Paginate through stream chunks
Related
- Streaming: Core concepts for streaming data from workflows
getWritable(): The standard way to write to streams from within steps- Storage: Query runs, steps, hooks, and events