Genbase - AI Video & Image Generator with x402

This guide will help you understand Genbase, an AI video and image generation platform powered by x402 open payment standard for programmatic payments.

This application showcases x402, the open payment standard that enables services to charge for access to their APIs directly over HTTP. It uses the HTTP 402 Payment Required status code to allow clients to programmatically pay for video generation without accounts, sessions, or credential management.


Why Use x402?

This application demonstrates how x402 addresses key limitations of existing payment systems:

Traditional payment problems:

  • • High fees and friction with credit cards and fiat payment processors
  • • Incompatibility with machine-to-machine payments
  • • Lack of support for micropayments
  • • Account creation and authentication overhead

x402 solutions:

  • Low fees: ~$0.001-0.01 gas fees on Base L2
  • 🤖 Machine-friendly: AI agents can pay autonomously
  • 💰 Micropayments: Pay $0.02-0.2 per generation (video/image)
  • 🚫 No accounts: Just connect your Web3 wallet

Who is this for?

Developers: Learn how to integrate x402 into your own applications for programmatic payments.
Users: Generate AI videos with pay-per-use pricing - no subscriptions required.
AI Agents: Demonstrate how autonomous agents can pay for API access programmatically.

What Can You Build?

This application showcases one use case, but x402 enables many more:

  • API services paid per request (demonstrated here with video generation)
  • AI agents that autonomously pay for API access
  • Paywalls for digital content
  • Microservices monetized via microtransactions
  • Proxy services that aggregate and resell API capabilities

In this app specifically:

  • 🎬 Pay $0.2 USDC to generate AI videos using Sora 2 (10-15 seconds)
  • Pay $0.01-0.15 USDC to generate AI videos using xAI Imagine (1-15 seconds, flexible)
  • 🖼️ Pay $0.02 USDC to generate AI images using GPT Image
  • 🆓 Free status queries to check progress
  • 📊 Real-time progress tracking with automatic updates
  • 💾 Automatic history of all your generations

How Does It Work?

High-Level Flow

1. User Request
2. 402 Payment Required Response
3. Wallet Signs Payment
4. Request with Payment Header
5. Payment Verification
6. Video Generation Starts
7. Free Status Polling (no payment)
8. Video Completed & Auto-play

⚠️ Important: Content Policy Notice

Your prompts may violate OpenAI's content policy, which could result in video generation failure. This includes prompts containing unsafe content such as violence, adult content, minors, etc.

If your video fails due to policy violations and you need a refund, please contact: contact@genbase.fun with your Video ID and wallet address.

Creating a Video with Sora 2 (Paid - $0.2 USDC)

// Frontend makes request
const response = await payingFetch("/api/video/create-sora2", {
  method: "POST",
  body: JSON.stringify({
    prompt: "A cat playing piano in a jazz club",
    model: "sora-2",
    seconds: "10",
    size: "1280x720"
  })
});

// Server middleware intercepts
// Returns: 402 Payment Required + payment info

// payingFetch automatically:
// - Signs payment with wallet
// - Retries with Authorization header
// - Returns final response

Creating an Image with GPT Image (Paid - $0.02 USDC)

// Frontend makes request
const response = await payingFetch("/api/image/create", {
  method: "POST",
  body: JSON.stringify({
    prompt: "A cute cat wearing sunglasses, digital art"
  })
});

// Server middleware intercepts
// Returns: 402 Payment Required + payment info

// payingFetch automatically:
// - Signs payment with wallet
// - Retries with Authorization header
// - Returns final response

Creating a Video with xAI Imagine (Paid - $0.01 USDC/second)

// Frontend makes request
const response = await payingFetch("/api/video/create-xai", {
  method: "POST",
  body: JSON.stringify({
    prompt: "A cat walking on a beach at sunset",
    duration: 5,              // 1-15 seconds
    aspectRatio: "16:9",      // 16:9, 9:16, 1:1, 4:3, 3:4
    resolution: "720p",       // 480p or 720p
    mode: "text-to-video"     // text-to-video, image-to-video, video-to-video
  })
});

// Payment: $0.05 USDC (5 seconds × $0.01)
// Flexible duration - pay only for what you need!

// Server middleware intercepts
// Returns: 402 Payment Required + payment info

// payingFetch automatically:
// - Signs payment with wallet
// - Retries with Authorization header
// - Returns final response

How to Use Genbase

