๐ŸŽจ AI Image Generation Telegram Bot

Production-ready AI-as-a-Service with monetization

โšก Deployed (Demo paused) Built: December 2024 ยท Updated 2025
โš™๏ธ Scalable Design | Cost-aware GPU usage

๐Ÿ“‹ Project Overview

Full-stack Telegram bot providing AI image generation as a paid service. Built with SDXL Turbo on L40 GPU, featuring credit-based pricing, payment integration, and multi-tier quality options.

๐Ÿ”— View on GitHub

๐Ÿ’ฐ Pricing Tiers

Starter

$1.20
100 Credits
~100 images

Pro

$4.80
500 Credits
~500 images

Power

$8.40
1000 Credits
~1000 images

๐Ÿ’ณ Payment via Telegram Stars | Instant credit top-up | Referral bonuses available

๐Ÿ› ๏ธ Technology Stack

BackendPython, python-telegram-bot
AI ModelSDXL Turbo (Stable Diffusion XL)
GPUNVIDIA L40 (48GB VRAM)
DeploymentRailway (Bot) + VPS (GPU Inference)
NetworkingNgrok Tunnel
PaymentTelegram Stars API
State ManagementIn-memory cache (prototype) โ†’ Planned: PostgreSQL

โšก Key Features

  • โšก 4-second generation time (SDXL Turbo)
  • ๐Ÿ’Ž Credit-based monetization ($0.01-0.12 per image)
  • ๐Ÿ“Š 3 quality tiers: Standard (512x512), HD (1024x1024), 4K (2048x2048)
  • ๐Ÿ’ฐ Telegram Stars payment integration
  • ๐ŸŽ Referral system (+20 credits per referral)
  • ๐ŸŽจ 7 pre-built style presets (anime, cyberpunk, pixel, fantasy, etc.)
  • ๐Ÿ‘ค Admin credit management system
  • ๐Ÿ”’ Rate limiting per user + prompt validation
  • ๐Ÿ“ˆ Break-even: ~50 images/day covers GPU rental cost

๐ŸŽจ Bot Interface & Sample Outputs

๐Ÿ“ฑ User Interface

Bot Main Interface
Main Menu L40 GPU status indicator, credit balance display, quality tier selection (Standard/HD/4K)
Payment System
Payment Packages Telegram Stars integration with instant credit delivery

๐Ÿ–ผ๏ธ Generated Images

Generated Robot Warrior
Sample Output Prompt: "a futuristic robot warrior" | โšก 4 seconds | ๐Ÿ“ฑ Standard Quality (512x512)
Generated Images Gallery
30+ Diverse Outputs Robots, mechs, landscapes, anime characters, cyberpunk scenes, nature, architecture, abstract art
๐Ÿ“ธ Visual Proof: Screenshots show actual production bot with working payment system, credit management, and real-time L40 GPU status. All images generated in 4 seconds using SDXL Turbo model.

๐Ÿšง Challenges & Solutions

Challenge 1: Docker conflicts on VPS

โœ… Solution: Deployed Python directly without containerization
๐Ÿ’ก Learning: Sometimes simple solutions work better than complex ones

Challenge 2: Secure API communication between Railway and VPS

โœ… Solution: Ngrok tunnel with environment variable URL management
๐Ÿ’ก Learning: Environment variables protect sensitive endpoints

Challenge 3: 35 deployment iterations to production

โœ… Solution: Systematic debugging of timeouts, payload limits, connection drops
๐Ÿ’ก Learning: Persistence and methodical error tracking leads to success

Challenge 4: Payment system integration

โœ… Solution: Telegram Stars API with invoice generation and webhook handling
๐Ÿ’ก Learning: Platform-native payment systems reduce friction

๐Ÿ“Š Results & Impact

35Deployment Iterations
4 secondsGeneration Time
10+ (family + friends)Users Tested
30+ diverse outputsImages Generated
โšก Scale Capability: Designed to scale to 100+ concurrent users with queueing, rate limits, and load balancing.

๐Ÿ’ป Code Highlights

# Key Functions from bot.py (~250 lines)

async def generate_handler(update, context):
    """Main image generation with quality tiers"""
    quality = context.user_data.get('quality', 'standard')
    required_credits = QUALITY_TIERS[quality]['credits']

    # Credit check
    if user_credits.get(user_id, 0) < required_credits:
        return await show_buy_options()

    # Generate with SDXL Turbo (4 seconds)
    response = requests.post(
        f"{GPU_API}/generate",
        json={"prompt": prompt, "size": QUALITY_TIERS[quality]['size']}
    )

    # Deduct credits and send image
    user_credits[user_id] -= required_credits
    await update.message.reply_photo(photo=response.content)

async def successful_payment_callback(update, context):
    """Handle Telegram Stars payments"""
    payload = update.message.successful_payment.invoice_payload
    credits = int(payload.split('_')[1])
    user_credits[user_id] += credits

    await update.message.reply_text(
        f"โœ… Payment Successful!\n๐Ÿ’Ž +{credits} credits added!"
    )

๐Ÿ”‘ Key Functions

  • start() - User onboarding with referral tracking
  • generate_handler() - Main image generation with quality selection
  • successful_payment_callback() - Credit purchase processing
  • button_handler() - Interactive menu system

๐Ÿš€ What I'm Building Next

Exploring GPU SaaS infrastructure, AI automation systems, and scalable inference platforms.
Open to collaborations, technical roles, and startup opportunities.