Stream Object

Streaming Structured Data Real-time

Stream structured objects progressively as they're generated. Watch your UI update in real-time as each field arrives - perfect for complex data that takes time to generate.

Streaming vs. Waiting

With generateObject, users wait for the complete response. With streamObject, they see data appearing progressively - names first, then messages, creating a much more responsive experience.

Demo

Server Endpoint

Use streamObject instead of generateObject. The key difference is toTextStreamResponse() which streams chunks to the client.

+server.ts

Client Component

Use the ReadableStream API to manually read chunks and parse partial JSON as it arrives. This gives you full control over the streaming experience.

+page.svelte