API
Official Telegram API templates and device metadata helpers live in opentele2.api.
APIData
APIData stores the Telegram client identity sent with a session:
api_idapi_hashdevice_modelsystem_versionapp_versionlang_codesystem_lang_codelang_pack
Use copy() when passing a reusable template into code that may mutate fields.
Use to_json() and from_json() when exporting or importing .session + .json
metadata.
from opentele2.api import APIData
api = APIData(
api_id=12345,
api_hash="0123456789abcdef0123456789abcdef",
device_model="PC 64bit",
system_version="Windows 11",
app_version="5.0.0",
lang_code="en",
system_lang_code="en-US",
lang_pack="tdesktop",
)
payload = api.to_json()
same_api = APIData.from_json(payload)API
API exposes built-in templates for official Telegram clients:
API.TelegramDesktopAPI.TelegramAndroidAPI.TelegramAndroidXAPI.TelegramIOSAPI.TelegramMacOSAPI.TelegramWeb_AAPI.TelegramWeb_KAPI.Webogram
Most templates support Generate(unique_id=None) to return a copy with realistic
device metadata. Passing the same unique_id makes the generated fingerprint
stable for the same input.
from opentele2.api import API
api = API.TelegramAndroid.Generate(unique_id="telethon.session")
print(api.device_model)
print(api.system_version)See Using official APIs for a complete workflow.
Last updated on