back to features

SDK Streaming

Structured token-by-token streaming with typed events, dual-mode ResponsePromise, and full-stack bridging from server to React UI - no SSE parsing or manual reconnection.

ChatBotKit's streaming works through a dual-mode ResponsePromise - await it for the full response or call .stream() for an async iterable of typed events. Every event carries a type field (token, message) so you always know what you are handling. No SSE parsing, no delta reassembly, no manual connection management.

Why This Is Better Than the ChatGPT API

OpenAI's streaming requires you to set stream: true, parse raw SSE text, reassemble deltas into messages, handle [DONE] sentinels, and build your own error recovery. ChatBotKit handles all of that internally and gives you structured objects.

  • Dual-mode responses: The same call can be awaited for the full result or streamed event by event. OpenAI forces you to choose upfront and the two code paths look completely different.
  • Typed event objects: Each event is a structured { type, data } object. No parsing data: [DONE] strings or reassembling delta.content fragments.
  • Built-in full-stack bridging: One import bridges the stream from your server to the browser. The Next.js and React SDKs handle SSE encoding, consumption, and re-rendering automatically.
  • Automatic connection management: Reconnection, backpressure, and timeout handling are built in. OpenAI streams drop silently on network interruptions.
  • Message-level events: Beyond tokens, you receive complete message events with metadata, type (bot, reasoning, activity), and IDs - not just raw text fragments.

Key Features

  • ResponsePromise.stream() returns an async iterable of typed events.
  • token events deliver individual text tokens as they are generated.
  • message events deliver complete messages with type, text, metadata, and ID.
  • React hooks consume streams automatically via useConversationManager.
  • Next.js edge streaming via a single stream() wrapper from @chatbotkit/next/edge.
  • Works everywhere - Node.js, Deno, Bun, Cloudflare Workers, Vercel Edge, and browsers.

Getting Started

For full-stack streaming with Next.js and React, add @chatbotkit/next and @chatbotkit/react to bridge the stream from your API route to the browser with zero boilerplate.