Skip to content

Data streams

Distinguish current UI-message SSE, legacy data streams and plain text before decoding.

Current UI-message SSE

Use the Vercel runtime recipe with DefaultChatTransport. The server returns a UI-message stream response, not just any text/event-stream body. The native SDK owns incremental message assembly, IDs, tool parts and cancellation. OpenAI Agents, Mastra and Pydantic AI have maintained server bridges.

AI SDK v7 is the checked hook path. Older v6/v5 wire compatibility does not establish that every older hook API matches; use the matching upstream migration guide. Plain text uses TextStreamChatTransport.

Legacy v4 data stream

For an existing legacy line-based data-stream endpoint, install assistant-stream@0.3.55. Reuse its decoder and accumulator instead of passing old bytes to a current transport or writing another parser.

legacy-stream.ts

The application supplies a stable assistant message ID for this response, preserves user history and replaces that same assistant record as snapshots arrive. Initiate fetch with the owner's AbortSignal; cancellation, network errors and incomplete streams must reach the host state. Render the canonical message through plain-data views. Preliminary tool results remain data rather than completed execution.

Limits and troubleshooting

The decoder does not provide persistence, replay, authentication or server-side tool execution. The helper rejects a stream with no known terminal outcome;the upstream accumulator can synthesize a complete/unknown status on EOF,which is not evidence of successful generation. Strict mode validates decoded values and sequencing, but the maintained legacy decoder logs and drops malformed serialized lines; it cannot establish complete wire integrity. A later valid finish can still follow a dropped line. Prefer a current protocol for new endpoints and keep transport failures visible. Configure decoder size limits for your application if the defaults do not fit. An endpoint advertised as “data stream” may mean a different generation of the protocol: compare actual bytes and headers first.

For arbitrary agent state carried alongside messages, use Assistant Transport. See assistant-stream source and protocol codecs for exhaustive formats; Ghost adds projection into canonical views, not a competing wire format.