Skip to main content

Signature

Not a promise. You get the iterator back synchronously and consume it with for await.

The events

In order:
Electron is the only SDK with a cancelled terminal event. Elsewhere a cancelled generation simply stops. The SDK never fabricates a successful completed.

Where errors surface

Preflight failures throw from the call: no model available, bad options. A failure during generation arrives as a failed event, so a window can render a retry without a try/catch around the loop.

Streaming into the renderer

Generation usually runs in the utility host while the text belongs on screen. Forward the deltas rather than the whole result:
Sending per token across IPC is fine for text this small, but batching on a timer keeps a busy window smoother.

Cancelling

Break out of the loop. That produces a cancelled terminal event rather than an error.