Every tutorial on streaming LLM tokens to a browser eventually reaches for the same stack: Server-Sent Events or a websocket server, usually with a Node sidecar, Pusher or Ably, or Redis pub/sub in front of Laravel Reverb. That is a lot of moving parts to show a reply typing itself out.
In Keel, our paid Laravel 13 starter kit, the AI chat streams tokens with one Livewire component and no realtime infrastructure at all. This post is the whole design, from the shipped code.
The shape of it
ChatBox is a Livewire component. Its send() method calls the AI provider through a generator that yields tokens, pushes each token to the browser as it arrives, and accumulates the full reply server-side:
$this->streamedReply = ''; try { foreach ($ai->streamChat($user, $this->messages, $this->model, $conversation->id) as $token) { $this->streamedReply .= $token; $this->stream(to: 'assistant-stream', content: $token); } } catch (InsufficientCreditsException $e) { $this->addError('prompt', $e->getMessage()); return; } $conversation->messages()->create(['role' => 'assistant', 'content' => $this->streamedReply]); The blade view has a single wire:stream target:
<span wire:stream="assistant-stream">{{ $streamedReply }}</span> $this->stream(to: ...) is Livewire's built-in streaming: the tokens ride the same Livewire request that is already running, and the framework swaps them into the named target as they arrive. No websocket server to provision, no pub/sub topology to debug, no second process to keep alive in production.
The honest tradeoff
One reply equals one long-running HTTP request. We wrote that down in the component itself:
The long-running request is intentional for v1: one request per reply keeps ordering and metering simple.
Ordering is free because one request writes one reply. Metering is free because the charge and the side effects live in one place. The cost is a PHP worker held for the duration of a reply, which is fine at starter-kit scale and the first thing we would revisit with a queue plus Reverb if concurrency ever demanded it. Starting there would have been optimizing a problem nobody had yet.
Metering inside the stream
Because Keel sells AI usage on credits, the stream is wrapped in checks that fail cleanly:
- The balance is checked before anything is persisted, so an empty account never leaves half-finished conversations behind.
-
AiManagerre-checks inside the transaction before charging, so two concurrent replies cannot both pass the first check. - If credits run out mid-stream,
InsufficientCreditsExceptionsurfaces as a validation error on the prompt. The user sees the partial reply and a clear message, not a broken page.
Rate limiting is a separate concern on the same path: AiUsageLimiter runs before the first token, and its exception becomes a normal form error.
What this buys a small team
- No realtime infrastructure in the deploy. Our own demo runs as a plain Render web service and streams tokens with no realtime add-ons.
- One readable file for the whole chat surface: the component is 123 lines including validation, persistence, rate limiting, and metering.
- No second service whose downtime looks like your product being down.
The full component ships in Keel, our paid Laravel 13 starter kit with auth, teams, Paddle/Stripe billing and an admin panel. The live demo shows the streaming chat UI with pre-recorded AI replies: https://keel-s657.onrender.com
If you have run Livewire streaming under real concurrency, we would genuinely like to hear where it bent first.
