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:

OpenAI
Vercel AI SDK
JavaScript

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 pointImport pathContents
Core@ably/ai-transportcreateAgentAdaptor, createDecoder, defineCodec, ErrorCode, errorInfoIs, makeLogger, consoleLogger, LogLevel, stripUndefined, EventEmitter
Vercel@ably/ai-transport/vercelvercelAdaptor, vercelDecoder
OpenAI@ably/ai-transport/openaiopenaiAdaptor, openaiDecoder
AG-UI@ably/ai-transport/ag-uiagUiAdaptor, 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:

PackageNeeded for
@ably/pubsub-serverAgent code, at version 3.
@ably/pubsub-deviceClient code, at version 3.
aiThe Vercel entry point, with the AI SDK at version 6 or 7.
openaiThe OpenAI entry point, at version 6.
@ag-ui/coreThe 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.

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
ParameterRequiredDescriptionType
optionsRequiredThe handler and the minimum level.

Errors