English فارسی

Quick start

Five minutes from pip install to a message sent and a meeting link created.

1. Say hello

hello.py
import asyncio
from balexyz import Client


async def main() -> None:
    # A session string is ":". See the Authentication page.
    async with Client("256049633:eyJhbGciOi...") as client:
        print("logged in as", client.user_id)

        await client.send_message("987654321|1", "hello from bale xyz")
        await client.send_message("me", "note to self")


asyncio.run(main())
What just happened.

async with connects the WebSocket, authenticates, and calls GetMe to populate client.me. The peer "987654321|1" is Bale's canonical id|type form. See peer addressing for the short forms.

2. Create a meeting link

This is exactly what the browser's “create call” button does:

meeting = await client.create_meet_link(title="Team sync", is_public=True)

print(meeting["link"])        # https://meet.bale.ai/i/zfqw-52pog-g5o5
print(meeting["expires_in"])  # 10800  → three hours

3. Start an audio-only conference for a group

result = await client.create_conference(
    "987654321|2",   # the group
    voice=True,      # ← audio only; video=False would enable the camera
)
call = result["group_call"]
print(call["id"], call["room"])

4. React to incoming messages

@client.on_message()
async def handler(message):
    print(message.text, "from", message.sender_id)

    if message.text == "/ping":
        await message.reply("pong")


await client.run_forever()

5. Or use a bot token

The same class. Detection is automatic — a string matching 123456:ABC… is treated as a bot token.

from balexyz import Client

bot = Client("123456789:AAH4x-veryLongTokenValueHere")

async with bot:
    me = await bot.get_me()
    print(me["username"])

    await bot.send_message("987654321|1", "beep")

6. Explore without credentials

Great for discovery before you have a session:

from balexyz import Client, dynamic

# Describe any of the 683 RPCs — request and response, no network
print(dynamic.describe("bale.meet.v1.Meet", "StartGroupCall"))

# Build a payload and look at the bytes
raw = dynamic.encode(
    "bale.meet.v1.Meet", "GenerateCallLink", {"isPublic": True}
)
print(raw.hex())   # 0801  — identical to the browser's frame

Patterns that save you time

Timeouts

Client(cred, timeout=30.0) applies to every RPC, the WebSocket and the Bot API.

Disable session persistence

Client(cred, session_dir="") keeps JWTs in memory only. Useful for tests and CI.

Async or blocking

await client.run() awaits one coroutine; client.run_forever() blocks like Telethon.

Avoid the async trap

Never call asyncio.run() twice on the same client. Create one event loop per process.

Where to go next

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