Telegram Bot API vs MTProto: which one to use
The Bot API is an HTTPS interface driven by a BotFather token: simple and low-risk, but a bot only sees new events meant for it. MTProto is the API built for Telegram clients: a user account (a userbot) can read history, list members and send files up to 2 GB, at the cost of FLOOD_WAIT limits and ban risk. Customer-facing service — bot; automating your own account — MTProto.
Updated:
The difference in short
With the Bot API you act as a bot: token-based, over HTTPS, within what bots are allowed to do. With MTProto you usually log in as a regular user — phone, code, 2FA — and can do from code nearly everything the Telegram app can. More power means more responsibility and more risk.
One clarification: MTProto doesn't automatically mean “userbot”. Bots can also log in over MTProto (auth.importBotAuthorization, with an api_id), but bot restrictions still apply. In practice, “MTProto” usually refers to acting as a user account, and that's how this article uses it.
Terms
- Bot API
- The HTTP interface at api.telegram.org. Each request is /bot<token>/methodName with a JSON response.
- MTProto API
- The protocol and API built for Telegram clients. Connecting requires an api_id and api_hash from my.telegram.org.
- Userbot
- A regular user account automated over MTProto. Developer slang, not an official term.
- Telethon
- A popular Python library for MTProto. Socialift's
TelegramAccountclient is built on top of it. - Local Bot API server
- Running Telegram's open-source Bot API server yourself, which raises file size limits and relaxes webhook restrictions.
The big comparison table
| Criterion | Bot API | MTProto (user account) |
|---|---|---|
| Authentication | BotFather token | api_id + api_hash, then phone → code → 2FA; the result is a session string |
| Transport | HTTPS + JSON, stateless requests | A persistent MTProto connection with session state |
| Messaging first | No: a person must message the bot or add it to a group | Possible, but privacy settings and anti-spam limits apply |
| Reading history | No history method; only new updates, kept up to 24 hours | Full history (unless the group hides it from new members) |
| Member lists | Only admins, a single member's status and the member count | Available; channel subscribers are visible to admins only, and admins can hide the list |
| Group messages | Privacy mode: commands and replies only (everything if admin or mode disabled) | Everything in chats the account belongs to |
| Joining chats | Can't join on its own — someone adds it | Via an invite link or public @username |
| Sending files | 50 MB (photos 10 MB); 2000 MB on a local server | 2 GB, 4 GB with Telegram Premium |
| Downloading files | 20 MB; unlimited on a local server | Anything the account can see, up to 4 GB |
| Rate limits | Documented: ~1 msg/s per chat, 20/min per group, ~30/s for broadcasts; exceed → 429 + retry_after | No published numbers; exceed → 420 FLOOD_WAIT_X, wait X seconds |
| Scheduled messages | No | Yes: Telegram sends the message at the set time itself |
| Channel statistics | No | For admins of channels above a certain size |
| ToS risk | Low; the main risk is a leaked token | Unofficial-client accounts are observed; spam, flooding or fake metrics mean a permanent ban |
| Hosting | Webhook (443/80/88/8443) or long polling; serverless-friendly | A long-running process; one session can't be used in parallel (AUTH_KEY_DUPLICATED) |
| Socialift SDK | Telegram | TelegramAccount (pip install "socialift[telegram]") |
Decision guide: pick by task
| Task | Choice | Why |
|---|---|---|
| Customer replies, order status, notifications | Bot API | Users press /start themselves; buttons and webhooks; low ban risk |
| News for thousands of subscribers | Channel + bot posting as admin | You avoid private message limits |
| Moderating your own group | Bot API | Bans, restrictions and join requests are all available to bots |
| Exporting or analysing your chat history | MTProto | Bots have no history method |
| Member list of your own group | MTProto (as an admin) | The Bot API doesn't return full lists |
| Scheduled channel posts, statistics | MTProto | Not in the Bot API |
| Files over 50 MB | MTProto or a local Bot API server | The official Bot API server caps uploads at 50 MB |
| Mass messages or invites to strangers | Neither | Against Telegram's rules; the account can be banned permanently |
Are userbots allowed? What Telegram's rules say
Telegram invites developers to build apps on its API free of charge, so automating an account over MTProto isn't forbidden in itself. The conditions: the app needs its own api_id, must not act on a user's behalf without their knowledge and consent, and must not use Telegram data to train AI models.
The official page is explicit: every account that logs in through an unofficial client is automatically put under observation, and using the API for flooding, spamming or faking channel subscriber and view counts gets you banned forever. The Bot API has rules too, but a bot's biggest practical risk is usually a leaked token — fixed with /token in BotFather.
Using both in one project
Often the right answer is “both”: the account reads what bots can't, and the bot handles the customer-facing part.
import asyncio
from socialift import Telegram, TelegramAccount
async def main():
async with Telegram.from_env() as bot, TelegramAccount.from_env() as account:
# Account: something a bot can't do — read and search group history
last = await account.messages("@my_group", limit=100)
found = await account.search("@my_group", "price", limit=100)
# Bot: post the report to a channel as the bot (the bot is a channel admin)
await bot.send_message("@my_channel",
f"Read {len(last)} messages, {len(found)} mention 'price'")
asyncio.run(main())Telegram.from_env() reads TELEGRAM_BOT_TOKEN; TelegramAccount.from_env() reads TELEGRAM_API_ID, TELEGRAM_API_HASH and TELEGRAM_SESSION.
Rate limits: two errors, one except
The Bot API returns 429 with retry_after; MTProto returns FLOOD_WAIT_X. The SDK maps both to RateLimitError; when the wait is known it's in retry_after, otherwise fall back to a fixed pause.
import asyncio
from socialift import RateLimitError
async def send_with_backoff(client, chat, text: str):
"""client is a Telegram or TelegramAccount instance."""
try:
return await client.send_message(chat, text)
except RateLimitError as exc:
await asyncio.sleep(exc.retry_after or 5)
return await client.send_message(chat, text)When a bot isn't enough
- You need messages from before the bot joined, or ones the bot never receives.
- You need the actual member list of a group or channel, not just the count or the admins.
- You need channel statistics or scheduled posts that Telegram sends itself.
- You handle files over 50 MB and can't run a local Bot API server.
- You need user actions such as creating a group or channel or joining a chat by link.
Frequently asked questions
Telethon or the Bot API — which is better?
They solve different problems. The Bot API is simpler and safer for public services, notifications and moderation. Telethon (MTProto) is for acting as an account, reading history, listing members and big files, but it demands serious care around FLOOD_WAIT and the ToS.
What is a Telegram userbot, and is it banned?
A userbot is a regular account automated over MTProto. It isn't banned as such, but the Telegram API Terms of Service apply: actions without user consent, spam, flooding and fake metrics are prohibited. Accounts using unofficial clients are automatically observed.
Can a bot read a group's history?
No. The Bot API has no method for reading chat history: a bot only receives new updates, and in groups privacy mode limits even those. If you need history, use MTProto with an account that is a member of the group.
What's the file size limit with MTProto?
A regular account can upload files up to 2 GB, and a Telegram Premium account up to 4 GB. The official Bot API server caps sending at 50 MB and downloading at 20 MB.
Can I run a bot over MTProto?
Yes: auth.importBotAuthorization logs a bot in with its token and an api_id, after which most MTProto methods work. Bot restrictions still apply. In Socialift, bots use the Telegram client (Bot API) and user accounts use TelegramAccount.
Can one project use both APIs?
Yes, it's a common setup: the bot talks to customers and moderates, while the account fetches data bots can't reach, such as history, member lists or statistics. In the SDK both clients share one error model.