Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

Building a Multi-Model AI Video & Image Studio (Wan 3.0, Veo 3.1, Sora 2 & Seedance 2.5) with FastAPI, SQLite & Stripe

If you have ever tried building short-form videos, product commercials, or image-to-video prototypes with modern generative video models, you have probably run into the same friction I did: every flagship model lives beh

Building a Multi-Model AI Video & Image Studio (Wan 3.0, Veo 3.1, Sora 2 & Seedance 2.5) with FastAPI, SQLite & Stripe

Wan3 Studio AI Video & Image Workspace

If you have ever tried building short-form videos, product commercials, or image-to-video prototypes with modern generative video models, you have probably run into the same friction I did: every flagship model lives behind a different monthly subscription.

  • Alibaba Wan 3.0 & Wan 3.0 Prime shine at smooth camera trajectories and physics
  • Google Veo 3.1 & Veo 3.1 Fast deliver studio lighting and synchronized native audio
  • OpenAI Sora 2 excels at imaginative multi-beat visual storytelling
  • ByteDance Seedance 2.5 and Vidu Q3 Pro handle e-commerce product shots and stylized anime animation
  • Seedream 5.5, Flux 2 Pro, and GPT Image 1 are essential for generating crisp first frames before animating

Instead of paying $100+/month across five separate portals, I built Wan3 Studioβ€”a lightweight, pay-as-you-go web workspace backed by a single Docker container (FastAPI + SQLite WAL + Stripe Checkout) that lets creators switch across all 11 flagship video and image models with one non-expiring credit balance.

Architecture Overview

I intentionally kept the stack minimal so the entire production app runs smoothly on a single ARM64 VPS behind Cloudflare Tunnel:

  • Backend: FastAPI + httpx async upstream routing + itsdangerous signed HTTP-only session cookies
  • Database: SQLite in WAL mode with BEGIN IMMEDIATE transactions for race-free credit deduction and idempotent order fulfillment
  • Frontend: Server-rendered HTML landing pages (for clean Google/Bing SEO indexing) + vanilla ES6 JS + locally hosted faststart H.264 preview loops
  • Payments: Stripe Checkout (one-time USD credit packs, zero subscriptions) with both return-URL verification and HMAC-verified webhook fulfillment

Designing Race-Free Credits & Automatic Failure Refunds

AI video generation is asynchronous and occasionally fails upstream (safety filter rejections, provider timeouts, or overloaded queues). Charging users when a render fails is the fastest way to lose trust.

To make credit accounting bulletproof in SQLite without external Redis locks, every deduction and refund runs inside an atomic BEGIN IMMEDIATE transaction with an idempotency flag (refunded = 0 -> 1):

def deduct_credits(user_id: int, cost: int) -> tuple[bool, int]:
    now = int(time.time())
    with get_conn() as conn:
        conn.execute("BEGIN IMMEDIATE")
        row = conn.execute("SELECT credits FROM users WHERE id = ?", (user_id,)).fetchone()
        if not row or row["credits"] < cost:
            conn.execute("ROLLBACK")
            return False, (row["credits"] if row else 0)
        new_bal = row["credits"] - cost
        conn.execute("UPDATE users SET credits = ?, updated_at = ? WHERE id = ?", (new_bal, now, user_id))
        conn.execute("COMMIT")
        return True, new_bal


def refund_task_credits(task_id: str) -> bool:
    """Idempotently refund 100% of credits if an upstream video render fails."""
    now = int(time.time())
    with get_conn() as conn:
        conn.execute("BEGIN IMMEDIATE")
        t = conn.execute("SELECT user_id, cost_credits, refunded FROM tasks WHERE id = ?", (task_id,)).fetchone()
        if not t or t["refunded"] or t["cost_credits"] <= 0:
            conn.execute("ROLLBACK")
            return False
        conn.execute("UPDATE tasks SET refunded = 1, updated_at = ? WHERE id = ?", (now, task_id))
        conn.execute(
            "UPDATE users SET credits = credits + ?, updated_at = ? WHERE id = ?",
            (t["cost_credits"], now, t["user_id"]),
        )
        conn.execute("COMMIT")
        return True

This guarantees two invariants:

  1. Concurrent requests can never drive a user's credit balance negative.
  2. Repeated status polls on a failed job can never double-refund credits.

First-Frame-to-Video Workflow (Image β†’ Video)

One pattern that dramatically improves AI video consistency is two-stage generation:

  1. Generate a high-detail keyframe using Seedream 5.5 or Flux 2 Pro in AI Image mode (only 5–6 credits per image).
  2. Click Animate β†’ Video to pass that exact frame into Wan 3.0, Google Veo 3.1, or Image-to-Video so character geometry, lighting, and product branding stay locked across frames.

Model Comparison Cheatsheet

Model Provider Best Use Case
Wan 3.0 / Wan 3.0 Prime Alibaba Wan Smooth camera movement, realistic street & cinematic shots
Veo 3.1 / Veo 3.1 Fast Google DeepMind Commercial product lighting + synchronized native audio
Sora 2 OpenAI Multi-beat narrative storytelling & imaginative physics
Seedance 2.5 ByteDance E-commerce ads, lookbooks, stable human motion
Vidu Q3 Pro Vidu Stylized anime shorts & consistent character animation
Seedream 5.5 / Flux 2 Pro ByteDance / BFL High-resolution first frames & editorial portraits

Try It Out & Open Prompt Library

Happy to answer questions about FastAPI async polling, Stripe webhook verification without heavy SDKs, or video model prompt engineering in the comments!

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.