Vercel AI SDK Core
Vercel AI SDK Core orchestrates LLM calls on the server. AI Transport encodes the resulting stream onto a durable session, so the same server code reaches every connected client instead of a single HTTP response.
Vercel AI SDK Core is Vercel's server 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 a durable session instead, so you get reconnects, multi-device, and bidirectional control without building them.
What Vercel AI SDK Core 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 stream of UIMessageChunk events: 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 invoke tools you define with a schema and an execute function. The SDK feeds the result back to the model. |
result.toUIMessageStream() | Converts the model's event stream into a ReadableStream of UIMessageChunk events for transport. |
AI Transport composes with each of these rather than replacing them; it is the layer that writes the stream to a session instead of a connection.
What AI Transport adds
| Feature | Description |
|---|---|
| Durable sessions | Tokens flow through a session that outlives any single connection. A client reconnects and resumes from where it left off. |
| Multi-device sync | Every device subscribed to the session sees the same conversation in realtime. |
| Bidirectional control | Cancel, steer, and interrupt the agent from any client. No separate control channel. |
| Active run tracking | view.runs() exposes which clients have runs streaming and which runs are in progress. |
| Conversation branching | Edit and regenerate create forks in the conversation tree rather than destructive replacements. |
| Approval gates that reach the user anywhere | Pending tool approvals persist on the session until someone acts on them. |
| History and replay | Load the full conversation on reconnect, page refresh, or new device join. |
| Token compaction | Reconnecting clients receive accumulated responses rather than a replay of every token. |
Where they connect
On the server, AI Transport replaces createUIMessageStreamResponse() with Run.pipe(). The HTTP response returns immediately; tokens flow to clients through the session instead of the HTTP body:
1
2
3
4
5
6
7
8
9
// Before: default HTTP transport
return createUIMessageStreamResponse({ stream: result.toUIMessageStream() });
// After: Ably transport
const pipeResult = await run.pipe(result.toUIMessageStream());
const outcome = await vercelRunOutcome(pipeResult, result.finishReason);
await run.end(outcome);
return Response.json({ invocationId: run.invocationId });On the agent, a full route:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { after } from 'next/server';
import { streamText, convertToModelMessages } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import * as Ably from 'ably';
import { Invocation } from '@ably/ai-transport';
import { createAgentSession, vercelRunOutcome } from '@ably/ai-transport/vercel';
const ably = new Ably.Realtime({ key: process.env.ABLY_API_KEY });
export async function POST(req) {
const invocation = Invocation.fromJSON(await req.json());
const session = createAgentSession({ client: ably, channelName: invocation.sessionName });
await session.connect();
const run = session.createRun(invocation, {}, { signal: req.signal });
after(async () => {
// Rebuild the conversation from run.view before run.start(): draining pages
// in this run's triggering input (otherwise run.start() awaits it live).
while (run.view.hasOlder()) {
await run.view.loadOlder();
}
const conversation = run.view.getMessages().map(({ message }) => message);
await run.start();
const result = streamText({
model: anthropic('claude-sonnet-4-20250514'),
messages: await convertToModelMessages(conversation),
abortSignal: run.abortSignal,
});
const pipeResult = await run.pipe(result.toUIMessageStream());
const outcome = await vercelRunOutcome(pipeResult, result.finishReason);
if (outcome.reason === 'suspend') {
await run.suspend();
} else {
await run.end(outcome);
}
await session.end();
});
return Response.json({ runId: run.runId, invocationId: run.invocationId });
}The integration has three pieces:
- The Vercel codec (from
createUIMessageCodec()) encodes Vercel'sUIMessageChunkevents as Ably messages. Every chunk type maps to an Ably operation with headers that track the metadata. The codec encodes on the agent and decodes on the client. createAgentSession({ client, channelName })from@ably/ai-transport/vercelconstructs the agent session bound to the channel from the invocation. The default codec is the Vercel codec (createUIMessageCodec()).run.pipe()reads the model'sUIMessageChunkstream, encodes each chunk, and publishes the resulting Ably messages.run.abortSignalwires cancellation through from the client.vercelRunOutcome()then maps the pipe result and Vercel'sfinishReasonto the right lifecycle action: suspend the run when the model requested tools the SDK did not auto-execute, otherwise end it with the matching reason.
Scope and trade-offs
Vercel AI SDK Core is intentionally focused on model orchestration. By design, it does not handle session continuity across reconnects, multi-device fan-out, or stream resumability. AI Transport adds those without changing how you call streamText. The same model and messages, the same tool definitions; the destination of the stream moves from an HTTP response to a durable session.
If you are building the client side, start with Vercel AI SDK UI.
Read next
- Get started with Vercel AI SDK: build a working app.
- Vercel AI SDK UI: the client-side integration that pairs with this page.
- Agent session API reference: every method and property on the agent session.
- Codec API reference: the codec interface that the Vercel codec implements.