Migrate from the streaming APIs
How to migrate from the streaming APIs to durable sessions.
Migrating from the streaming APIs to durable sessions swaps one factory on the client and one on the agent. The channel stays, the run and step structure stays, and the SDK takes over maintaining the conversation.
What is replaced
Five things change:
| What you had | What replaces it |
|---|---|
createClientTransport | createClientSession |
subscribe plus your own merge of chunks into messages | session.view, or useView in React |
| your database stores the conversation | Ably channel history |
| your hydration endpoint | the SDK's client hydration |
WireCodec | the full Codec, with a reducer |
On the agent, createAgentTransport becomes createAgentSession, and the context you assembled from your own store comes from run.view instead.
The last row is the one to budget for. On top of the encode and decode a wire codec has, a full codec adds a reducer that merges events into a per-message projection, and a getMessages that returns the messages in that projection to the tree. The shipped Vercel and OpenAI codecs already have both, so this row is written for you there. If you wrote your own, expect the branching rules to reach into the reducer.
What does not change
- The Ably channel, and the channel name your conversations live on.
- The channel rule that allows token appends.
- Authentication, the token endpoint, and your capability scoping.
- The run and step structure, including the supersede rule for a retried step.
- Cancellation, including your agent's
onCancelauthorisation. - Steering, and the agent loop driven by
hasInput(). - Waking the agent. That POST is still yours to make.
A conversation that was streaming before the swap is still readable after it. The streaming APIs and durable sessions write the same wire protocol, so the messages already on the channel decode into the tree without a migration.
Conversation history moves to the channel
Your existing conversation store stops being the source of truth. The channel becomes the conversation storage for the period configured by your retention window, and your store becomes the archive behind it. Your read path inverts to match: you load and render the conversation from the view.
Database hydration covers integrating durable sessions with your own database storage, including the metadata you need to store to make this work.
Read next
- Durable sessions: what you get for the swap.
- Database hydration: joining the channel to the store you already have.
- Conversation tree: the structure the SDK builds for you.
- Get started with Vercel useChat: the same app, on the other side of the swap.