Telegram· 5 min read

Send files with the Telegram Bot API: size limits and file_id


A Telegram bot can send a file three ways. It can use a file_id Telegram already stores, an HTTP URL Telegram downloads, or a multipart/form-data upload. Each has its own ceiling. A file_id has none. A URL takes 5 MB for photos and 20 MB for everything else. An upload takes 10 MB for photos and 50 MB for other files. Downloading with getFile stops at 20 MB. These figures come from the “Sending files” section of the Bot API reference, at Bot API 10.3 of August 24, 2026 (accessed 2026-11-04).

Route Photos Other files Telegram’s note
file_id No limit No limit “There are no limits for files sent this way.”
HTTP URL 5 MB 20 MB “Telegram will download and send the file.”
multipart/form-data upload 10 MB 50 MB “in the usual way that files are uploaded via the browser”
getFile download 20 MB 20 MB “For the moment, bots can download files of up to 20MB in size.”

The reference has no curl or Python samples for file sending. Every example below was written for this post against the rules on that page, so treat none of it as Telegram’s sample.

Upload a file with multipart/form-data

Upload when the file lives on your server and Telegram has never seen it. curl -F builds the multipart body, and the @ prefix reads the file from disk.

curl -F chat_id=CHAT_ID \
  -F [email protected] \
  "https://api.telegram.org/botBOT_TOKEN/sendDocument"

The same call in Python with the standard library only. It builds the multipart body by hand and prints the two IDs Telegram returns for the document.

# send_document.py  usage: TELEGRAM_BOT_TOKEN=BOT_TOKEN python send_document.py CHAT_ID PATH
import json
import mimetypes
import os
import sys
import urllib.error
import urllib.request
import uuid

API = "https://api.telegram.org/bot" + os.environ["TELEGRAM_BOT_TOKEN"]


def multipart(fields, files):
    boundary = uuid.uuid4().hex
    body = b""
    for name, value in fields.items():
        body += (
            f'--{boundary}\r\nContent-Disposition: form-data; name="{name}"\r\n\r\n'
            f"{value}\r\n"
        ).encode()
    for name, path in files.items():
        ctype = mimetypes.guess_type(path)[0] or "application/octet-stream"
        with open(path, "rb") as f:
            data = f.read()
        body += (
            f'--{boundary}\r\nContent-Disposition: form-data; name="{name}"; '
            f'filename="{os.path.basename(path)}"\r\nContent-Type: {ctype}\r\n\r\n'
        ).encode() + data + b"\r\n"
    body += f"--{boundary}--\r\n".encode()
    return body, f"multipart/form-data; boundary={boundary}"


def call(method, fields, files=None):
    if files:
        body, ctype = multipart(fields, files)
    else:
        body, ctype = json.dumps(fields).encode(), "application/json"
    req = urllib.request.Request(f"{API}/{method}", data=body, headers={"Content-Type": ctype})
    try:
        with urllib.request.urlopen(req, timeout=120) as r:
            return json.load(r)
    except urllib.error.HTTPError as e:
        return json.load(e)  # Telegram puts the error in a JSON body


if __name__ == "__main__":
    chat_id, path = sys.argv[1], sys.argv[2]
    result = call("sendDocument", {"chat_id": chat_id}, {"document": path})
    if not result["ok"]:
        sys.exit(f"{result.get('error_code')}: {result.get('description')}")
    doc = result["result"]["document"]
    print("file_id:", doc["file_id"])
    print("file_unique_id:", doc["file_unique_id"])

Every response carries a Boolean ok, which is why the script checks it before reading result. The 120-second timeout is the script’s choice, sized for a 50 MB upload on a slow link. Telegram documents no client timeout.

Send by URL

A URL saves you the upload, with two catches. First, “When sending by URL the target file must have the correct MIME type.” A server that labels a JPEG as application/octet-stream breaks the send. Second, for sendDocument, “sending by URL will currently only work for .PDF and .ZIP files.” Any other document type has to be uploaded or resent by file_id.

curl -X POST "https://api.telegram.org/botBOT_TOKEN/sendPhoto" \
  -H "Content-Type: application/json" \
  -d '{"chat_id": "CHAT_ID", "photo": "https://YOUR_DOMAIN/images/product.jpg"}'

Voice notes by URL have their own rule: “the file must have the type audio/ogg and be no more than 1MB in size.” Telegram sends voice files of 1 to 20 MB as plain files.

