Create a Telegram application on my.telegram.org to get your api_id and api_hash, fill in the form correctly, keep them secret and fix the usual errors.
To get a Telegram API ID and API hash, log in at my.telegram.org with your phone number, open API development tools, fill in the short form describing your application, and submit it. The page then shows your api_id (a number) and api_hash (a long string of letters and digits). Treat both as secrets, because they identify your application to Telegram.
This guide explains what the two values are, when you actually need them and when a bot token is enough, how to fill in the form, how to store the values safely, and how to fix the errors people run into. It also covers the scam that uses my.telegram.org to steal accounts.
Telegram offers two different programming interfaces, and they need different credentials.
The Bot API is a simplified HTTP interface for bots. You create a bot with @BotFather and receive a bot token. That token is all an ordinary bot needs. Most people building a bot never touch my.telegram.org.
The Telegram API, built on Telegram's own MTProto protocol, is the full interface that Telegram's own apps use. With it you can build a complete Telegram client, automate a user account, or use libraries that talk to Telegram directly rather than through the Bot API. To use it, your program must say which application it is. That is what the api_id and api_hash do.
They identify the application, not the person using it. Every user who logs in through your app still needs their own phone number and login code. Your api_id does not give you access to anyone's account, and it does not give anyone access to yours. Those secrets matter for a different reason, covered below.
For a broader comparison of the two interfaces and of user-account automation, see Bot API vs MTProto vs userbots.
Check this first. Many people go through my.telegram.org when they do not need to.
You need an api_id and api_hash if you are:
You do not need them if you are:
If a website or person asks for your api_id and api_hash and you are not building anything, stop and read the scam section below.
Before you set up a developer application, check whether a built-in feature or a plain bot already does the job. Each alternative below avoids the risks of running your own account through code.
Saving your chat history. If your goal is a copy of your chats, channels or media, Telegram Desktop has an export tool that saves history as readable files or as machine-readable data. It needs no programming. See how to export Telegram chat history.
Posting to your own channel automatically. A bot added as an admin of your channel can post through the Bot API. That covers scheduled announcements, posts from a website feed, and buttons under posts. Only the bot token is needed.
Replying to people who message you. Again a bot is the right tool. People start a chat with the bot, and the bot can answer them. Automating your personal account to reply to strangers is far more likely to get it restricted.
Collecting form answers, polls or sign-ups. Native polls, a group with a bot, or a bot builder cover most of this without any MTProto work.
Reading channels you do not run. This is where a Bot API bot usually falls short, because a bot only sees chats it has been added to. Reading public channels as yourself, at a gentle pace, is one of the more common honest reasons to get an api_id.
As a rule of thumb, if the job is something a bot could do as a member or admin, use a bot. Reach for the api_id when the job genuinely requires acting as a user.
Telegram's own guide also notes that each phone number can currently have only one api_id. If you already created an application with your number, you will see its details instead of the form.
You can come back later, log in again and open API development tools to view the same values.
The form is short. None of the fields needs to be perfect, but sensible values avoid problems.
App title. A human-readable name for your application, such as "Sam's Channel Archiver". It appears in the active sessions list of anyone who logs in through your app, so pick something you would be happy for users to see.
Short name. A compact identifier made of letters and digits only. The form tells you the allowed length if your entry is rejected. Avoid spaces, punctuation and anything that resembles Telegram's own app names.
URL. A website for your project, if you have one. Many personal projects leave it blank or use a project page. It is optional on most versions of the form.
Platform. The platform your application runs on, such as desktop, Android, iOS, web or other. Choose the closest match; it does not limit where you can run your code.
Description. A sentence or two explaining what the app does. Be honest and plain: "Personal tool that saves posts from channels I follow into a local archive."
Telegram's documentation says the test servers are a separate environment with separate accounts. They are useful for trying sign-in flows without risking your main account, but data there is not your real Telegram data.
Telegram's developer terms describe these credentials as confidential and prohibit publishing them. In practice:
If your api_id and api_hash leak, other people can run software that presents itself to Telegram as your application. If that software spams or floods Telegram's servers, the abuse is tied to your application. Telegram may then restrict the api_id, which breaks your app for everyone using it, and may take action against the account that registered it.
Some open-source projects include an api_id and api_hash in their example code. Telegram's terms say these sample values are restricted and meant for testing only. Software that uses them outside testing can trigger an error for its users (API_ID_PUBLISHED_FLOOD). Always get your own pair for anything real.
You should read Telegram's API terms of service yourself, because they are the binding version and they change. The main themes, in general terms:
For people automating their own account, the practical rule is to behave like a careful human, not a script running flat out. The guide to Telegram flood wait explains the rate limits you will meet when a program sends requests too quickly, and what they mean.
How to recognise it: you entered your number on my.telegram.org but see no SMS.
Why: the code is sent inside Telegram, not by SMS. It arrives as a message from Telegram's official notification account.
Fix:
If it still does not appear: check that you typed the number exactly as it is registered, including the country code. If you are logged out of every device, log in to Telegram first, then return to the website.
How to recognise it: the site refuses to send another code or says to try later.
Fix: wait. Repeated attempts extend the block. Come back later, request one code and enter it carefully. The limit lifts on its own after a while; nothing you do on the site shortens it.
How to recognise it: you submit the form and get an error message with little or no explanation.
Why: Telegram does not publish a full list of reasons. Developers commonly report it with brand-new accounts, with connections through a VPN or proxy, with browser extensions that block scripts, and with form values the site does not accept.
Fix, one step at a time:
If it still fails: the account may be too new or have restrictions that prevent creating an application. Using Telegram normally for a while, rather than creating many accounts to try, is the reasonable path. Do not buy accounts or pre-made credentials to get around it; those come from other people and break the terms.
How to recognise it: the program starts but Telegram rejects the connection with an error mentioning an invalid API ID.
Fix:
How to recognise it: you start getting flood errors, cannot message people outside your contacts, or receive a notice about restrictions.
Fix: stop the automation, read the restriction message carefully, and follow the in-app path Telegram offers. The account banned guide covers the appeal routes. Then reduce how often your program acts and stop any messaging to people who did not ask for it.
Because my.telegram.org can delete accounts and create API credentials, scammers target its login code.
The pattern usually looks like this. Someone in a chat, often posing as support, a bot developer or a giveaway organiser, asks you to "verify" by logging in to my.telegram.org and sending them the code, or by entering it on a site they link. With that code, they can log in to the site as you. From there they can create an API application on your number, view your api_hash, or reach the account deletion page.
Rules that protect you:
The broader rules are in never share your Telegram login code.
Each library or tool has its own setup, but the flow is broadly the same.
That fourth point catches many people out. The api_hash identifies your app; the session is the key to your account. Keep session files out of public code and shared folders, and delete them when you stop using a tool.
Code that logs in as you acts with your full account. A mistake in it, or a rule broken by accident, lands on your personal profile, your chats and any channels you own. A few habits reduce that risk.
Telegram runs a separate test environment, and the server details for it appear on your API development tools page. It has its own accounts, separate from your real one, and data there is not your real Telegram data.
It is useful when you are building something that handles sign-in, such as your own client, and you want to try the login flow repeatedly without tripping limits on your real number. Most libraries have a setting to point them at the test servers instead of the production ones. Your library's documentation explains how.
For tools that read real channels or manage your real account, the test environment does not help, because the content you care about only exists in production. In that case, go slowly in production instead.
Example: a personal channel archive. A researcher wants to save posts from public channels they follow into a spreadsheet. A Bot API bot cannot read channels it is not a member of, so they create an application on my.telegram.org, use an MTProto library with their own api_id and api_hash, and log in with their own account. They keep the request rate low and run it once a day.
Example: a bot that turns out not to need it. A shop owner wants a bot that answers questions and takes orders. A tutorial mentioned api_id, so they went to my.telegram.org first. In fact a bot token from @BotFather is all their Bot API framework needs, and the my.telegram.org step was unnecessary.
Example: a leaked hash. A developer pushed a project to a public repository with their api_id and api_hash inside. They remove the values, rewrite the project history so old versions no longer contain them, and move the values to local configuration. They also review their active sessions, remove any session files from the repository, and watch for unusual activity on the account.
Once you have your credentials, the next steps depend on what you are building.
Keep the API development tools page bookmarked, and keep the phone number current, since Telegram uses it to reach you about your application.
Yes. Creating an application on my.telegram.org does not cost anything.
Telegram's guide says each phone number can currently be linked to only one api_id. One application usually serves all your personal projects.
The API development tools page shows your application details when you log in again. Options to edit details may be offered there; check the page itself, as Telegram does not document every option. Your api_id stays tied to your number.
No, not by themselves. They would still need a login code or a session for your account. But they could run software that presents itself as your application, and abuse by that software is tied to you. Keep both values private.
Bots have a token, not an api_id. Some MTProto-based bot frameworks ask for an api_id and api_hash as well, which come from your own application on my.telegram.org.
Someone may be trying to get into it with your number. Do not share the code with anyone who contacts you about it. Check your active sessions in Telegram and turn on two-step verification if you have not already. Our guide to two-step verification walks through it.
Log in to my.telegram.org with your number, type the code sent inside Telegram, open API development tools and fill in the short form to get your api_id and api_hash. You only need them for MTProto-based tools, clients and TDLib, not for ordinary bots. Keep both values and any session files private, follow Telegram's API terms, and never give the my.telegram.org code to anyone.
Ownership confirmed through our claim process — not an endorsement of their content.
Founder of Telegram.
The official Telegram on Telegram. Much recursion. Very Telegram. Wow.
Telegram Premium – a subscription that unlocks dozens of exclusive features.
Binance Official English Group Binance Official Chinese Group Binance English Announcements Binance Chinese Announcements
is a modern crypto news and research platform covering the latest developments across digital assets, markets, regulation, and blockchain technology.
Technical analysis & high-probability trade setups. Price action, market structure, risk control.
BlackBlock Markets exists to observe how capital moves before it becomes obvious.
This channel focuses exclusively on what shapes global finance. Macroeconomics, markets, liquidity, central banks.
Clear long & short signals for BTC, ETH & liquid altcoins. AI-backed analysis, real-time execution.