Skip to main content
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 SSE events.
  • HTTP mapping: 401 -> AuthenticationError 403 -> PermissionDeniedError 404 -> NotFoundError 409 -> ConflictError 422 -> UnprocessableError 429 -> RateLimitError 5xx -> InternalServerError
  • SSE event mapping: { type: “error” } -> ModusError (raised from run/stream) { type: “cancelled” } -> RunCancelledError { type: “stream_timeout” } -> StreamTimeoutError

ModusError

Bases: Exception Base class for all Modus SDK errors.

APIConnectionError

Bases: ModusError Network-level failure (ConnectError, ReadTimeout, etc.) after all automatic retries are exhausted.

AuthenticationError

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

PermissionDeniedError

Bases: ModusError Raised when the API key does not have permission for the requested operation (HTTP 403).

NotFoundError

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

ConflictError

Bases: 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

Bases: ModusError Request validation failed (HTTP 422). The errors attribute contains the full validation error detail.

RateLimitError

Bases: ModusError Rate limit exceeded (HTTP 429). The retry_after attribute contains the number of seconds to wait before retrying, if the server provided a Retry-After header. The SDK retries automatically — this error only surfaces after all retry attempts are exhausted.

InternalServerError

Bases: ModusError The server encountered an internal error (HTTP 5xx). The SDK retries automatically — this error only surfaces after all retry attempts are exhausted.

RunCancelledError

Bases: ModusError Raised when a chat stream is cancelled before completing.

StreamTimeoutError

Bases: ModusError Raised when a chat stream times out before completion.