Reuse a file with file_id

Once a file has gone through Telegram, send its file_id instead of the bytes. The reference marks this route “recommended” on sendPhoto, and the size limits don’t apply. Take the file_id from the Message that the send method returns, or from an incoming message.

curl -X POST "https://api.telegram.org/botBOT_TOKEN/sendDocument" \
  -H "Content-Type: application/json" \
  -d '{"chat_id": "CHAT_ID", "document": "FILE_ID"}'

Three rules from the reference limit reuse. A file_id “is unique for each individual bot and can’t be transferred from one bot to another.” You can’t change the file type when you resend, so a document’s file_id won’t go out through sendPhoto. Thumbnails can’t be resent at all. The reference doesn’t say whether a file_id expires, so keep the original file or its source URL as a fallback.

file_unique_id serves a different job. It is “supposed to be the same over time and for different bots,” but it “Can’t be used to download or reuse the file.” Use it as the dedupe key in your database, and keep file_id for sending.

For photos, Message.photo is an array of PhotoSize objects, one per available size. The reference doesn’t say which one to reuse. Taking the largest entry is the sensible reading of the field types.

Pick the right method

Method What the reference says
sendPhoto At most 10 MB; width plus height up to 10000; aspect ratio at most 20
sendDocument Any file type up to 50 MB; has disable_content_type_detection
sendVideo Clients support MPEG4, other formats “may be sent as Document”; up to 50 MB; has supports_streaming
sendAnimation Animation files up to 50 MB
sendAudio For audio “you want Telegram clients to display them in the music player”
sendMediaGroup 2 to 10 photos, live photos, videos, documents or audios as one album

The 50 MB ceilings carry the phrase “this limit may be changed in the future”. Keep them in config, where a change is one edit. Thumbnails, where a method accepts one, should be JPEG, under 200 kB and at most 320 pixels on each side.

Send an album with sendMediaGroup

In sendMediaGroup, media is a JSON-serialized array of InputMedia objects. Each media field takes a file_id, a URL, or attach://<name>, which points at a multipart part of that name.

curl -F chat_id=CHAT_ID \
  -F 'media=[{"type":"photo","media":"attach://p1"},{"type":"photo","media":"attach://p2"}]' \
  -F [email protected] \
  -F [email protected] \
  "https://api.telegram.org/botBOT_TOKEN/sendMediaGroup"

“Documents and audio files can be only grouped in an album with messages of the same type.” The response is an array of Message objects, one per item, so store a file_id from each.

Download a file with getFile

getFile takes a file_id and returns a File object with a file_path. You then fetch https://api.telegram.org/file/bot<token>/<file_path>.

curl "https://api.telegram.org/botBOT_TOKEN/getFile?file_id=FILE_ID"
curl -o downloaded.bin "https://api.telegram.org/file/botBOT_TOKEN/FILE_PATH"

The link is “guaranteed” valid for at least one hour. Call getFile again when it expires. The download may lose the original file name and MIME type. Telegram tells you to save both when the File object arrives. file_size can exceed 2^31, so store it in a 64-bit integer. The same expiring-link pattern on WhatsApp is in download WhatsApp media before the URL expires.

Raise the limits with a local Bot API server

Telegram publishes the Bot API server source code as tdlib/telegram-bot-api (accessed 2026-11-04). In --local mode a bot can download files without a size limit and upload files up to 2000 MB. It can also upload by local path with the file:// URI scheme. file_path then holds an absolute local path. The README lists these features under local mode and doesn’t describe the limits without it.

curl "https://api.telegram.org/botBOT_TOKEN/logOut"
telegram-bot-api --api-id=API_ID --api-hash=API_HASH --local

--api-id and --api-hash are the only required options, and the server listens on port 8081 unless you set --http-port. Call logOut on the cloud server first. The reference warns that otherwise “there is no guarantee that the bot will receive updates”. After the call you can’t log back in to the cloud Bot API for 10 minutes. Then send requests to your own server’s address instead of https://api.telegram.org.

Local mode also lifts webhook restrictions: plain HTTP, any local IP and any port. If you move the webhook along with the bot, Telegram webhooks with secret_token covers setWebhook. The file-sending sections state no rate limit of their own. If a run of sends starts failing with 429, see Telegram Bot API limits: 429 errors and retry_after.

Z-API Omni team