Interface StreamTextResult

The object returned immediately by streamText.

Consumers iterate textStream for raw token deltas or fullStream for all event types; the promise properties settle once that iteration has drained the stream, and awaiting one of them alone starts no request.

interface StreamTextResult {
    grounding?: Promise<undefined | VerifiedResponse>;
    textStream: AsyncIterable<string, any, any>;
    fullStream: AsyncIterable<StreamPart, any, any>;
    text: Promise<string>;
    usage: Promise<TokenUsage>;
    responseModel: Promise<undefined | string>;
    serviceTier: Promise<undefined | string>;
    toolCalls: Promise<ToolCallRecord[]>;
    provider: Promise<string>;
    model: Promise<string>;
    fallback?: Promise<undefined | FallbackSignal>;
    finishReason: Promise<StreamFinishReason>;
    cacheDiagnostics: Promise<null | CacheDiagnostics>;
    providerMessageId: Promise<null | string>;
}

Properties

grounding?: Promise<undefined | VerifiedResponse>

Citation verdicts after text completes, when enabled on a default-runtime session.

textStream: AsyncIterable<string, any, any>

Async iterable that yields only raw text-delta strings (filters out non-text parts).

fullStream: AsyncIterable<StreamPart, any, any>

Async iterable that yields all StreamPart events in order.

text: Promise<string>

Resolves to the assembled assistant reply when the stream completes: the text of the latest step that produced any. A stream that ends mid-step, on an error after output or because the consumer stopped reading, resolves to the text that step delivered.

usage: Promise<TokenUsage>

Resolves to aggregated TokenUsage when the stream completes.

responseModel: Promise<undefined | string>

Provider-reported model id of the final step (may differ from the requested/resolved id across aliases and fallback hops; spec batch-1 C1). Settles on every terminal path — normal completion, fallback, error, early abandonment — and is undefined when no chunk reported a model id. The existing model-related fields keep their meaning.

serviceTier: Promise<undefined | string>

Provider-reported service tier the final step actually ran at (OpenAI; spec batch-1 C2). Settles on every terminal path; undefined when no chunk reported a tier.

toolCalls: Promise<ToolCallRecord[]>

Resolves to the ordered list of ToolCallRecords when the stream completes.

provider: Promise<string>

Resolves to the resolved provider id (e.g. openrouter, anthropic) once the stream has started. Available eagerly because routing happens before the first chunk; exposed as a Promise so the type lines up with the rest of this contract and so callers don't see undefined while the stream is still spinning up. Used by wilds-ai's [llm-call] telemetry line for per-step latency attribution (production fix 2026-05-05: narrator-stream rows were logging provider=unknown model=unknown, which made model-routing audits significantly harder).

model: Promise<string>

Resolves to the resolved model id once the stream has started.

fallback?: Promise<undefined | FallbackSignal>

The failover trail, resolved when the stream ends: fired is true when a fallback leg served or was tried; finalProvider / finalModel name the run that answered; undefined only when the stream ended before routing. Optional in the type, so an object typed as StreamTextResult without it still compiles; streamText always sets it.

finishReason: Promise<StreamFinishReason>

Resolves to the reason the FINAL model step stopped emitting, on the same cadence as usage (when the stream completes):

  • 'stop' — natural end of turn (or an unknown provider vocabulary).
  • 'length' — the provider's output token cap cut the text off; the assembled reply is TRUNCATED mid-thought. Hosts that persist or cache streamed prose as canonical should branch on this before doing so (wilds-ai narrator truncation guard, 2026-07-08).
  • 'tool-calls' — the run ended with outstanding tool calls and no final text (maxSteps exhaustion).
  • 'error' — the stream emitted an error part.

Historically the streaming surface discarded the provider's reason and fabricated 'stop'; the provider layer always had it (final chunk choices[0].finishReason; Anthropic maps max_tokens → length in its adapter). Settled via the generator's cleanup on early abandonment too, so awaiting it after a partial consume does not hang. On a stream the consumer abandoned it does not say why the stream ended: it reports the latest step that finished. The prompt-shim tool-emulation path reports 'stop' (its internal calls do not thread per-step reasons).

cacheDiagnostics: Promise<null | CacheDiagnostics>

Cache-diagnostics verdict of the FINAL step (Anthropic beta; see GenerateTextOptions.cacheDiagnostics). Resolves when the stream completes: null when the run did not opt in, when the provider sent no verdict, or when the compared requests did not diverge; a populated cacheMissReason names the earliest divergence. Settled in the generator's cleanup too, so awaiting after early abandonment never hangs.

providerMessageId: Promise<null | string>

Provider message id (msg_...) of the FINAL step; null when the run did not opt into cache diagnostics or the provider sent no id. Persist it and pass it back as the next request's cacheDiagnostics.previousMessageId to thread the comparison across turns (the wilds-ai narrator threads it per session).