When I started working on streaming in Neuron AI, I thought it was the easy part of the framework. The model produces text, you forward it to the browser, the user watches the answer appear. Done. It took me months, a custom protocol, a TypeScript package, and a long look at a pricing page to admit I was wrong.
This article is the story of that journey and of the tool that came out of it. IQ-Stream is a streaming server that does one job: it carries the tokens generated by a large language model (LLM) from your application backend to your users' browsers in real time, using Server-Sent Events. If a browser loses its connection in the middle of an answer, it gets back every event it missed as soon as it reconnects. Your backend talks to it with plain HTTP requests, so it works with PHP and with any other language.
I'll start from the basics, because many of you are building your first agent right now and not everything here is obvious. If you already know why streaming matters and how it works in PHP, feel free to skip ahead to the section about the limits I found along the way.
What streaming means in an AI application
An LLM doesn't write an answer all at once. It generates text in small pieces called tokens, roughly a word or a part of a word each, one after another. A long answer of a few thousand tokens can take from tens of seconds to more than a minute to complete. If your application waits for the whole thing before showing anything, the user stares at a spinner for that entire time. Streaming means sending each piece to the browser as soon as the model produces it, so the user starts reading immediately.
With agents, there's more than text to stream. An agent can reason before answering, decide to call a tool (a PHP function that queries your database or calls an external API), wait for the result, and then continue writing. Users want to see all of this as it happens, otherwise a thirty second tool call looks like a frozen application. In Neuron AI you switch from a regular call to a streamed one by calling stream() instead of chat(), and you get back a sequence of chunks: TextChunk for pieces of the answer, ReasoningChunk for the model's reasoning, ToolCallChunk when the model asks to run a tool, and ToolResultChunk with the tool's output.
use App\Neuron\MyAgent; use NeuronAI\Chat\Messages\UserMessage; $stream = MyAgent::make() ->setThreadId('chat_id') ->stream(new UserMessage('How are you?')); foreach ($stream as $chunk) { echo $chunk->content; } In a terminal, this works beautifully. The problems begin when there's a browser on the other side.
Why you can't just stream from a controller
The first idea everyone has is to keep the HTTP request open and write the chunks into the response as they arrive. For a short answer that's fine, and Neuron supports it out of the box. But agents are rarely short. An agent that calls a few tools, waits on slow APIs, and writes a long report can easily run for minutes. Along the way it runs into PHP's max_execution_time, the 60 second default timeout of Nginx when it works as a reverse proxy, and whatever limit your load balancer applies to long connections. Any of them can cut the answer in half without telling anyone.
So you do what PHP developers have always done with long-running work: you move it into a queue. A Laravel job, a Symfony Messenger handler, a worker process. The agent now runs safely in the background, but there's a new problem. The worker has no browser attached. It produces tokens, and it has no way to deliver them to the user who asked the question.
To bridge that gap you need a real-time server, something the worker can publish events to and the browser can stay connected to. In the PHP world the usual candidates are Pusher, Laravel Reverb, Soketi, and Mercure. They're mature, widely used tools, and they were the natural choice when I designed streaming channels in Neuron AI 4.
The limits I discovered building Neuron's streaming channels
Channels in Neuron forward the agent's events to an external transport. The agent code stays the same whether it runs in a controller, a queue worker, or a cron job, and if the transport fails, the error goes to your observability tool while the agent keeps working. It looked clean on paper. Then I started testing real agents.
The first one was an agent that reads code repositories. It worked perfectly in the terminal. In a queue worker, streaming through Pusher, the chat stopped in the middle of an answer and never moved again. A tool had returned the content of a file, the event was larger than Pusher's 10 KB limit, and Pusher rejected it silently. The UI kept waiting for something that would never arrive.
That was the first limit: event size. Pusher caps each event at 10 KB, Laravel Reverb uses the same default, and Soketi allows 100 KB. A text token fits easily, but tool calls, tool results, and message snapshots often don't. The second limit was frequency. Managed Mercure plans allow roughly one to twenty publish requests per second, while a model can produce dozens of tokens per second. The third was ordering. Not every server guarantees that events reach the browser in the same order you sent them, and a stream of text tokens in the wrong order is just noise.
To make these systems work, I designed a small protocol inside Neuron. Every event is wrapped in an envelope with a stream identifier, a sequence number, a type, and the payload. When an event is too big for the transport, the channel splits it into consecutive fragments, each one carrying its position and the total number of parts. The channel can group several events into a single request, and it can pace its own sends when the server only accepts a few requests per second. You don't write any of this yourself, you just tell the channel what limits your server has:
use NeuronAI\Agent\Adapter\AgentChunkAdapter; use NeuronAI\Workflow\Streaming\Channel\PusherChannel; use NeuronAI\Workflow\Streaming\Channel\StreamingChannelInterface; use Pusher\Pusher; class MyAgent extends Agent { // ... protected function streamAdapter(): ?StreamAdapterInterface { return new AgentChunkAdapter(); } protected function channel(): StreamingChannelInterface { return new PusherChannel( client: new Pusher(...), channel: 'chat-'.$this->getThreadId(), maxRequestBytes: 10_000, batchSize: 10 ); } } The backend was only half of the story. If the server receives events in fragments and doesn't guarantee their order, someone has to put them back together, and that someone is the browser. So we released @neuron-core/streaming, a TypeScript package that reorders events, joins fragments, discards duplicates, and tells you when something is definitely missing. On the frontend, a Pusher integration looks like this:
import Pusher from 'pusher-js'; import { subscribeToPusher } from '@neuron-core/streaming'; const pusher = new Pusher('YOUR_APP_KEY', { cluster: 'eu' }); const channel = pusher.subscribe(`chat-${threadId}`); channel.bind('pusher:subscription_succeeded', () => { const subscription = subscribeToPusher(channel, { onEvent: ({ streamId, type, data }) => renderEvent(streamId, type, data), onGap: reason => reloadConversation(reason), }); // Now it is safe to ask the backend to start the agent startAgent(threadId, message); }); Notice two details. You have to wait for the subscription to succeed before starting the agent, otherwise the first events are lost because nobody was listening yet. And there's an onGap callback, because when events go missing, the only reliable recovery is to reload the whole conversation from the database and subscribe again. I described the full protocol in my article about the Neuron UI Streaming Protocol, and the configuration of each channel is in the Neuron streaming documentation.
As far as I know, no other agentic framework goes this far. Most of them stop at "here are the chunks" and leave the delivery problem to you.
Tricks that work, until they don't
In Naples we have a name for this kind of solution: l'arte di arrangiarsi, the art of making things work with whatever you have at hand. It's a skill I'm proud of, and Neuron's streaming protocol is a pretty good example of it. But at some point I had to be honest with myself. All of that machinery exists to make tools behave like something they weren't designed to be.
Pusher, Reverb, Soketi, and Mercure were built for a different shape of traffic. A chat message, a notification, a live score update: one small event, delivered to many people, every now and then. An LLM answer is the opposite. It's thousands of tiny events in a dense burst, usually delivered to one or two browsers, that must arrive complete and in order, and that must survive a dropped connection. A phone switching from Wi-Fi to mobile data in the middle of a two minute agent run is normal, not an edge case.
That last point deserves a moment. Pusher, Reverb, Soketi, and Mercure with its default in-memory transport keep no history of the events they relay. If the browser disconnects for three seconds, the tokens sent during those three seconds are gone. Neuron's frontend module detects the gap and reloads the conversation, which is the correct behavior, but it's recovery, not streaming. The user sees the answer stall, disappear, and come back.
Still, these are engineering problems, and engineering problems can be worked around. The one I couldn't work around was on the pricing page.
The limit no protocol can fix: the message count
Hosted real-time services charge by the number of messages, and they count them in a way that makes sense for chat apps and very little sense for AI. Pusher counts every message it receives from your backend plus every message it delivers to a connected browser. Their own pricing page gives the example: publish one message to 50 subscribers and you've used 51.
The Pro plan costs $99 per month and includes 4 million messages per day. It sounds like a lot until you do the math for an agent. Let's assume each token travels as one event, which is close to what many providers send, and that a single browser is watching. A 4,000 token answer costs 4,000 messages to publish and 4,000 more to deliver, so 8,000 messages in total. Divide 4 million by 8,000 and you get 500. That's the daily budget of your entire application: about 500 long answers, shared among all your users. If 50 people ask your agent ten questions each, you're done for the day.
Now look at it from the point of view of peak hours. Twenty users chatting with your agent at the same time, with answers streaming at around 100 tokens per second, generate 2,000 published events and 2,000 deliveries every second. At that rate, the 4 million messages of the day last about 17 minutes.
You can pack several tokens into one event to reduce the number, and Neuron lets you do that with batchSize, but batching divides the count by the size of the batch, and that's all it does. The bill keeps growing with every token your agents produce, and agents are getting more talkative, not less: reasoning models think out loud before answering, and every tool call streams its arguments piece by piece. Even the largest self-serve Pusher plan, 90 million messages per day for $1,199 per month, covers around 11,000 answers of that size. For a chat app these plans are generous. For an AI product they're a ceiling you reach as soon as real users show up.
That's when I stopped asking how to make the existing tools fit, and started asking what a server designed only for this job would look like.
What IQ-Stream is, and what it isn't
IQ-Stream is the answer I came up with. It's a streaming server built for a single use case: relaying LLM output from your backend to your users' browsers in real time, without losing events.
The interesting part is what it leaves out. It has no topics, channels, presence, or permanent message history. It doesn't need a database, Redis, a disk, or a message broker. It ships as a single Docker image for both amd64 and arm64. It keeps each answer in memory only while the model is writing it, so any browser that reconnects can catch up, and it lets the answer go as soon as it's finished. Your database stays the source of truth for the conversation, exactly as it is in Neuron, where the chat history is the reference and the live stream is a convenience layer on top of it.
It doesn't parse your events either. Whatever format you send, it relays unchanged: AG-UI (an open protocol for agent user interfaces), the data stream format of the Vercel AI SDK, plain text, or your own custom format. And since it sits after the model, it doesn't care which LLM you use, hosted or self-hosted.
A quick introduction to Server-Sent Events
IQ-Stream delivers events to the browser using Server-Sent Events (SSE). If you've never used them, they're worth knowing, because they're much simpler than they sound.
SSE is a standard part of the web platform. The browser opens a regular HTTP connection, and instead of receiving one response and closing it, it keeps the connection open while the server writes events into it, one after another. Every modern browser has a built-in object for this called EventSource, so you don't need any library. Communication goes in one direction only, from the server to the browser, which happens to be exactly the direction tokens travel. WebSockets, the technology behind Pusher and Reverb, are bidirectional, more powerful, and also more complicated, and you need a client library to use them.
SSE also has a feature that fits LLM streaming perfectly. When the connection drops, EventSource reconnects automatically and tells the server the identifier of the last event it received, using the Last-Event-ID header defined by the standard. A server that remembers recent events can pick up exactly from there. Most servers don't remember. IQ-Stream does.
How IQ-Stream works from the developer's point of view
The flow has a few steps, and you'll recognize most of them from what you already do with queues.
When a user sends a question, your backend starts the agent, usually by dispatching a job, and signs two short-lived tokens with a few lines of code. One token allows publishing the events of that answer, the other allows watching it. They're separate on purpose: the watch token goes to the browser, and it can't be used to publish anything.
While the agent runs, your backend sends each chunk to IQ-Stream with a plain HTTP request, one JSON line per event. There's no persistent connection to manage on the backend, and a client library is a convenience rather than a requirement, which means it works the same way from PHP, Python, Node.js, Go, Ruby, Java, .NET, or anything else that can make an HTTP call. IQ-Stream holds the events of the running answer in memory.
The browser opens the stream with the watch URL, using the EventSource object it already has:
// standard Server-Sent Events. No SDK. const stream = new EventSource(watchUrl); stream.onmessage = (event) => render(event.data); Compare this with the Pusher snippet above. There's no subscription handshake to wait for before starting the agent, because the running answer is held in memory and a browser that connects a moment late can still catch up. There's no fragment reassembly and no reordering, because every viewer receives the same events, in the same order, exactly once. There's no gap handler that reloads the conversation, because when the connection drops, the browser reconnects, IQ-Stream replays what was missed, and the answer keeps flowing without holes or duplicates.
When the answer ends, every browser receives a final signal saying whether it completed or failed, and why. A browser that shows up after the end is told immediately, so it can load the final result from your backend instead of waiting for a stream that already closed. Then IQ-Stream releases the answer from memory.
A few details seem minor until you run this in production. IQ-Stream sends regular heartbeats, so proxies and load balancers don't close the connection while your agent waits thirty seconds for a slow tool. Each browser is paced independently, so a user on a weak mobile connection doesn't slow down other viewers and isn't disconnected for being slow. And the event size limit is sized for agent traffic, from 32 KiB per event on the free plan up to 128 KiB on larger plans, so most tool results fit in a single event and there's nothing to stitch back together in the browser.
For Neuron users there's one more point. Since IQ-Stream doesn't interpret your events, the output of the AG-UI and Vercel AI adapters you already use in Neuron can travel through it exactly as it is.
Built-in support in Neuron AI
If you use Neuron, you don't have to write the publishing code yourself. Neuron AI has a built-in IQStreamChannel, a streaming channel like the Pusher one I showed you earlier, that forwards the agent's events to IQ-Stream. It relies on the official PHP client, so install that first:
composer require neuron-core/iq-stream-php The client reads the server address and your app's credentials from the IQ_STREAM_URL, IQ_STREAM_APP_KEY, and IQ_STREAM_APP_SECRET environment variables. In the request that starts the chat, you create a ticket for a new stream, start the agent in a background job with the stream's id, and return the ticket to the browser:
use IQStream\IQClient; $iq = IQClient::fromEnvironment(); // A new stream, and the ticket the browser subscribes with $ticket = $iq->ticket(); // The background job that runs the agent and publishes to the stream dispatch(new RunAgentJob($threadId, $message, $ticket->streamId->value)); // Return the ticket for the browser to connect return $ticket; Inside the job, with the client resolved from your container, you attach a stream adapter and the IQ-Stream channel to the agent, and run it in streaming mode:
use App\Neuron\MyAgent; use IQStream\IQClient; use NeuronAI\Agent\Adapters\AGUIAdapter; use NeuronAI\Chat\Messages\UserMessage; use NeuronAI\Workflow\Streaming\Channel\IQStreamChannel; class RunAgentJob { public function __construct( protected string $threadId, protected string $message, protected string $streamId, ) {} public function handle(IQClient $iq): void { MyAgent::make() ->setThreadId($this->threadId) ->setStreamAdapter(fn () => new AGUIAdapter($this->threadId)) ->setChannel(fn () => new IQStreamChannel($iq, $this->streamId)) ->chat(new UserMessage($this->message), stream: true); } } Compare it with the PusherChannel configuration above: the channel takes only the client and the stream id, with no request size or batch size to set. It keeps a single request open for the whole answer, continues on a new one if the server closes it while a slow tool runs, and resends whatever a dropped connection didn't deliver. I used the AG-UI adapter here, but any Neuron stream adapter works the same way.
In the browser, pass the ticket's URL to subscribeToIQ, from the same @neuron-core/streaming package, which unwraps Neuron's envelopes and gives you the agent's events:
import { subscribeToIQ } from '@neuron-core/streaming'; const subscription = subscribeToIQ(ticket.url, { onEvent: ({ type, data }) => renderEvent(type, data), onGap: reason => reloadConversation(reason), }); A dropped connection never reaches onGap, because the browser resumes it by itself and IQ-Stream replays what was missed. The callback only fires when the stream itself breaks, for example if the backend stops publishing in the middle of an answer. The complete setup is in the IQ-Stream section of the Neuron documentation.
Performance and reliability numbers
Since I built IQ-Stream after months spent fighting the limits of other servers, I wanted numbers, not impressions. We benchmarked it against Mercure, Laravel Reverb, and Soketi, each one in its fastest documented configuration, on AWS Graviton4 machines. The workload simulated realistic agent runs: a streamed text answer, a tool call with streamed arguments, a pause of a second and a half, an 8 KB tool result, and a second answer, for a total of 429 events in about ten seconds per run. One browser in ten dropped its connection in the middle of the answer, because that's what happens in real life. A server passed a load level only if at least 99% of events arrived with a p99 latency under 250 milliseconds, meaning 99 out of 100 events reached the browser within a quarter of a second.
On a single virtual CPU core, IQ-Stream moved about 27,700 events per second, roughly 40 microseconds of CPU per event with TLS included. On two cores it reached 46,554 events per second, about 3.6 times Mercure's peak and 14 times Laravel Reverb's on the same hardware. Reverb and Soketi had to send every event through Redis to scale across processes, while IQ-Stream keeps each answer on a single worker, so tokens go straight from your backend to the browser without crossing processes or passing through a broker.
The number I care about most is a different one. At 1,100 concurrent runs, 647 browsers lost their connection and reconnected, and none of them missed a single event. With Mercure and Soketi, which keep no history, each reconnecting browser lost about 51 of the 429 events in its run. Mercure can keep history if you enable its Bolt transport, but it writes every event to disk before relaying it, and in our tests it never went above 463 events per second.
On the memory side, IQ-Stream sizes itself from the container's memory limit and refuses new work before running out. A 2 GB container holds about 1,400 complete answers of 4,000 tokens in flight.
These are our numbers, measured by us, and the full methodology is on the performance page. If you reproduce the test and get different results, I want to hear about it.
How pricing works
This whole story started on a pricing page, so it's fair to close the loop. IQ-Stream never caps the number of messages. Plans are defined by how many answers can stream at the same moment, plus a monthly amount of data transfer, because concurrent streams are what actually consume server resources. How many tokens each answer contains doesn't change the count.
There's a free plan with five concurrent streams, enough to connect it to your agent and see how it behaves with your own traffic. All the details are on the pricing page.
When you don't need IQ-Stream
I'd rather you use the right tool than mine, so let me be clear about this. If your agent answers quickly and runs inside the HTTP request, streaming directly from your controller with SSE is perfectly fine, and Neuron supports it natively. If you're experimenting, or you already run Mercure or Reverb with a handful of users, Neuron's channels and the frontend module will serve you well. And IQ-Stream isn't a general replacement for Pusher or Reverb: if you need presence, notifications, or chat between users, those tools are still the right choice.
IQ-Stream makes sense when your agents run in the background, real users start depending on them, and you begin to see answers cut in half on mobile connections, events too big for your transport, or a message quota running out before lunch.
Frequently asked questions
What is IQ-Stream?
IQ-Stream is a streaming server designed to relay LLM tokens from an application backend to users' browsers in real time. The backend publishes events with plain HTTP requests, and browsers receive them through Server-Sent Events. If a browser disconnects, it receives every missed event when it reconnects.
Do I need Neuron AI to use IQ-Stream?
No. IQ-Stream works with any backend language that can make an HTTP request, including PHP, Python, Node.js, Go, Ruby, Java, and .NET. Neuron AI is where the problem showed up for me, but the server doesn't depend on it.
Are there client libraries for IQ-Stream?
Yes. In PHP, Neuron AI integrates with IQ-Stream. For Python and JavaScript there are official client libraries on GitHub: iq-stream-python and iq-stream-js. For any other language, the HTTP interface is small enough to call directly with the HTTP client you already use.
What happens if the user's connection drops during an answer?
The browser's EventSource reconnects automatically and tells IQ-Stream which event it received last. IQ-Stream replays the events that were missed and then continues live, with no gaps and no duplicates. If the answer finished while the browser was offline, the browser is told right away so it can load the final result from your backend.
Does IQ-Stream store my conversations?
No. It keeps an answer in memory only while the model is generating it, then releases it. Your own database remains the source of truth for the conversation history.
Can I use IQ-Stream with Laravel or Symfony?
Yes. The typical setup is to run the agent in a Laravel job or a Symfony Messenger handler, publish each chunk to IQ-Stream over HTTP, and let the browser read the stream with EventSource.
Does it work with OpenAI, Anthropic, Gemini, or local models?
Yes. IQ-Stream sits after the model and relays events without parsing them, so it works with any hosted or self-hosted LLM and with any event format, including AG-UI and the Vercel AI SDK data stream.
Wrapping up
Streaming is the moment where your agent meets the person using it, and it's the part users judge first. I spent months teaching general-purpose real-time servers to carry something they weren't built for, and I learned a lot doing it. Neuron's channels are still there and they still work. But for agents in production I wanted a piece of infrastructure that treats an LLM answer for what it is: a long, dense, fragile sequence of events that has to arrive complete, in order, even when the connection doesn't cooperate.
You can find IQ-Stream at iq-stream.dev and create a free account at app.iq-stream.dev. If you try it with your Neuron agents, I'd love to know how it goes. And if you hit a limit I didn't think of, tell me. That's exactly how this whole thing started.