Skip to main content

Errors

Exceptions

Shared error types raised by both clients. Modus SDK exception hierarchy. All exceptions raised by the SDK are subclasses of ModusError. HTTP errors are mapped from status codes; run errors are raised from stream events.

ModusError

Extends: Error Base class for all Modus SDK errors. HTTP failures map to subclasses by status code. Streaming run failures map from event types (error, cancelled, stream_timeout). Properties:
  • statusCode: number
  • requestId: string
  • responseHeaders: Record<string, string>
  • body: string
  • code: string

APIConnectionError

Extends: ModusError Network-level failure (connection error, read timeout, etc.) after all automatic retries are exhausted.

AuthenticationError

Extends: ModusError The API key is missing, invalid, or expired (HTTP 401). Check that MODUS_API_KEY is set correctly, or pass apiKey explicitly. Create a token at app.getmodus.com → Settings → API Tokens.

PermissionDeniedError

Extends: ModusError The API key does not have permission for the requested operation (HTTP 403).

NotFoundError

Extends: ModusError The requested resource does not exist (HTTP 404).

ConflictError

Extends: ModusError Idempotency conflict — a run with this ID already exists with a different body (HTTP 409). Use a new idempotency key or omit it to auto-generate.

UnprocessableError

Extends: ModusError Request validation failed (HTTP 422). Inspect errors when present for field-level details. Properties:
  • errors: unknown

RateLimitError

Extends: ModusError Too many requests (HTTP 429). When present, retryAfter is the suggested wait in seconds. Properties:
  • retryAfter: number

InternalServerError

Extends: ModusError Unexpected server failure (HTTP 5xx).

RunCancelledError

Extends: ModusError The run was cancelled before it finished.

StreamTimeoutError

Extends: ModusError The streaming connection timed out before a final result arrived.

ValidationError

Extends: ModusError Client-side argument validation failed before a request was sent (for example an unsupported chat model id).