Skip to Content

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_id
  • api_hash
  • device_model
  • system_version
  • app_version
  • lang_code
  • system_lang_code
  • lang_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.TelegramDesktop
  • API.TelegramAndroid
  • API.TelegramAndroidX
  • API.TelegramIOS
  • API.TelegramMacOS
  • API.TelegramWeb_A
  • API.TelegramWeb_K
  • API.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