Skip to content

Interface: StreamResult

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / StreamResult

Defined in: src/types/stream.ts:196

Stream result - an async iterable that also provides the final turn.

Allows consuming streaming events while also awaiting the complete Turn result after streaming finishes. Implements PromiseLike<Turn> for direct awaiting with automatic stream consumption.

import { StreamEventType } from 'upp';
const stream = instance.stream('Tell me a story');
// Option 1: Consume streaming events manually
for await (const event of stream) {
if (event.type === StreamEventType.TextDelta) {
process.stdout.write(event.delta.text ?? '');
}
}
const turn = await stream.turn;
// Option 2: Just await the turn (auto-drains the stream)
const turn = await instance.stream('Tell me a story');
// Option 3: Fire-and-forget with callback
instance.stream('Tell me a story').then(turn => saveToDB(turn));

TData = unknown

Type of the structured output data

readonly turn: Promise<Turn<TData>>

Defined in: src/types/stream.ts:204

Promise that resolves to the complete Turn after streaming finishes. Rejects if the stream is aborted or terminated early.

Accessing turn auto-drains the stream if it has not been iterated yet.

[asyncIterator](): AsyncIterator<StreamEvent, any, any>

Defined in: node_modules/typescript/lib/lib.es2018.asynciterable.d.ts:38

AsyncIterator<StreamEvent, any, any>

AsyncIterable.[asyncIterator]


abort(): void

Defined in: src/types/stream.ts:210

Aborts the stream, stopping further events and cancelling the request. This will cause StreamResult.turn to reject.

void


then<TResult1, TResult2>(onfulfilled?, onrejected?): PromiseLike<TResult1 | TResult2>

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1544

Attaches callbacks for the resolution and/or rejection of the Promise.

TResult1 = Turn<TData>

TResult2 = never

The callback to execute when the Promise is resolved.

(value) => TResult1 | PromiseLike<TResult1> | null

The callback to execute when the Promise is rejected.

(reason) => TResult2 | PromiseLike<TResult2> | null

PromiseLike<TResult1 | TResult2>

A Promise for the completion of which ever callback is executed.

PromiseLike.then