Skip to main content

Signature

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

The events

started, then token deltas, then completed.

Where errors surface

Updating React state

Setting state on every token re-renders on every token. For long outputs, accumulate and flush on an interval:

Cancelling

Break out of the loop. Track unmount so you do not set state on a gone component: