Skip to content
TGWAY
Channels & Bots STEP 62 / 99

How to Get a Telegram api_id and api_hash Safely

Where to get an api_id and api_hash on my.telegram.org, why the login code there can also delete your account, and how to keep the pair out of your code.

  • Applies toDevelopers
  • LevelL4
  • Reading time4 min
  • Screenshots1
  • Verified

The short answer

  1. 1Log in at my.telegram.org with your number; the code arrives in the Telegram app, not by SMS.
  2. 2API development tools creates one api_id and api_hash per phone number.
  3. 3Treat the pair like a password, ship your own values, and never share the login code.
In this article
  1. What api_id and api_hash are
  2. Getting the pair
  3. Keeping the pair safe
  4. Accounts on unofficial clients are watched
  5. FAQ
  6. At a glance

What api_id and api_hash are

To build an app that logs in as a person, with the Telegram API or TDLib, you need a pair of values: an api_id (a number) and an api_hash (a long string of letters and digits). They identify your app to Telegram's servers. If you are only building a bot, you do not need them; a bot runs on the single token @BotFather gives you. See choosing between the four APIs.

ItemDetail
Wheremy.telegram.org, under API development tools
You needA Telegram account created in an official app, and that app signed in somewhere to receive the code
How manyThe official guide says each phone number can currently have one api_id

Getting the pair

  1. Open my.telegram.org in a browser on your computer and enter your phone number in international format, with the country code and without a leading zero.
The my.telegram.org login page, titled Delete Account or Manage Apps: log in to manage your apps using Telegram API or delete your account; a Your Phone Number field in international format, a Next button, and a note that the code comes via Telegram, not SMS
  1. The same site manages apps and deletes accounts
  2. Your number in international format; the code arrives in the Telegram app
  1. Read the confirmation code in the Telegram app, not in your SMS. It arrives in the verified Telegram service chat. Enter it on the site and sign in. On a shared computer, leave Remember Me off.
  2. Open API development tools. The same page also offers Delete account, which is permanent; do not touch it.
  3. Fill in the form with an app title and a short name. Submitting it creates your api_id and api_hash. If you have created one before, the page shows that app's configuration instead.

Keeping the pair safe

An api_id and api_hash combined with your phone number login let a program act as your account. Treat them like a password.

  • Keep them out of your code. Put them in environment variables or a config file, and keep that file out of your repository.
  • Don't put your values into someone else's program. Handing over the pair together with a login code is the same as handing over the account.
  • Ship your own values. Open-source examples include a sample api_id that is limited on Telegram's side; the official guide warns that releasing an app with it causes the API_ID_PUBLISHED_FLOOD error for your users.

Accounts on unofficial clients are watched

The official guide says all accounts that log in through unofficial API clients are automatically put under observation, and flooding or spamming leads to a permanent ban. If an account that did not break the rules is banned, the guide points to recover@telegram.org. What counts as abuse is in the API terms of service; the login flow itself is in the user login flow.

FAQ

Where do I get a Telegram api_id and api_hash?

Log in at my.telegram.org with your phone number, open API development tools and fill in the app form.

Do I need an api_id to build a Telegram bot?

No. Bots use the token from @BotFather. The api_id and api_hash are for apps that log in as a user.

What is API_ID_PUBLISHED_FLOOD?

An error users get when an app is released with the sample api_id from open-source examples. Use your own api_id before publishing.

Sources

Summary

At a glance

How to Get a Telegram api_id and api_hash Safely — at a glance illustration
  1. 1Where

    my.telegram.org, API development tools.

  2. 2Danger

    The same login can delete your account.

  3. 3Safety

    Keep values out of code; ship your own.

Share this guide

Send it to a friend who has the same question.

Telegram WhatsApp
More

Open on your phonePoint your phone camera here to open this guide.

Updated

Related articles

View all ›