Errors

The ErrorInfo type that every AI Transport failure path surfaces, the numeric codes you match against, and the patterns for handling errors on the client and the agent.

Every rejected promise and every error passed to a decoder's onError handler carries an ErrorInfo object. The same type covers AI Transport-specific failures, Ably platform errors (auth, channel attach, rate limits), and underlying network errors. Match against a specific code with the errorInfoIs utility.

ErrorInfo

The ErrorInfo type is exported from @ably/pubsub-server and @ably/pubsub-device. AI Transport surfaces it as the rejection reason on every promise that can fail, as the argument to every onError handler on a decoder, and as the error that ends a chat transport stream.

Properties

codeNumber
Ably error code. Match against this with errorInfoIs to identify a specific failure.
messageString
Human-readable description of the error.
statusCodeNumber
HTTP-equivalent status code for the error.
causeErrorInfo or Undefined
The underlying cause of the error, when applicable.
detailRecord<string, string> or Undefined
Structured metadata associated with the error.

AI Transport error codes

General errors

CodeNameHTTP statusDescriptionRecovery
40003InvalidArgument400An argument was invalid. For example, a header value that is not a string, number, boolean or null, or an event that send() cannot publish because the codec encodes it as an append or an update. The chat transport's sendMessages() rejects with this error if the transport cannot build a request from the headers, body, or messages that useChat passes.Check the argument against the API reference for the method.
40033OperationCancelled400The operation was cancelled. A pipe's abort signal fired. A cancelled pipe finishes the messages it has written before it rejects. With the chat transport, this error has the name AbortError, so useChat treats it as a stop. A chat transport stream ends with it if useChat stops the stream or the transport closes, or if a later call reads the channel again after a long disconnection left the response open. sendMessages() and reconnectToStream() reject with it if useChat stops them before they return a stream, and sendMessages() also rejects with it if the transport closes first.Expected after a deliberate cancel. Treat it as a normal outcome rather than a failure to retry.
40160InsufficientCapability401The Ably channel rejected a publish through send() with a 401 or 403 status, for example because the token does not permit it.Inspect the cause. Add the publish capability for the channel to the token.
50000InternalError500The SDK or the Ably service behaved in a way the SDK cannot explain, for example a publish that succeeded but returned no serial. The chat transport's sendMessages() and reconnectToStream() reject with it if the transport cannot read the channel, and the channel's error has no code.Retry the operation.

Adaptor and decoder errors

Some of these code names start with Session to match the Ably error registry. They are adaptor and decoder errors.

CodeNameHTTP statusDescriptionRecovery
104000StreamedMessageFinalizeFailed500An append to a streamed message failed, and the update that would have repaired it with the full content failed too. The partial message stays on the channel. The first failure is the cause.Check connectivity, and decide whether to publish the response again.
104005SessionSendFailed500A publish through send() failed for a reason other than a 401 or 403 status. The Ably failure is the cause. A chat transport stream ends with it if the request to your backend fails, or your backend responds with a status outside 2xx, before the response ends. Its statusCode is the HTTP status, or 500 if the request got no response.Inspect the cause, and check the connection state. For the chat transport, read the error's message in place of the cause. It includes the HTTP status and the start of the response body, or the reason the request failed.
104008PipeFailed500A pipe failed for one of these reasons: the source stream threw, such as on a provider rate limit or a model error; the codec could not encode an event; a publish or update failed; or the repair of a stream failed. When the underlying failure is an Ably ErrorInfo, it is the cause. A provider error leaves cause undefined.Inspect the message for the provider error.
104009SessionMessageProcessingFailed500The codec threw while decoding an inbound message. The message is still delivered with no event, and the decoder carries on. Reported to the decoder's onError handlers. A chat transport stream ends with it if a message that arrives while the response streams cannot be decoded.Check the codec's decode for the message type.

Auth and channel errors

Auth and channel errors come from the Ably platform rather than AI Transport. The most common codes you encounter:

CodeDescriptionRecovery
40142Token expired.Refresh the token (handled automatically with authUrl/authCallback).
40300Forbidden.The token is valid but not authorised for this resource.
80000Channel attach failed.Check the channel name and capability.
90000Internal channel error.Retry the operation. If the error persists, contact support.
93002Can only update/delete/append messages on channels with mutableMessages enabled. No channel rule with mutableMessages matches the channel, so AI Transport cannot append stream tokens. This is the most common AI Transport setup failure.Enable the Message annotations, updates, deletes, and appends rule on the channel.

The Ably error codes page lists every code the platform returns.

Match an ErrorInfo against a code

errorInfoIs(errorInfo: Ably.ErrorInfo, error: ErrorCode): boolean

errorInfoIs returns true if the ErrorInfo's code matches the supplied ErrorCode. Use it in error handlers to branch on a specific failure by its numeric code.

JavaScript

1

2

3

4

5

6

7

8

import { errorInfoIs, ErrorCode } from '@ably/ai-transport';

try {
  await adaptor.pipe(stream, { signal: req.signal });
} catch (error) {
  if (errorInfoIs(error, ErrorCode.OperationCancelled)) return;
  throw error;
}

Example

The agent treats a cancelled pipe as a normal outcome and reports any other failure. The client logs the errors the decoder reports.

OpenAI
Vercel AI SDK
JavaScript

1

2

3

4

5

6

7

8

9

10

11

12

13

// Agent code.
import { ErrorCode, errorInfoIs } from '@ably/ai-transport';
import { ErrorInfo } from '@ably/pubsub-server';

try {
  await adaptor.pipe(stream, { signal: req.signal });
  return new Response(null, { status: 204 });
} catch (error) {
  const cancelled = error instanceof ErrorInfo && errorInfoIs(error, ErrorCode.OperationCancelled);
  return new Response(null, { status: cancelled ? 204 : 500 });
} finally {
  ably.close();
}
JavaScript

1

2

3

4

5

6

// Client code.
decoder.onError((error) => {
  console.error(`Error ${error.code}: ${error.message}`);
});

await channel.subscribe(decoder.receive);