Vercel AI SDK Core
Vercel AI SDK Core orchestrates LLM calls on the server. AI Transport encodes the resulting stream onto an Ably channel, so the same server code reaches every connected client instead of a single HTTP response.
Vercel AI SDK Core is Vercel's library for orchestrating LLM calls. streamText is the main entry point: pass a model, system prompt, and conversation history, and get back a stream of events. The default deployment writes that stream to an HTTP response over Server-Sent Events. AI Transport writes it to an Ably channel instead, so the channel gives you reconnects, multi-device delivery, and replay from your own store.
What the Vercel AI SDK brings
| Feature | Description |
|---|---|
| Provider system | Abstracts model providers (Anthropic, OpenAI, Google) behind a unified interface. Switching models is a one-line change. |
streamText | Calls the model and returns a result object whose stream carries text deltas, tool calls, tool results, reasoning content, and lifecycle events. |
UIMessage model | Messages with role and parts (text, reasoning, tool calls, tool results, files, sources). Each part tracks its own streaming state. |
| Tool calling | Models emit calls to tools you define with a schema and an execute function. The SDK runs the tool and feeds the result back to the model. |
toUIMessageStream | Converts the model's event stream into a stream of UIMessageChunk events. |
readUIMessageStream | Merges a stream of UIMessageChunk events into each fuller state of a UIMessage. |
AI Transport composes with each of these rather than replacing them. It carries the chunk stream over a channel instead of a connection.
What AI Transport adds
Everything below comes from AI Transport rather than the framework.
| Feature | Description |
|---|---|
| Streams that outlive a connection | The response flows through a channel rather than one HTTP response, so a client can reconnect and receive what it missed. |
| Multi-device delivery | Every device subscribed to the conversation receives the same messages in realtime. |
| History and replay | A client that loads the conversation from your store replays the channel from the stored serial, then receives live messages. |
| Token compaction | A client that joins mid-response receives the response's text so far in one delivery, rather than a replay of every token. |
| Requests matched to responses | Headers on send() and pipe() tie each response to the prompt it answers. |
Where they connect
On the server, AI Transport replaces createUIMessageStreamResponse() with pipe(). The response flows to clients through the channel instead of the HTTP body, and the route returns once the pipe resolves:
1
2
3
4
5
6
7
8
9
10
// Agent code.
// Before: the default HTTP transport.
return createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.fullStream }) });
// After: the Ably transport.
const { serial } = await transport.pipe(toUIMessageStream({ stream: result.fullStream }), {
signal: req.signal,
headers: { requestId: message.id },
});
return new Response(null, { status: 204 });On the client, each subscribed client merges the chunks of a response with readUIMessageStream, from the response's start chunk to its finish chunk:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Client code.
import { readUIMessageStream } from 'ai';
let response;
transport.subscribe(({ event }) => {
if (event === undefined || event.type === 'user-message') return;
if (event.type === 'start') {
const stream = new ReadableStream({ start: (controller) => (response = controller) });
(async () => {
for await (const message of readUIMessageStream({ stream })) render(message);
})();
}
response?.enqueue(event);
if (event.type === 'finish') response?.close();
});The integration has three pieces:
- The Vercel codec,
vercelfrom@ably/ai-transport/vercel, encodes the AI SDK'sUIMessageChunkevents as Ably messages, and auser-messageevent for the message the client sends. Each text, reasoning and tool-input stream appends to one message. The codec encodes on the agent and decodes on every client. createTransportwith thevercelcodec creates the transport for the conversation's channel, on the agent and on the client.pipe()reads theUIMessageChunkstream, encodes each chunk, and publishes the resulting messages. Passing the request'ssignalcancels the pipe when the client closes the request.
Pass generateMessageId to toUIMessageStream, so each response has its own message id on its start chunk. Without it, the client merges every response into the same message. The quickstart shows the full agent route and client.
Scope and trade-offs
The Vercel AI SDK focuses on model orchestration and the message model. AI Transport adds continuity across reconnects, multi-device fan-out and stream resumability. You call streamText with the same model, messages and tool definitions. The stream that went to an HTTP response now goes to an Ably channel.
Read next
- Get started with the Vercel AI SDK: build a working chat app.
- Vercel codec API reference: the events the codec encodes and decodes.
- Transport API reference: every method on the transport.