Telegram 400: Bad Request: wrong file identifier/HTTP URL specified — how to fix it
Bad Request: wrong file identifier/HTTP URL specified means Telegram could not use the file you passed as a photo, document or other media. Usually the file_id belongs to a different bot (a file_id works only for the bot that got it), a file_unique_id was sent instead, the id was cut, or Telegram could not download your URL. Upload the file again with this bot and save the new file_id, or upload it instead of sending a link.
By Livops team, the people who build and run LivopsUpdated
The error, as the Telegram Bot API returns it with error code 400[2][3]:
Bad Request: wrong file identifier/HTTP URL specified
Each library wraps it in its own words:
| Library | What you see |
|---|---|
| aiogram 3 | TelegramBadRequest: Telegram server says - Bad Request: wrong file identifier/HTTP URL specified[6][7] |
| python-telegram-bot | telegram.error.BadRequest: Wrong file identifier/http url specified[9][10] |
| grammY | GrammyError: Call to 'sendPhoto' failed! (400: Bad Request: wrong file identifier/HTTP URL specified)[11] |
| Telegraf | TelegramError: 400: Bad Request: wrong file identifier/HTTP URL specified[13] |
python-telegram-bot drops the Bad Request: prefix and runs the rest through Python’s capitalize(), which also lowercases HTTP URL[9]; search your logs case-insensitively. This page explains why one message covers both a file_id and a URL, lists the causes from the most common, shows the fix for each, and ends with what to check when the bot runs on Livops.
What does the error mean?
Every media field — photo, document, video and the rest — takes one of three things: a file_id of a file already on Telegram’s servers, an HTTP URL for Telegram to download, or a new file uploaded with multipart/form-data[1]. The Bot API server hands the first two to Telegram as the same kind of “remote file” string[2]. A string with a dot in it is read as a URL; anything else is decoded as a file_id[4].
When Telegram then cannot turn that string into media it can send, it reports empty media, and the Bot API translates that into wrong file identifier/HTTP URL specified[3]. It does not say which of the two went wrong, because at that point it does not know: a valid-looking file_id this bot may not use and a URL that did not give a usable file end the same way.
The close variants
The same family has more specific messages. The Bot API lowercases the first letter of each and puts Bad Request: in front[2]:
| Message | What it means |
|---|---|
wrong remote file identifier specified: Wrong string length, ...: Wrong character in the string |
The string is not a file_id at all: it was cut, or has characters a file_id never contains[4][5] |
wrong remote file identifier specified: can't unserialize it |
It decodes, but does not have the structure of a file_id[4] |
can't use file of type ... as ... |
A real file_id, sent with the method for another file type[4] |
failed to get HTTP URL content |
Telegram’s attempt to download the URL failed[2] |
wrong type of the web page content |
Telegram reached the URL, but what it got is not the expected media[2] |
invalid file HTTP URL specified: ... |
The URL itself cannot be parsed[4] |
Causes, most common first
1. A file_id from a different bot
A file_id is unique for each individual bot and can’t be transferred from one bot to another[1]. The id is real, but it belongs to someone else. The usual ways it happens:
- the database was filled by the production bot, and a test bot with its own token now reads it — or the other way round;
- the bot’s token was replaced with a new bot’s;
- the id was copied from another bot, a helper bot or a forum answer.
Check which bot the token belongs to:
curl -s "https://api.telegram.org/bot$BOT_TOKEN/getMe"
getMe returns the bot’s id and username[1]; it must be the bot that saved the file_id.
2. file_unique_id instead of file_id
Every file object has both. file_id can be used to download or reuse the file; file_unique_id is meant to stay the same over time and across bots, and can’t be used to download or reuse the file[1]. Storing both in one table and reading the wrong column gives this error, or one of the wrong remote file identifier variants.
3. The id was cut or changed on the way
A VARCHAR column shorter than the id, a log line or chat message that wrapped it, a value pasted with quotes or a newline into an environment variable. A broken id usually fails before Telegram sees it, with wrong remote file identifier specified and the reason after the colon[4][5]. Print the exact value you send, with its length, and compare it with the one you saved.
4. The right id for the wrong method
It is not possible to change the file type when resending by file_id: a video can’t be sent as a photo, a photo can’t be sent as a document[1]. sendPhoto with a video’s file_id fails with can't use file of type ... as ...[4]. Store the type next to the id and pick the method from it.
5. A URL Telegram cannot download
With a URL, Telegram’s servers download the file and send it[1] — not your server, and not your browser. A link that opens for you can still fail for them:
- it needs a login, a cookie or an
Authorizationheader; - it points at
localhost, a private address or a server that only your network can reach; - it is a share page (a cloud drive’s preview, a login redirect) that answers with HTML instead of the file.
A failed download comes back as failed to get HTTP URL content[2]; content that is not usable media as this error or wrong type of the web page content[2][3].
6. A URL Telegram does not accept for this method
Sending by URL has its own rules[1]:
- at most 5 MB for photos and 20 MB for other content;
- the file must have the correct MIME type, for example
audio/mpegforsendAudio; sendDocumentby URL currently works only for.PDFand.ZIPfiles;- for
sendVoice, the file must beaudio/oggand no more than 1 MB; voice notes of 1–20 MB are sent as files.
Telegram adds that other configurations may work but are not guaranteed[1]. For larger files, see Bad Request: file is too big.
How to fix it
Upload again with this bot, and keep the new file_id
A file_id from another bot cannot be repaired. Upload the original file once with the current bot and save the file_id from the Message it returns. Sending by file_id has no size limit[1], so the next sends cost nothing. Keep the original file somewhere, so this works again after the next token change:
# aiogram 3
from aiogram import Bot
from aiogram.exceptions import TelegramBadRequest
from aiogram.types import FSInputFile
async def send_cached_photo(bot: Bot, chat_id: int, key: str, path: str, db) -> None:
file_id = await db.get_file_id(key) # saved by this bot
if file_id:
try:
await bot.send_photo(chat_id, file_id)
return
except TelegramBadRequest as e:
if "file identifier" not in e.message:
raise
msg = await bot.send_photo(chat_id, FSInputFile(path))
await db.save_file_id(key, msg.photo[-1].file_id)
"file identifier" matches both wrong file identifier/HTTP URL specified and wrong remote file identifier specified. Resending a photo by file_id sends all of its sizes[1], so saving the last one is enough.
If several bots serve the same files, key your cache by file_unique_id, which is the same for every bot[1], and keep one file_id per bot.
Let the bot download the URL and upload it
When Telegram cannot fetch a link — behind a login, on a private network, or not the right MIME type — download it in the bot and upload it. The upload limits then apply: 10 MB for photos, 50 MB for other files[1].
aiogram’s URLInputFile streams the URL through the bot’s own HTTP session and accepts headers, so a link behind a token works[8]:
from aiogram.types import URLInputFile
await bot.send_document(
chat_id,
URLInputFile(url, headers={"Authorization": f"Bearer {api_token}"}, filename="report.xlsx"),
)
grammY’s InputFile takes a URL object and fetches it itself; a failed download throws Download failed, received HTTP status ... in your code instead of a Bot API error[12]:
import { InputFile } from "grammy";
await ctx.replyWithPhoto(new InputFile(new URL(imageUrl)));
With curl, the same is a normal upload:
curl -s "https://api.telegram.org/bot$BOT_TOKEN/sendDocument" \
-F "chat_id=$CHAT_ID" \
-F "[email protected]"
Or fix the URL
If you want Telegram to fetch it, check the link from a machine outside your network:
curl -sI "$FILE_URL"
It should answer 200 without a login, with the file’s own Content-Type (image/jpeg, application/pdf …), not text/html, and within the URL limits above[1].
How to confirm the fix
Send the stored id with the token the app uses:
curl -s "https://api.telegram.org/bot$BOT_TOKEN/sendDocument" \
--data-urlencode "chat_id=$CHAT_ID" \
--data-urlencode "document=$FILE_ID"
"ok":true means the id and the token belong together, and the problem is in how the code reads the id. The same error again means the id is another bot’s or not a file_id: run getMe, and check which column the value came from.
On Livops
- One bot, one set of file_ids. The token goes under Variables as
BOT_TOKEN; new values take effect on the next deploy. A new environment such asstagingcopies production’s variables and gets its own empty database. Give it its own test bot’s token: it then starts with no savedfile_ids and fills them with its own uploads. Copying production’s table offile_ids into staging brings this error with it. - file_ids in PostgreSQL. Add PostgreSQL under Databases, and
DATABASE_URLis written into every service in the environment. Store ids asTEXT, next to the file’s type andfile_unique_id. - Keep the originals. Files the bot must be able to upload again go to
/app/data, whose path is inDATA_DIRand which is kept across deploys and restarts;/tmpis wiped on every restart and deploy. For many or large files, use a storage bucket. See Files and data. - A link Telegram can open. A bucket is private by default and hands out temporary signed links (presigned URLs), or can be made public with a
..._PUBLIC_URLvariable. Either one gives Telegram a URL that needs no login; the URL limits above still apply. - Logs. Log the
file_id, its length and the bot’s username next to each failed send; the project’s Logs page andlivops logs <service> -f(CLI) show them.
A bot costs 19 credits a month (19,000 so’m); see Pricing.
Questions
Can two bots share a file_id?
No. A file_id is unique for each bot and cannot be transferred from one bot to another. If a second bot needs the file, it has to upload it once itself and keep the file_id that upload returns.
What is the difference between file_id and file_unique_id?
file_id is what you send and download with, and it is specific to your bot. file_unique_id stays the same over time and across bots, which makes it good for spotting duplicates, but it cannot be used to download or resend the file.
My bot worked yesterday and now every saved file_id fails. Why?
Most often the token changed: a new bot, or a test bot's token in production, or the other way round. The file_ids in your database belong to the old bot. Run getMe to see which bot the token belongs to, and re-upload the files with that bot.
Why does sending a photo by URL fail when the link opens in my browser?
Telegram's servers download the link, not your browser. A link that needs a login or cookie, points at localhost or a private network, returns an HTML page instead of the file, or has the wrong MIME type will fail there. Photos by URL are also limited to 5 MB.
How do I send a file Telegram cannot download itself?
Download it in your bot and upload it with multipart/form-data. aiogram's URLInputFile and grammY's InputFile with a URL do this for you. Uploads allow up to 10 MB for photos and 50 MB for other files.
Can I change a video into a photo by resending its file_id?
No. Telegram does not allow changing the file type when resending by file_id: a video cannot be sent as a photo and a photo cannot be sent as a document. Use the send method that matches the file's type.
Sources
- Telegram Bot API — Sending files, File, getMe, sendPhoto, sendDocument (core.telegram.org). Checked .
- Telegram Bot API server source — telegram-bot-api/Client.cpp (raw.githubusercontent.com). Checked .
- TDLib source — td/telegram/MessageQueryManager.cpp (raw.githubusercontent.com). Checked .
- TDLib source — td/telegram/files/FileManager.cpp (raw.githubusercontent.com). Checked .
- TDLib source — tdutils/td/utils/base64.cpp (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/exceptions.py (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/client/session/base.py (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/types/input_file.py (raw.githubusercontent.com). Checked .
- python-telegram-bot source — telegram/error.py (raw.githubusercontent.com). Checked .
- python-telegram-bot source — telegram/request/_baserequest.py (raw.githubusercontent.com). Checked .
- grammY source — src/core/error.ts (raw.githubusercontent.com). Checked .
- grammY source — src/types.node.ts (raw.githubusercontent.com). Checked .
- Telegraf source — src/core/network/error.ts (raw.githubusercontent.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your botRelated
- Bad Request: file is too big — Telegram bot file size limits and how to get around themBad Request: file is too big means the bot called getFile for a file over the Bot API's 20 MB download limit. Request Entity Too Large (413) is the upload side: a file uploaded over the 50 MB limit. Resend by file_id, which has no limit, compress or split the file, or run a Local Bot API Server, which downloads without a size limit and uploads up to 2000 MB.
- Telegram 400: Bad Request: not enough rights to send text messages to the chat — how to fix itBad Request: not enough rights to send text messages to the chat means the bot is in the group, but its permissions there do not allow this kind of message: the group's default permissions turn sending off for members, or the bot itself was restricted. Make the bot an administrator, or turn the permission back on; check with getChatMember for the bot's own id. In a channel the bot needs to be an administrator that can post.
- Telegram 400: Bad Request: chat not found — how to fix itThe bot asked Telegram for a chat it does not know. Either the chat_id is wrong (a typo, a channel id without its -100 prefix, a user's @username, an id cut to 32 bits), or it is right but this bot has never been in that chat: the user never pressed Start, the bot was never added to the group or channel, or the token belongs to a different bot.
- Is the Telegram Bot API free? Limits and costs in 2026Yes. Telegram charges nothing to create a bot or to call the Bot API, and bots message their users at no cost. What costs money is around it: the server the bot runs on, paid broadcasts above about 30 messages a second, and Telegram Stars when you sell digital goods. The free API has limits: about one message a second per chat, 20 a minute per group, 20 MB downloads and 50 MB uploads, more with a local Bot API server.
- Telegram bot hosting in 2026: the options comparedA Telegram bot needs a process that never stops, or a public HTTPS address for a webhook. On Livops it runs from a GitHub push for 19 credits a month (19,000 so'm). Here is how a VPS, Railway, Render, Fly.io and Vercel compare.
- aiogram bot hosting: how to deploy an aiogram 3 botAn aiogram 3 bot needs one process that never stops, the token in an environment variable, state kept outside memory and a clean exit on SIGTERM. On Livops you push a repository with bot.py and requirements.txt, and it runs for 19 credits a month (19,000 so'm), polling or webhook.
- python-telegram-bot hosting: deploying a v22 botA python-telegram-bot bot runs as one Application: run_polling() for polling, run_webhook() with the webhooks extra for a webhook. Both stop cleanly on SIGTERM. On Livops it runs from a push with bot.py and requirements.txt for 19 credits a month (19,000 so'm).
- grammY bot deploy: polling, webhooks and hostingDeploy a grammY bot as one always-on Node.js process: bot.start() for polling, or webhookCallback() behind an HTTP server, with bot.stop() on SIGTERM. On Livops a repository with grammy in package.json runs as a bot from every push, for 19 credits a month (19,000 so'm).
- Telegraf bot hosting: deploying a Telegraf 4 bot on Node.jsA Telegraf bot is one Node.js process: bot.launch() for polling, or bot.webhookCallback() behind an HTTP server for a webhook, with bot.stop() on SIGTERM. On Livops a repository with telegraf in package.json is run as a bot from every push, for 19 credits a month (19,000 so'm).
- Bad Request: failed to get HTTP URL content — Telegram bot error and how to fix itBad Request: failed to get HTTP URL content means your bot sent a photo, document or video as a URL, and Telegram's servers could not download it. The link points at localhost or a private network, needs a login, has expired, or does not answer with the file. Upload the file yourself with multipart/form-data, which aiogram, python-telegram-bot, grammY and Telegraf all support, or give Telegram a public direct link.