Streaming
Stream RAG responses token-by-token with Server-Sent Events. Includes React hook and Next.js integration.
Coming Soon -- Streaming for query and chat endpoints (.stream(), .streamMessage()) is not available in the V1 release. Use /v1/memories/search and the .search() SDK method for retrieval-based search. Streaming RAG responses will be available in a future release.
Stream query and chat responses in real-time using Server-Sent Events (SSE). The API sends tokens as they're generated, so your users see answers appear immediately.
SSE protocol
The stream endpoint returns a standard SSE stream with typed events:
Event types
| Event | Payload | Description |
|---|---|---|
text | { content: string } | A chunk of the generated answer |
sources | Source[] | Retrieved sources used for the answer |
usage | { tokens_used: number } | Token usage for this request |
done | {} | Stream complete |
error | { message: string } | An error occurred |
Stream a query
Stream a chat message
Chat streaming works the same way — the response arrives token-by-token with full conversation context:
React hook
A reusable useMemoryStream hook for React apps. Handles SSE parsing, state management, and error handling.
Usage in a component
Next.js server proxy
Never expose your API key in client-side code. Use a server proxy to keep it secure.
Create a Route Handler that proxies the SSE stream:
app/api/stream/route.ts
The useMemoryStream hook above uses /api/stream by default, so it works with this proxy out of the box.
Chat component
A complete chat UI with message history and streaming:
Error handling
Add retry logic for production reliability: