AI Transport API reference
Reference for every public API in the @ably/ai-transport package. The SDK is split into entry points, so you only import what you need.
This reference covers every public API in the @ably/ai-transport package. The SDK is split into entry points, so you only import what you need.
Quick example
A client creates a transport for a conversation's channel, with a codec for its framework, and subscribes to its deliveries:
1
2
3
4
5
6
7
8
9
10
11
import * as Ably from 'ably';
import { createTransport } from '@ably/ai-transport';
import { openai } from '@ably/ai-transport/openai';
const ably = new Ably.Realtime({ authUrl: '/auth' });
const transport = createTransport({ client: ably, channelName: 'conversations:42', codec: openai });
transport.subscribe(({ event }) => {
if (event !== undefined) render(event);
});Entry points
| Entry point | Import path | Contents |
|---|---|---|
| Core | @ably/ai-transport | createTransport, fromSerial, untilEvent, defineCodec, createDecoderCore, OBJECT_MODES, ErrorCode, errorInfoIs |
| React | @ably/ai-transport/react | TransportProvider, useTransport, useDeliveries, useHistory, useTransportStatus |
| Vercel | @ably/ai-transport/vercel | vercel, createVercelCodec |
| OpenAI | @ably/ai-transport/openai | openai, createOpenAICodec |
| AG-UI | @ably/ai-transport/ag-ui | agui, createAGUICodec |
Peer dependencies
ably is required. The rest are optional, and you only need the ones matching the entry points you import:
| Package | Needed for |
|---|---|
ably | Every entry point. |
ai | The Vercel entry point, with the AI SDK at version 6 or 7. |
openai | The OpenAI entry point, at version 6. |
@ag-ui/core | The AG-UI entry point, at version 1. |
react | The React entry point. |
JavaScript
Transport
A transport publishes to and receives from one channel through one codec. The agent pipes the model's output to it, and the client sends its messages and subscribes to deliveries, with history replayed first when it asks.
Transport
Create a transport, send and pipe events, subscribe with history replay, read history, and handle discontinuities.
Codec
The encode and decode contract a transport uses, and how defineCodec builds a codec from a table of events.
OpenAI
AG-UI
Vercel
React
TransportProvider
Create a transport for a channel and make it available to the components inside it.
useTransport
Read the transport from the nearest or a named provider.
useDeliveries
Receive every delivery on the channel while a component is mounted.
useHistory
Read the channel history one page at a time, oldest first.
useTransportStatus
Observe the transport's discontinuities and errors.