Skip to content
Instagram APITelegram BotPythonTutorialReel Downloader

Build an Instagram Downloader Telegram Bot in Python (2026) — Using Instagram API

October 10, 2026 · 10 min read · By AR Digital Services

In this guide, you'll build a production Telegram bot that accepts Instagram Reel, Story, and Post URLs and instantly returns a direct MP4 download button — powered by the Instagram API with lifetime credits. The entire bot fits in a single Python file.

What We're Building

  • User sends an Instagram Reel/Post link to the bot
  • Bot calls the Instagram API to extract the direct MP4 URL
  • Bot replies with the thumbnail photo and a Download MP4 inline button
  • Private posts and deleted content handled gracefully

Prerequisites

Install dependencies

pip install python-telegram-bot requests

Complete Bot Code

Save this as bot.py. Set your environment variables TELEGRAM_BOT_TOKEN and INSTAGRAM_API_KEY before running:

import os
import re
import requests
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, ContextTypes

TELEGRAM_TOKEN = os.environ["TELEGRAM_BOT_TOKEN"]
INSTAGRAM_API_KEY = os.environ["INSTAGRAM_API_KEY"]
API_BASE = "https://api.teraboxdl.site/v1/instagram"

INSTAGRAM_URL_PATTERN = re.compile(
    r"https?://(www\.)?instagram\.com/(reels?|p|tv)/[A-Za-z0-9_\-]+/?"
)

def extract_instagram_media(url: str) -> dict | None:
    """Call the Instagram API and return extracted media data."""
    try:
        resp = requests.post(
            f"{API_BASE}/reel",
            headers={"X-API-Key": INSTAGRAM_API_KEY},
            json={"url": url},
            timeout=30,
        )
        resp.raise_for_status()
        data = resp.json()
        return data["data"] if data.get("status") == "success" else None
    except Exception:
        return None

async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
    await update.message.reply_text(
        "👋 Send me any Instagram Reel or Post link and I'll "
        "extract the direct MP4 download URL for you!\n\n"
        "Powered by teraboxapi.com/instagram-api"
    )

async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
    text = update.message.text or ""
    match = INSTAGRAM_URL_PATTERN.search(text)
    
    if not match:
        await update.message.reply_text("❌ Please send a valid Instagram Reel or Post URL.")
        return

    processing_msg = await update.message.reply_text("⏳ Extracting media link...")
    
    media = extract_instagram_media(match.group(0))
    if not media:
        await processing_msg.edit_text("❌ Failed to extract media. The post may be private or deleted.")
        return

    # Build download button
    keyboard = [[InlineKeyboardButton("📥 Download MP4", url=media["video_url"])]]
    reply_markup = InlineKeyboardMarkup(keyboard)

    caption = (
        f"✅ *Instagram Media Extracted*\n\n"
        f"👤 Author: @{media.get('username', 'unknown')}\n"
        f"❤️ Likes: {media.get('like_count') or 0:,}\n"
        f"📝 {(media.get('caption') or '')[:200]}"
    )
    
    await processing_msg.delete()
    await update.message.reply_photo(
        photo=media["thumbnail"],
        caption=caption,
        parse_mode="Markdown",
        reply_markup=reply_markup,
    )

def main():
    app = ApplicationBuilder().token(TELEGRAM_TOKEN).build()
    app.add_handler(CommandHandler("start", start))
    app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
    print("Bot is running...")
    app.run_polling()

if __name__ == "__main__":
    main()

Run the Bot

export TELEGRAM_BOT_TOKEN="your_bot_token"
export INSTAGRAM_API_KEY="your_instagram_api_key"
python bot.py

Why Lifetime API Credits Are Ideal for Telegram Bots

Telegram bots have highly variable usage. Monthly subscription APIs waste credits in slow months. The Instagram API uses a lifetime credit model:

  • Buy once — credits never expire
  • Scale from the 100 free requests to ₹14,999 Mega (1M credits)
  • Credits deduct only on successful 200 OK responses
  • Private posts and failed extractions cost 0 credits

Purchase Your Instagram API Key

Sign up free: 100 requests are added to your account. Use the bot code above right away.

Related Instagram API Guides