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

On React Native, a failure during generation is thrown into the consumer, so the for await loop itself throws. This is the opposite of the Web SDK, where in-flight failures arrive as a failed event. Do not share one error-handling helper between them.

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: