Ilana Docs
SDK

Error Handling

Result Pattern

By default, client.query() returns a Result<QueryOutput>:

type Result<T> =
  | { ok: true; data: T }
  | { ok: false; error: IlanaError };

This avoids uncaught exceptions and makes error handling explicit:

const result = await client.query({ botId: 'bot-123', input: 'Hello' });

if (result.ok) {
  console.log(result.data.response);
} else {
  console.error(result.error.code, result.error.message);
}

throwOnError Mode

If you prefer exceptions, set throwOnError: true in the client config:

const client = new IlanaClient({
  runtimeUrl: 'https://api.getilana.ai',
  token: 'your-token',
  throwOnError: true,
});

try {
  // Returns QueryOutput directly, not wrapped in Result
  const data = await client.query({ botId: 'bot-123', input: 'Hello' });
  console.log(data.response);
} catch (err) {
  if (err instanceof IlanaSDKError) {
    console.error(err.code, err.status, err.message);
  }
}

IlanaError

The error shape returned in Result.error:

interface IlanaError {
  code: IlanaErrorCode;
  message: string;
  status?: number;
  requestId?: string;
  raw?: unknown;
}
PropertyTypeDescription
codeIlanaErrorCodeMachine-readable error code
messagestringHuman-readable error description
statusnumber | undefinedHTTP status code from the server
requestIdstring | undefinedServer request ID for debugging
rawunknownRaw error payload for inspection

IlanaSDKError

Thrown when throwOnError is enabled. Extends Error:

class IlanaSDKError extends Error {
  readonly code: IlanaErrorCode;
  readonly status?: number;
  readonly requestId?: string;
  readonly raw?: unknown;
}

Error Codes

CodeHTTP StatusDescription
UNAUTHORIZED401Invalid or missing embed token
FORBIDDEN403Token valid but domain not allowed
NOT_FOUND404Bot not found
RATE_LIMITED429Too many requests — try again later
MESSAGE_CAP_EXCEEDED429Monthly message limit reached for your plan
INVALID_REQUEST400Malformed request body
INTERNAL_ERROR500Server error
SERVICE_UNAVAILABLE503Service temporarily unavailable
NETWORK_ERRORNetwork failure (no response received)
UNKNOWN_ERRORUnexpected error

MESSAGE_CAP_EXCEEDED

When the monthly message cap is reached, the error includes additional fields:

{
  code: 'MESSAGE_CAP_EXCEEDED',
  message: 'Monthly message limit exceeded',
  status: 429,
  raw: {
    tier: 'free',
    limit: 100,
    resetAt: '2026-03-01T00:00:00.000Z'
  }
}