Call stream() on an agent and loop over the events.
use Laravel\Ai\Streaming\Events\TextDelta;
foreach (agent('You are a helpful assistant.')->stream('Tell me a story.', provider: 'workers-ai') as $event) {
if ($event instanceof TextDelta) {
echo $event->delta;
}
}Reasoning events
A reasoning model sends ReasoningStart, ReasoningDelta and ReasoningEnd events before the text events. All three classes are in Laravel\Ai\Streaming\Events.
Models send reasoning text under different keys. The package reads reasoning_content, reasoning and thinking for you.
Usage on streams
The package asks Cloudflare for usage data on the stream and adds it up across tool-call steps. Cloudflare can send a last usage chunk of all zeros. The package keeps the real figures and ignores that chunk.
Stream and tools
Streaming works with tool calls. The package joins the partial tool-call fragments and gives Laravel AI the complete call. See Tools.
Stream errors
On laravel/ai 0.11 and later, a stream that ends on an error event throws StreamErrorException. On 0.9 and 0.10, the stream ends with no exception. Check for an error event in your loop if you support those versions.
Neuron events on streams
WorkersAiUsageReported fires for streamed calls too, once per model step after the last chunk. See Cost tracking. The StreamEnd event also carries the summed token usage. On laravel/ai 1.x, StreamEnd::$usage is a TextUsage with inputTokens. On 0.9 to 0.11, it is a Usage with promptTokens.