Simple Steps to Generate Videos & Images:

  1. 1. Connect Wallet - Click "Connect Wallet" and approve MetaMask connection
  2. 2. Get Test USDC - Visit Coinbase Faucet to get free testnet USDC
  3. 3. Select Model - Choose Sora 2, xAI Imagine (video), or GPT Image (image)
  4. 4. Enter Prompt - Describe what you want to create
  5. 5. Pay & Create - Pay $0.01-0.2 USDC and sign the transaction
  6. 6. Watch Progress - Status updates automatically every 5 seconds
  7. 7. Enjoy Result - Video plays or image displays automatically when complete!

All your generated videos and images are automatically saved to your browser's local storage, so you can easily re-query them later from the History panel.

API Reference

Genbase provides three AI generation endpoints: Sora 2 (video), xAI Imagine (video), and GPT Image (image).

🎬 POST /api/video/create-sora2

Create AI videos using OpenAI's Sora 2 model (requires payment: $0.2 USDC)

Request Body:

{
  "prompt": "A cat playing piano in a jazz club",
  "model": "sora-2",           // or "sora-2-pro"
  "seconds": "10",             // "10", "15", or "25" (pro only)
  "size": "1280x720"           // "1280x720", "720x1280", "1792x1024", "1024x1792"
}

Response (200 OK):

{
  "success": true,
  "data": {
    "id": "sora-2:task_01j9abc123xyz456def789ghi0",
    "status": "pending",           // "pending" | "processing" | "Ready" | "failed"
    "video_url": null,             // Available when status is "Ready"
    "thumbnail_url": null
  }
}

Models:

  • sora-2 - Standard quality, 10-15 seconds
  • sora-2-pro - Enhanced quality, up to 25 seconds

⚡ POST /api/video/create-xai

Create AI videos using xAI's Grok Imagine model (requires payment: $0.01 USDC per second)

Request Body:

{
  "prompt": "A cat walking on a beach at sunset",
  "duration": 5,                   // 1-15 seconds
  "aspectRatio": "16:9",           // "16:9", "9:16", "1:1", "4:3", "3:4"
  "resolution": "720p",            // "480p" or "720p"
  "mode": "text-to-video",         // "text-to-video", "image-to-video", "video-to-video"
  "referenceImage": "https://..."  // Optional: for image-to-video mode
}

Response (200 OK):

{
  "success": true,
  "data": {
    "id": "xai_request_123",
    "status": "pending",
    "provider": "xai",
    "duration": 5,
    "message": "Video generation started. Use the query endpoint to check status."
  }
}

Features:

  • Flexible Duration: 1-15 seconds (pay per second)
  • Multiple Modes: Text-to-video, image-to-video, video-to-video
  • Resolution Options: 480p or 720p
  • Aspect Ratios: 16:9, 9:16, 1:1, 4:3, 3:4
  • Model: grok-imagine-video

Pricing Examples:

  • • 5 seconds = $0.05 USDC
  • • 10 seconds = $0.10 USDC
  • • 15 seconds = $0.15 USDC

🖼️ POST /api/image/create

Create AI images using GPT Image (requires payment: $0.02 USDC)

Request Body:

{
  "prompt": "A cute cat wearing sunglasses, digital art",
  "referenceImage": "data:image/png;base64,..."  // Optional: for image-to-image
}

Response (200 OK):

{
  "success": true,
  "data": {
    "id": "img_abc123",
    "url": "https://example.com/generated-image.png",
    "status": "completed"
  }
}

Features:

  • Fast Generation: ~30-90 seconds
  • High Quality: Professional-grade images
  • Image-to-Image: Optional reference image support
  • Affordable: 10x cheaper than video generation

🔍 GET /api/video/query

Query Sora 2 video generation status (FREE - no payment required)

Request Parameters:

?id=sora-2:task_01j9abc123xyz456def789ghi0

Response:

{
  "success": true,
  "data": {
    "id": "sora-2:task_01j9abc123xyz456def789ghi0",
    "status": "Ready",
    "video_url": "https://...",
    "detail": {
      "input": {
        "prompt": "Original prompt",
        "model": "sora-2",
        "duration": "10",
        "size": "1280x720"
      }
    }
  }
}

Status Values:

  • pending - Waiting to process (Progress: 20%)
  • processing - Generating video (Progress: 50%)
  • video_upsampling - Enhancing quality (Progress: 80%)
  • Ready or completed - Ready to watch (Progress: 100%)
  • failed - Generation failed

🔍 GET /api/video/query-xai

Query xAI Imagine video generation status (FREE - no payment required)

Request Parameters:

?id=xai_request_123

Response:

