Skip to content
Telegram BotPythonTutorial

Build a TeraBox Downloader Telegram Bot with the TeraBox API

July 19, 2026 · 10 min read · By AR Digital Services

In this guide, you'll build a fully working Telegram bot that accepts any TeraBox share link and instantly replies with a direct download URL — using python-telegram-bot and the TeraBox API. No cookies, no browser — just a clean HTTP POST.

What You'll Need

Project Setup

mkdir terabox-bot && cd terabox-bot
pip install python-telegram-bot requests python-dotenv

Create a .env file:

TELEGRAM_TOKEN=your_bot_token_here
TERABOX_API_KEY=tbx_your_key_here

Full Bot Code — bot.py

import os
import re
import requests
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, ContextTypes

load_dotenv()

TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
TERABOX_API_KEY = os.getenv("TERABOX_API_KEY")

TERABOX_PATTERN = re.compile(
    r"https?://(www.)?(terabox.com|1024terabox.com|4funbox.com)/s/\S+"
)

async def start(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
    await update.message.reply_text(
        "👋 Send me any TeraBox share link and I'll give you a direct download URL!"
    )

async def handle_link(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
    text = update.message.text or ""
    match = TERABOX_PATTERN.search(text)

    if not match:
        await update.message.reply_text("❌ No TeraBox link detected. Please send a valid share link.")
        return

    share_url = match.group(0)
    msg = await update.message.reply_text("⏳ Fetching your link…")

    try:
        res = requests.post(
            "https://api.teraboxdl.site/v1/api",
            headers={"X-API-Key": TERABOX_API_KEY},
            json={"url": share_url},
            timeout=15
        )
        data = res.json()
    except Exception as e:
        await msg.edit_text(f"⚠️ Network error: {e}")
        return

    if not data.get("ok"):
        await msg.edit_text(f"❌ API error: {data.get('error', 'Unknown error')}")
        return

    reply = (
        f"✅ *{data['file_name']}*\n"
        f"📦 Size: {round(data['size'] / 1_048_576, 1)} MB\n\n"
        f"[⬇️ Direct Download]({data['download_url']})\n"
        f"[▶️ HLS Stream]({data['stream_url']})"
    )
    await msg.edit_text(reply, parse_mode="Markdown", disable_web_page_preview=True)

if __name__ == "__main__":
    app = ApplicationBuilder().token(TELEGRAM_TOKEN).build()
    app.add_handler(CommandHandler("start", start))
    app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_link))
    print("Bot is running…")
    app.run_polling()

Run the Bot

python bot.py

Send your bot a TeraBox link like https://terabox.com/s/1LpQ... and it will reply with the direct download URL and HLS stream link within a second.

Handling 429 Rate Limit Errors

If you hit HTTP 429, your daily quota is exhausted. Add retry logic or upgrade your plan for more capacity.

Start Building Your Bot Today

Get a TeraBox API key from ₹1,999/month. Instant activation.

Buy API Key →