Vercel AI SDK
Use @durable-streams/aisdk-transport to make Vercel AI SDK useChat generations durable and resumable and shareable across tabs, devices, users and agents.
This is the integration to use when you want a chat generation to survive refreshes and reconnect cleanly to the same stream. It plugs into the AI SDK's transport layer, so you can keep the normal useChat flow while swapping in a durable transport.
Install
pnpm add @durable-streams/aisdk-transportClient
Swap the default transport for createDurableChatTransport, following the same transport model documented in the AI SDK transport docs:
import { useChat } from "@ai-sdk/react"
import { createDurableChatTransport } from "@durable-streams/aisdk-transport"
const transport = createDurableChatTransport({ api: "/api/chat" })
const chat = useChat({ transport, resume: true })Server
Wrap the AI SDK UI message stream with toDurableStreamResponse:
import { toDurableStreamResponse } from "@durable-streams/aisdk-transport"
return toDurableStreamResponse({
source: result.toUIMessageStream(),
stream: {
writeUrl: buildWriteStreamUrl(streamPath),
readUrl: buildReadProxyUrl(request, streamPath),
headers: DURABLE_STREAMS_WRITE_HEADERS,
},
})The server writes AI SDK chunks into Durable Streams and returns the read URL through Location and { streamUrl }.
Resume flow
For refresh-safe generations:
- Persist the active stream id for the chat while generation is in progress.
- Add a reconnect endpoint such as
GET /api/chat/:id/stream. - Return
204when there is no active generation, or200plusLocationand{ streamUrl }when there is one. - Enable
resume: trueinuseChat.
Example
See the working example in: