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 subscribes a decoder for its framework to a conversation's channel, and receives its deliveries:
1
2
3
4
5
6
7
8
9
10
11
import { createClient } from '@ably/pubsub-device';
import { openaiDecoder } from '@ably/ai-transport/openai';
const ably = createClient({ authUrl: '/auth' });
const channel = ably.channels.get('conversations:42');
const decoder = openaiDecoder();
decoder.onEvent(({ event }) => {
if (event !== undefined) render(event);
});
await channel.subscribe(decoder.receive);Entry points
| Entry point | Import path | Contents |
|---|---|---|
| Core | @ably/ai-transport | createAgentAdaptor, createDecoder, defineCodec, ErrorCode, errorInfoIs, makeLogger, consoleLogger, LogLevel, stripUndefined, EventEmitter |
| Vercel | @ably/ai-transport/vercel | vercelAdaptor, vercelDecoder |
| OpenAI | @ably/ai-transport/openai | openaiAdaptor, openaiDecoder |
| AG-UI | @ably/ai-transport/ag-ui | agUiAdaptor, agUiDecoder |
Peer dependencies
Every peer dependency is optional, and you only need the ones matching the code you run and the entry points you import:
| Package | Needed for |
|---|---|
@ably/pubsub-server | Agent code, at version 3. |
@ably/pubsub-device | Client code, at version 3. |
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. |
JavaScript
Core
An agent adaptor publishes to one channel through one codec. The agent sends the prompt and pipes the model's output to it, and the client subscribes a decoder to the channel and can pass history through the same decoder.
Agent adaptor
Create an adaptor, and send and pipe events.
Decoder
Decode each message the channel delivers, live or from history, into events.
Codec
The encode and decode contract an adaptor and a decoder use, and how defineCodec builds a codec from a table of events.
OpenAI
AG-UI
Vercel
Logger
The adaptor and the decoder do not log unless you give them a logger. Create one with makeLogger, and pass it in the logger option of an adaptor factory or a decoder factory.
makeLogger(options: LoggerOptions): Logger| Parameter | Required | Description | Type |
|---|---|---|---|
| options | Required | The handler and the minimum level. |