?
InvokeOptions
TypeThe second argument to a method call that turns it into a stream, delivering results as they arrive.
The options that make a call stream. onToken receives accumulated language-model text, so replace your display each time rather than appending, while onStreamData receives the structured progress events a method emits through its own stream. The call still resolves with the method's final value once the stream completes, the same value a non-streaming call returns.
InvokeOptions.ts
interface InvokeOptions { stream?: boolean onToken?: (text: string) => void onStreamData?: (payload: unknown) => void onStreamError?: (error: string) => void }
Fields
stream?
boolean
Set true to receive the response as a stream instead of a single payload. Defaults to false.
onToken?
(text: string) => void
Called as language-model text arrives. The value is the full text so far, not a delta, so replace your display each time rather than appending.
onStreamData?
(payload: unknown) => void
Called for each structured event the method emits through its own stream. Each payload is the raw object, independent of the last.
onStreamError?
(error: string) => void
Called on a stream-level error. If the stream then closes without a result the call rejects; if a result still arrives the call resolves.
Observe a streaming call
const order = await api.processOrder({ id }, { stream: true, onToken: (text) => setText(text), // accumulated text: replace, do not append onStreamData: (event) => setStatus(event), // structured progress from stream({...}) }); // `order` is the same final value a non-streaming call would return