How to get a Telegram api_id and api_hash
How to get api_id and api_hash for the Telegram API on my.telegram.org: where "API development tools" is, what to enter in the form, why the keys must stay private and what Telegram bans accounts for.
api_id and api_hash are the app keys for the Telegram API (MTProto). You need them to write your own Telegram client or a program that signs in to Telegram as a user — for example, with Telethon, Pyrogram or TDLib. Bots don't need them: a bot works with a token from @BotFather.
How to get api_id and api_hash
- Sign up for Telegram with an official app.
- Open my.telegram.org and log in with your phone number — the confirmation code arrives in Telegram.
- Open "API development tools".
- Fill in the form: the app's title (App title), a short name (Short name) and the platform.
- Save — the page now shows App api_id and App api_hash.
Each phone number can have only one api_id.
Use a number you actually use: Telegram sends important developer notifications to it.
See also: How to create a Telegram bot.
How to keep the keys
- api_hash is a secret. Don't publish it in open code, on GitHub or in chats.
- Don't use someone else's keys from examples on the internet in your app: published keys get the
API_ID_PUBLISHED_FLOODerror, and logging in with them fails. - The keys are tied to your account — you are responsible for what an app does with them.
What Telegram bans for
Under the Telegram API rules, an account is banned forever for flooding, spamming or faking channel subscriber and view counts through the API. Accounts that sign in through unofficial clients are put under observation. If you were banned by mistake, Telegram suggests writing to recover@telegram.org and describing how you use the API.
If you need Stars and Premium, not keys
To sell something for Stars in your own bot you don't need an api_id — the Bot API is enough: how to accept Stars payments in a bot. And buying Stars or Premium for your users from your own program is done through the Shiba Bank bot's API — the Telegram Stars API.
FAQ
Where do I get a Telegram api_id and api_hash?
On my.telegram.org: log in with your phone number, open "API development tools" and fill in the app form.
Does a bot need an api_id?
No. A bot works through the Bot API with a token from @BotFather. api_id and api_hash are for programs that sign in to Telegram as a user.
Can I get several api_ids?
Only one api_id per phone number.
Can I share my api_hash?
No. It's the app's secret: keep it out of open code and away from strangers.


