Four operations stream their results as server-sent events: generating vocabulary, sending a tutor message, creating a lesson plan and following one. Every library turns the event stream into the language’s own kind of iterator, and hands you each event already decoded into a typed value.
How a stream ends
When the work is done. The iteration stops by itself at the stream’s final event. For a lesson plan, that final event carries the result, so you receive it before the loop ends.
When the API reports an error. An error that arrives inside the stream is raised as an API error, the same type as one that arrives before it.
When the connection fails. A stream that ends before its final event, or that sends nothing at all for 120 seconds, is raised as a transport error.
When you stop. Cancel the call in your language’s usual way, or stop reading, and the connection closes promptly.
Keepalive comments and event types a library does not know yet are skipped, so a newer API never breaks an older library.
Never replayed
A stream that has delivered even one event is never retried by the library, because repeating it could spend your allowance twice. If a lesson plan’s stream breaks after it has started, follow the same plan with streamLessonPlan and the plan_id from its first event.