English فارسی

Enums & errors

The small vocabulary of the library — and how failures surface.

CallMode

NameValueMeaning
CallMode.GROUP2Conference bound to a chat
CallMode.MULTI_PEER3Link-based room
CallMode.LIVE4Broadcast

CallRecordQuality

Accepted by start_call_recording(quality=…) as a name or raw int.

ChatType

NameValueHelpers
ChatType.USER1is_private
ChatType.GROUP2is_group
ChatType.CHANNEL3is_channel
ChatType.BOT4—
ChatType.SUPERGROUP5is_group
ChatType.THREAD6—

ChatAction

Typing-style indicators: typing, uploading_photo, recording_video, and friends.

Exception hierarchy

BaleError                     # base for everything
├── ClientStateError          # used before connecting, or no session
├── SessionError              # session string / cookie extraction failed
├── TransportError            # socket or HTTP layer failed
└── RpcError                  # server said no
    ├── AuthError             # login rejected
    └── FloodWait             # rate limited (has .seconds)

BotApiError                   # separate: tapi.bale.ai returned ok=false
ExceptionAttributesTypical cause
RpcErrorcode, message, reason, detailsAny application-level failure
AuthErrorsame, plus the auth stepWrong code, expired session, no JWT in the response
FloodWaitsecondsToo many requests — sleep and retry
BotApiErrorcode, description, methodBot API ok: false
ClientStateError—Calling RPC before start()

Catching correctly

from balexyz import BaleError, FloodWait, RpcError

try:
    await client.send_message("987654321|1", "hi")
except FloodWait as exc:
    await asyncio.sleep(exc.seconds)
    await client.send_message("987654321|1", "hi")
except RpcError as exc:
    log.warning("rpc failed: code=%s reason=%s", exc.code, exc.reason)
except BaleError:
    log.exception("transport or state problem")
Order matters.

FloodWait and AuthError both subclass RpcError, so catch the specific ones first. Catching BaleError alone will also swallow programming mistakes like using a closed client.

bale xyz 1.0.0 · MIT licensed · unofficial client © 2026 bale xyz contributors