cd /news/generative-ai/building-a-multi-model-ai-video-imag… · home › topics › generative-ai › article
[ARTICLE · art-176553] src=dev.to ↗ pub= topic=generative-ai verified=true sentiment=↑ positive

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

A developer built Wan3 Studio, a pay-as-you-go web workspace that routes requests across 11 generative video and image models—including Wan 3.0, Veo 3.1, Sora 2 and Seedance 2.5—from a single Docker container running FastAPI, SQLite in WAL mode and Stripe Checkout on an ARM64 VPS behind Cloudflare Tunnel. To prevent charging users for failed renders, the app runs credit deductions and idempotent refunds inside atomic BEGIN IMMEDIATE transactions, using a refunded flag to guarantee race-free accounting without external locks. The developer also recommends two-stage generation, using image models such as Seedream 5.5 or Flux 2 Pro to produce first frames before video generation, to improve consistency.

recommendation

Wrap credit deduction and refunds in atomic BEGIN IMMEDIATE transactions with an idempotency flag so failed async renders are refunded exactly once, even under concurrent retries.

more in playbook: Running AI in production
by read2 min views8 publishedNov 26, 2026

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.

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.

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

httpx async upstream routing + itsdangerous signed HTTP-only session cookiesWAL mode with BEGIN IMMEDIATE transactions for race-free credit deduction and idempotent order fulfillment 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:

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

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

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

── more in #generative-ai 4 stories · sorted by recency
── more on @wan3 studio 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/building-a-multi-mod…] indexed:0 read:2min 2026-11-26 · —