SDK

SDK: error handling

Every error is a subclass of AistAgentError. HTTP errors carry .status and .body, so you can catch specific situations by type.

Hierarchy

The base class is AistAgentError. HTTP errors are AistAgentApiError (with the .status and .body properties) and its subclasses:

ClassStatus / case
UnauthorizedError401 — the token is invalid, expired or revoked
ForbiddenError403 — accessing someone else’s task
NotFoundError404 — task not found
TaskConflictError409 — tool-results for a task that isn’t interrupted
ValidationError422 — the body failed validation
RateLimitError429 — the active task limit is exceeded
AistAgentTimeoutErrorA request or wait timeout
MissingToolHandlerErrorNo handler for the called client tool

Example

ts
import { RateLimitError, ValidationError } from '@aist-packages/aist-agent-sdk';

try {
  await client.createTask({ assistant_id: 1, input: [textInput('…')] });
} catch (e) {
  if (e instanceof RateLimitError) {        // 429: too many active tasks
    console.warn('Try again later:', e.status, e.body);
  } else if (e instanceof ValidationError) {  // 422
    console.error('Check the request body:', e.body);
  } else {
    throw e;
  }
}

AistAgentApiError properties

PropertyDescription
.statusThe HTTP response code.
.bodyThe parsed response body (JSON or text).
.messageA human-readable message.
Error codes and what they mean on the server side are on the Errors and limits page.