{
  "success": true,
  "data": {
    "id": "xai_request_123",
    "status": "completed",
    "video_url": "https://vidgen.x.ai/video.mp4",
    "url": "https://vidgen.x.ai/video.mp4",
    "provider": "xai",
    "duration": 5,
    "model": "grok-imagine-video"
  }
}

Status Values:

  • pending - Waiting to process
  • completed - Video ready (when video.url exists)
  • failed - Generation failed

🔍 GET /api/image/query

Query image generation status (FREE - no payment required)

Request Parameters:

?id=abc123xyz456def789ghi012jkl345-mn6op7

Response:

{
  "success": true,
  "data": {
    "id": "abc123xyz456def789ghi012jkl345-mn6op7",
    "status": "completed",         // Normalized from "Ready"
    "image_url": "https://...",    // Direct image URL
    "result": {
      "sample": "https://..."
    }
  }
}

💰 Pricing Comparison

Sora 2 Video

$0.20

USDC per video

xAI Imagine

$0.01/s

USDC per second (1-15s)

GPT Image

$0.02

USDC per image

Status Query

FREE

No payment required

Features

Video Generation (Sora 2)

  • 🌟 Sora 2 & Sora 2 Pro - OpenAI's advanced models
  • ⏱️ Duration: 10-25 seconds (model dependent)
  • 📐 Multiple sizes: 1280x720, 720x1280, 1792x1024, 1024x1792
  • ✨ Enhanced quality and realism
  • 🎬 Professional-grade video output
  • 💰 $0.20 USDC per video

Video Generation (xAI Imagine)

  • ⚡ xAI Grok Imagine - Fast generation
  • ⏱️ Flexible duration: 1-15 seconds
  • 📐 Multiple aspect ratios: 16:9, 9:16, 1:1, 4:3, 3:4
  • 🎨 Resolution: 480p or 720p
  • 🖼️ Image-to-video & video-to-video support
  • � $0.01 USDC per second (pay what you use)

Image Generation (GPT Image)

  • 🖼️ GPT Image model
  • 💰 10x cheaper than video
  • ⚡ Fast generation time (~30-90s)
  • 🎨 High-quality digital art
  • 📸 Perfect for quick iterations
  • 💵 $0.02 USDC per image

Free Status Queries

  • 🆓 Completely free - no payment needed
  • 🔄 Auto-polling every 5 seconds
  • 📊 Progress bar: 20% → 50% → 80% → 100%
  • 🎥 Auto-play when complete

Video History

  • 💾 Auto-save all generated videos
  • 🔍 Click to quickly re-query
  • 📅 Shows creation time & parameters
  • 🗑️ Clear all history button
  • 📱 Stored in browser localStorage

Wallet Integration

  • 🦊 MetaMask and other Web3 wallets
  • 🔗 Auto-connect and network switching
  • 💰 Real-time balance display
  • 🔐 Secure signing flow

FAQ

Q: Why is querying free?

A: Querying doesn't consume AI resources, so we made it free to improve UX. This demonstrates x402's flexibility - you can set different prices for different operations.

Q: How long does generation take?

A:

  • • Sora 2 Video: ~3-10 minutes
  • • Sora 2 Pro Video: ~5-15 minutes (higher quality, longer videos)
  • • xAI Imagine Video: ~2-5 minutes (faster generation)
  • • GPT Image: ~30-90 seconds
  • • Time varies based on prompt complexity and server load

Q: Why use Base instead of Ethereum mainnet?

A: Base offers:

  • ⚡ Low gas fees (~$0.001-0.01 vs $1-10 on Ethereum)
  • 🚀 Fast confirmations (~2 seconds)
  • 🔐 Ethereum-level security (Base is an Ethereum L2)
  • 💰 Native USDC support

Q: Which wallets are supported?

A: Any EIP-1193 compatible wallet:

  • • MetaMask ✅
  • • Coinbase Wallet ✅
  • • Rainbow Wallet ✅
  • • Trust Wallet ✅
  • • WalletConnect wallets ✅

Q: What's the difference between Sora 2 and xAI Imagine?

A:

  • Sora 2: Fixed price ($0.20), 10-15s duration, higher quality, professional output
  • xAI Imagine: Pay-per-second ($0.01/s), 1-15s flexible duration, faster generation, more aspect ratios
  • Use Sora 2 for high-quality professional videos
  • Use xAI Imagine for quick iterations, short clips, or when you need specific aspect ratios

Ready to create AI videos? 🎬

Start using Genbase now and experience pay-per-use AI video generation!