Anthropic vs OpenAI Streaming: What Changes in Your Parser
Explore how to handle streaming responses from Anthropic and OpenAI in your parser by normalizing provider-specific events into a common internal format. Learn to keep your UI state consistent by separating parsing logic from reducer logic and verifying event conformity before deployment. This lesson helps you maintain reliable incremental rendering for AI model outputs despite differing stream structures.
We'll cover the following...
Everything up to here assumed OpenAI’s event shape. That’s the one assumption left worth testing. A browser UI that renders streaming text does not care which provider produced it. The UI wants a small, typed sequence that drives one reducer the stream yields text fragments to append; one signal means stop, and one path reports errors. The swap that breaks code is almost always upstream of the reducer, because providers serialize different event shapes on the wire.
So keep the invariant where it belongs. The reducer consumes your internal event types and updates state the same way every time, while the parsing layer is the only place that is allowed to know raw provider event names and where deltas live.