Telethon: The api_id/api_hash combination is invalid

It turns out that my script worked perfectly until I tried using it on another server, and from that moment on it stopped working and the error appears api_id / api_hash combination is invalid. I have checked api_id and hash_id many times, but they haven’t changed… so I would appreciate some help. Thanks.

Traceback (most recent call last):
  File "mytelegram.py", line 41, in <module>
    tclient.send_code_request(phone)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/telethon/telegram_client.py", line 241, in send_code_request
    result = self(SendCodeRequest(phone, self.api_id, self.api_hash))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/telethon/telegram_bare_client.py", line 486, in __call__
    result = self._invoke(call_receive, request, ordered=ordered)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/telethon/telegram_bare_client.py", line 583, in _invoke
    raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_error_list.ApiIdInvalidError: The api_id/api_hash combination is invalid

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I actually figured it out. It was my fault I guess.

I created a bot account from BotFather and I was using my bot’s API token for all the variables; api_id, api_hash and bot_token. I did not realize that I had to use my api_id and api_hash for those variables. So to summarize:

api_id = <youraccount_api_id>
api_hash = <youraccount_api_hash>
bot_token = '123456789:apitoken_ofyourbot_thatyougetfrom_botfather'

I was actually going back and forth through the documentation and realized that I was wrong after reading TelegramClient page. In my opinion it should be mentioned on here too.

BTW both my own api_id and bot’s api_id are longer than 5 chars.

The “here” you mention already says:

(at the top) Note: This API ID and hash is the one used by your application, not your phone number. You can use this API ID and hash with any phone number or even for bot accounts.

Signing In as a Bot Account […] You will still need an API ID and hash.

API ID, API hash, and bot token, all are different terms. But if you can improve the documentation, feel free to send a PR.