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

FeatureDescription
Provider systemAbstracts model providers (Anthropic, OpenAI, Google) behind a unified interface. Switching models is a one-line change.
streamTextCalls the model and returns a result object whose stream carries text deltas, tool calls, tool results, reasoning content, and lifecycle events.
UIMessage modelMessages with role and parts (text, reasoning, tool calls, tool results, files, sources). Each part tracks its own streaming state.
Tool callingModels 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.
toUIMessageStreamConverts the model's event stream into a stream of UIMessageChunk events.
readUIMessageStreamMerges 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.

FeatureDescription
Streams that outlive a connectionThe response flows through a channel rather than one HTTP response, so a client can reconnect and receive what it missed.
Multi-device deliveryEvery device subscribed to the conversation receives the same messages in realtime.
History and replayA client that loads the conversation from your store replays the channel from the stored serial, then receives live messages.
Token compactionA 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 responsesHeaders 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:

JavaScript

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:

JavaScript

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:

  1. The Vercel codec, vercel from @ably/ai-transport/vercel, encodes the AI SDK's UIMessageChunk events as Ably messages, and a user-message event 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.
  2. createTransport with the vercel codec creates the transport for the conversation's channel, on the agent and on the client.
  3. pipe() reads the UIMessageChunk stream, encodes each chunk, and publishes the resulting messages. Passing the request's signal cancels 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.