Client.Stream delivers a response incrementally. skyl models it as a pull
iterator rather than a channel, and that single choice determines most of what
this chapter covers.
In this chapter
- The four-method
Streaminterface and the loop that goes with it - Why
stream.Err()after the loop is not optional - The four event types, and which providers emit which
- How to drain a stream into one
Responsewhen you do not want events - How cancellation works, and why no stream can leak
- Why a stream that dies halfway is reported rather than hidden
The shape#
stream, err := client.Stream(ctx, req)
if err != nil {
return err
}
defer stream.Close()
for stream.Next() {
if ev := stream.Event(); ev.Type == skyl.EventTextDelta {
fmt.Print(ev.Text)
}
}
return stream.Err()stream, err := client.Stream(ctx, req)
if err != nil {
return err
}
defer stream.Close()
for stream.Next() {
if ev := stream.Event(); ev.Type == skyl.EventTextDelta {
fmt.Print(ev.Text)
}
}
return stream.Err()Read Your First Stream for what each method does and the two lines people forget.
Events#
| Constant | Value | Meaning |
|---|---|---|
EventTextDelta | text_delta | The next fragment of assistant text, in StreamEvent.Text. The event most callers want. |
EventThinkingDelta | thinking_delta | A fragment of the model's reasoning, when the provider discloses it. Only Anthropic ever emits this. |
EventToolCall | tool_call | A completed tool call. skyl buffers partial arguments and emits this once, when the call's JSON is whole — a half-parsed tool call is not actionable. |
EventDone | done | The final event of a successful stream, carrying Usage and StopReason. |
Read Stream Events for which adapters emit which, and why tool calls arrive whole.
Collecting#
resp, err := skyl.CollectStream(stream, "openai", "gpt-5.6")resp, err := skyl.CollectStream(stream, "openai", "gpt-5.6")Read Collecting a Stream for when this is the right tool and what it costs you.
Cancellation#
Read Cancellation and Cleanup for why abandoning a stream is safe, and why Close still matters.
Tool calls#
Read Streaming Tool Calls — skyl reassembles fragmented arguments so you never see half a call.
Truncation#
Read Truncated Streams for the failure that used to look exactly like success.
What’s next?
Start with Your First Stream. If you already stream and are chasing a bug where answers are occasionally cut short, go straight to Truncated Streams.