English فارسی

Client reference

One class, 84 public members. Grouped by job so you can find things without scrolling a 1,300-line file.

Constructor

Client(credential=None, *, timeout=30.0, session_dir="sessions", session_name=None, device_title="bale xyz", websocket_uri="wss://next-ws.bale.ai/ws/", origin="https://web.bale.ai", auto_connect=False, bot_token=None, bot_api_url="https://tapi.bale.ai", phone_prompt=None, code_prompt=None, password_prompt=None, name_prompt=None)
credential
Session string (id:jwt), phone number, or bot token — detected automatically
timeout
Seconds, applied to RPCs, the socket and HTTP
session_dir
Where to persist sessions; "" disables persistence
session_name
Filename inside session_dir
device_title
Shown in Bale's active-sessions list
websocket_uri
Override the RPC endpoint
origin
Origin header sent with the handshake
auto_connect
Connect on construction (blocks; prefer await start())
bot_token
Explicit bot mode, ignoring credential
bot_api_url
Bot API base URL
phone_prompt / code_prompt / password_prompt / name_prompt
Sync or async callables that supply interactive auth values
client = Client(
    "256049633:eyJ…",
    timeout=45,
    session_dir="",          # ephemeral
    device_title="my bot runner",
)

Lifecycle

MemberAsyncPurpose
start()✔Authenticate if needed, open the socket, load me. Returns self.
connect()✔Same but returns None
close()✔Close the socket, gRPC client and Bot API session. Idempotent.
__aenter__ / __aexit__✔Enables async with Client(...)
run(task=None)✔Connect, optionally await one coroutine, then block
run_forever()—Blocking entry point (creates its own loop)
connected—bool

State

AttributeType
user_idint | None
medict — the GetMe response
is_user / is_botbool
sessionSession | None
botBotApi | None
dispatcherDispatcher
rpcRpcClient (after connect)
token = await client.export_session()      # "256049633:eyJ…"

Messaging

MethodSignature
send_message(chat_id, text, *, reply_to=None, silent=False, edit=False)
edit_message(chat_id, message_id, text)
delete_messages(chat_id, message_ids, *, revoke=True)
send_typing(chat_id, action="typing")
get_chat(chat_id) → dict
get_history(chat_id, *, limit=50, before=None)
get_dialogs(*, limit=100)
get_me() → dict

Files & media

MethodSignature
upload_file(path=None, *, data=None, name=None, mime_type=…, chat_id=None, kind="document", chunk_size=0, put=True)
send_file(chat_id, path=None, *, data=None, name=None, mime_type=…, caption=None, kind="document", width=0, height=0, duration=0, reply_to=None, silent=False)
send_photo(chat_id, photo, *, caption=None, **kwargs)
send_video(chat_id, video, *, caption=None, **kwargs)
send_voice(chat_id, voice, *, caption=None, **kwargs)
send_audio(chat_id, audio, *, caption=None, **kwargs)
send_document(chat_id, document, *, caption=None, name=None, mime_type=…)
download_file(file_id, *, ciphertext=False) → bytes
get_file_url(file_id, *, ciphertext=False) → str | None
get_upload_limits() → dict

Chats, groups, users

create_group(title, members=())
get_group_info(chat_id)
add_group_member(chat_id, user)
remove_group_member(chat_id, user)
search_users(query, *, limit=20)
search_messages(chat_id, query, *, limit=20)
resolve_username(username)

Conferences & Meet

GroupMethods
Createcreate_meet_link, create_conference, start_call, generate_call_link, set_call_link_title
Joinjoin_conference, join_call, leave_call, accept_call, receive_call, discard_call, ask_to_join_call, answer_join_request
Moderatemute_participant, remove_from_call, raise_hand, lower_hand, take_call_action, send_call_reaction, update_call_layout, invite_to_call
Record / streamstart_call_recording, stop_call_recording, start_call_stream, delete_call_stream
Inspectget_call, get_call_state, get_ongoing_calls, get_call_logs, delete_call_logs, get_call_link_details, submit_call_feedback, send_call_fanoos_event

Full guide with examples →

Events

on_message(filter=None)          # decorator → Message
on_event(*event_classes)         # decorator
on_update(handler)               # raw dict frames

await next_update(timeout=None)
client.iter_updates()            # async generator
await next_event(timeout=None)
client.iter_events()             # async generator

RPC layer

await call(service, method, payload=None)     # → protobuf message
await invoke(service, method, payload=None)   # → snake_case dict
client.api(service)                           # → attribute proxy
client.rpc_stream(service, method, payload)   # async generator
await bot_call(method, **params)              # Bot API passthrough

methods()                                     # list[str] of 683 pairs
find(term)                                    # list[str] matches
describe(service, method)                     # str signature

Everything, alphabetically

accept_call, add_group_member, answer_join_request, api, ask_to_join_call, bot, bot_call, call, close, connect, connected, create_conference, create_group, create_meet_link, delete_call_logs, delete_call_stream, delete_messages, describe, discard_call, download_file, export_session, find, generate_call_link, get_call, get_call_link_details, get_call_logs, get_call_state, get_chat, get_dialogs, get_file_url, get_group_info, get_history, get_me, get_ongoing_calls, get_upload_limits, invite_to_call, invoke, is_bot, is_user, iter_events, iter_updates, join_call, join_conference, leave_call, lower_hand, methods, mute_participant, next_event, next_update, on_event, on_message, on_update, raise_hand, receive_call, remove_from_call, remove_group_member, resolve_username, rpc_stream, run, run_forever, search_messages, search_users, send_audio, send_call_fanoos_event, send_call_reaction, send_document, send_file, send_message, send_photo, send_typing, send_video, send_voice, session, set_call_link_title, start, start_call, start_call_recording, start_call_stream, stop_call_recording, submit_call_feedback, take_call_action, update_call_layout, upload_file.

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