Task stream
A task’s answer as it is written, read piece by piece or all at once.
A task’s answer as the model writes it, from run() with stream: true. Read it with for await, or call text() or done() to wait for the whole answer.
interface TaskStream extends AsyncIterable<TaskChunk> {
readonly requestId: string | undefined
readonly processedIn: string | undefined
text(): Promise<string>
done(): Promise<TaskDone>
}
interface TaskChunk {
text: string
}
interface TaskDone {
text: string
json: unknown
stopReason: StopReason
usage: TaskUsage
}Fields and methods
for awaitTaskChunkEach piece of the answer as it arrives, in
text. A reasoning model’s reasoning is left out.text()Promise<string>Reads the rest of the stream and gives the whole answer.
done()Promise<TaskDone>Reads the rest of the stream and gives the whole answer with
json,stopReason, andusage, as in a task reply. After afor awaitloop, it gives them straight away.requestIdstring or undefinedThe request’s ID, for support.
processedInstring or undefinedThe country the model ran in.
A stream can be read once. A second for await fails with stream_consumed; keep the text as you read it, or call done().
When the run fails after the answer started, reading fails with the service’s code, such as model_unavailable. A stream cut off before the end fails with stream_interrupted.
Last updated