An autonomous AI video generation platform that combines Vercel Workflow DevKit, x402 micropayments, and Coinbase Developer Platform to create AI-generated UGC videos with pay-per-use. The user types in a topic they want to make content on, the agent searches the web, creates a script based on its findings and generates the content using x402 to call and uses the tools and services it needs to complete the task.
π Live Demo: https://x402ugc.vercel.app/
π¦ Repository: https://github.com/Must-be-Ash/content-agent
This application enables users to generate AI-powered video content by simply entering a topic. The system automatically:
- π Searches the web for relevant information (Firecrawl)
- π Generates a video script using GPT-4o
- π₯ Creates a video using Genbase AI video generation
- π° Handles micropayments via x402 protocol on Base (USDC)
Key Innovation: Hybrid client-server architecture that combines deterministic workflow orchestration with interactive x402 micropayment protocol.
- Node.js 18+
- pnpm (recommended)
- Coinbase Developer Platform account
- OpenAI API key
- Firecrawl API key
# Clone repository
git clone https://github.com/Must-be-Ash/content-agent.git
cd content-agent
# Install dependencies
pnpm install
# Set up environment variables
cp .env.example .env.local
# Edit .env.local with your API keys# CDP (Coinbase Developer Platform)
NEXT_PUBLIC_CDP_PROJECT_ID=your_cdp_project_id
# Firecrawl x402 API
FIRECRAWL_API_BASE_URL=https://api.firecrawl.dev/v2/x402/search
FIRECRAWL_API_KEY=your_firecrawl_api_key
# Genbase
GENBASE_API_URL=https://www.genbase.fun
# OpenAI
OPENAI_API_KEY=your_openai_api_key
# x402 Network (Base)
NEXT_PUBLIC_NETWORK=base
USDC_CONTRACT_ADDRESS=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913pnpm devOpen http://localhost:3000 to see the application.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Interface β
β (Next.js App Router + CDP Embedded Wallet + x402-fetch) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β 1. User enters topic
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PHASE 1: Web Search β
β (Client-Side x402) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β x402 payment (~$0.01-0.05 USDC)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Firecrawl API β
β POST /v2/x402/search (x402 micropayment) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β Returns research results
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WORKFLOW PHASE 1 β
β Script Generation Workflow β
β (Vercel Workflow DevKit - Server) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β Step: generateScript()
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β OpenAI GPT-4o β
β (via Vercel AI Gateway - FREE) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β Returns script
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PHASE 2: Video Creation β
β (Client-Side x402) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β x402 payment ($0.20 USDC)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Genbase API β
β POST /api/video/create-sora2 (x402 micropayment) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β Returns taskId
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WORKFLOW PHASE 2 β
β Video Polling Workflow β
β (Vercel Workflow DevKit - Server) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β Poll every 2 minutes with sleep()
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Genbase Status Endpoint β
β GET /api/video/query?id={taskId} (FREE) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β Video ready after 3-10 minutes
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Final Result β
β Video URL + Script + Research + Cost Breakdown β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Problem: Vercel Workflow DevKit requires deterministic execution, but x402 micropayments involve interactive 402 status codes and payment retries.
Solution: Hybrid approach where:
- Client-side: Handles x402 payments using
x402-fetchwrapper - Server-side workflows: Orchestrate deterministic AI operations
- Proxy API routes: Bridge client payments with server API keys
- Client: User enters topic (e.g., "what's new with x402")
- Client: x402-wrapped fetch calls Firecrawl search API
x402-fetchautomatically handles 402 β payment β retry- Payment settled on Base network (~$0.01-0.05 USDC)
- Server: API route starts
contentGeneratorWorkflow - Workflow: Receives research, streams progress updates
- Step:
generateScript()calls OpenAI GPT-4o via AI Gateway (free) - Return: Script + research results
- Client: x402-wrapped fetch calls Genbase API
- Payment settled on Base network ($0.20 USDC)
- Returns video task ID
- Server: API route starts
videoPollWorkflow - Workflow: Polls Genbase status every 2 minutes using
sleep()- Zero compute cost during sleep
- Status: pending β processing β video_upsampling β Ready
- Step:
checkVideoStatus()queries Genbase (free, unlimited) - Return: Video URL + thumbnail + script + total cost
// Client setup (app/page.tsx)
const user = await getCurrentUser(); // CDP wallet
const viemAccount = await toViemAccount(user.evmAccounts[0]);
const walletClient = createWalletClient({
account: viemAccount,
chain: base,
transport: http('https://mainnet.base.org'),
});
// Wrap fetch with x402 payment capability
const fetchFunc = wrapFetchWithPayment(fetch, walletClient, maxPaymentAmount);
// Call API - x402-fetch handles entire payment flow
const response = await fetchFunc('/api/test-firecrawl', {
method: 'POST',
body: JSON.stringify({ query, limit }),
});What happens under the hood:
- Client calls API without payment
- Server forwards to Firecrawl (returns 402 Payment Required)
x402-fetchintercepts 402, creates payment authorization- Client retries with
X-PAYMENTheader - Server forwards payment proof to Firecrawl
- Firecrawl verifies on-chain and returns results
- Server forwards
X-PAYMENT-RESPONSEwith transaction hash - Client logs transaction on BaseScan
content-agent/
βββ app/
β βββ page.tsx # Main UI (x402 payments + workflows)
β βββ providers.tsx # CDP wallet configuration
β βββ layout.tsx # Root layout
β βββ api/
β βββ content/
β β βββ create/route.ts # Start script generation workflow
β β βββ status/[runId]/route.ts # Poll workflow status
β β βββ stream/[runId]/route.ts # SSE progress updates
β β βββ video-poll/route.ts # Start video polling workflow
β βββ test-firecrawl/route.ts # Firecrawl proxy (x402)
β βββ genbase/
β βββ create-video/route.ts # Genbase proxy (x402)
β
βββ workflows/
β βββ content-generator.ts # Phase 1: Script generation workflow
β βββ video-poll.ts # Phase 2: Video polling workflow
β βββ steps/
β βββ content-steps.ts # All step functions (I/O operations)
β
βββ lib/
β βββ config.ts # Environment configuration
β βββ payment-logger.ts # x402 transaction logging
β βββ rate-limit.ts # In-memory rate limiter
β
βββ types/
β βββ firecrawl.d.ts # TypeScript definitions
β
βββ next.config.ts # Workflow DevKit integration
Main application logic:
- CDP wallet authentication
- x402 payment setup with
x402-fetch - Two-phase workflow orchestration
- Real-time progress updates via SSE
- Result display with cost breakdown
Critical functions:
handleSubmit(): Orchestrates entire flowcreateVideoAndStartPolling(): Phase 2 video creationpollWorkflowUntilComplete(): Checks workflow status every 20s
Firecrawl proxy with x402 support:
- Extracts
X-PAYMENTheader from client - Adds
Authorization: Bearer {API_KEY} - Forwards both headers to Firecrawl
- Returns 402 or forwards
X-PAYMENT-RESPONSE
Why needed? Keeps API key secret while enabling client-side x402 payments.
Script generation workflow ("use workflow"):
- Receives research from client
- Streams progress updates
- Calls
generateScript()step - Returns script + metadata
Key constraint: No direct I/O allowed (deterministic execution).
All step functions ("use step"):
generateScript(): Calls OpenAI GPT-4o via Vercel AI SDKcheckVideoStatus(): Queries Genbase for video readinesswriteProgress(): Sends progress updates to client
Key feature: Automatic retries with exponential backoff.
- Next.js 16 with App Router
- React 19 (Server Components)
- TypeScript for type safety
- Tailwind CSS v4 for styling
- Vercel Workflow DevKit (WDK)
- Durable execution with automatic retries
- Zero-cost
sleep()for polling - Progress streaming with Server-Sent Events
- x402 Protocol - Pay-per-use HTTP requests
- x402-fetch - Client-side payment wrapper
- Coinbase Developer Platform - Embedded wallets
- Viem - Ethereum interactions
- Base Network - L2 for low-cost USDC transactions
- OpenAI GPT-4o - Script generation (via Vercel AI Gateway)
- Genbase - AI video generation (Sora 2 via x402)
- Firecrawl - Web search with x402 micropayments
- Framer Motion - UI animations
- Axios - HTTP client
- Zod - Schema validation
| Service | Cost | Payment Method | Timing |
|---|---|---|---|
| Firecrawl Search | ~$0.03 | x402 on Base | Before Phase 1 |
| Script Generation | ~$0.01 | AI Gateway | During Phase 1 |
| Genbase Video (15s) | $0.20 | x402 on Base | Before Phase 2 |
| Video Polling | Free | No auth | During Phase 2 |
| Total per video | ~$0.25 |
*Free with Vercel AI Gateway quota
Gas Costs on Base:
- Per transaction: ~$0.0004-0.001
- Covered by CDP facilitator (users pay service cost only)
# Terminal UI
npx workflow inspect runs
# Web UI
npx workflow inspect runs --web# Follow workflow execution
npx workflow logs {runId} --followVercel (Recommended):
vercel deployEnvironment:
- Workflows auto-deployed with Next.js app
- Access Workflow dashboard: Vercel β AI β Workflows
- Monitor runs, view timelines, debug errors
Workflows ("use workflow"):
- Deterministic orchestration (pure control flow)
- Can use:
sleep(),getWritable(),createWebhook() - Cannot use:
fetch(),Date.now(),Math.random()
Steps ("use step"):
- Handle all I/O operations
- Automatic retries with backoff
- Throw
FatalErrorfor non-retryable errors
Protocol: HTTP 402 "Payment Required" status code
Network: Base (Ethereum L2)
Currency: USDC (6 decimals)
Contract: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
Flow:
- Request β 402 response with payment requirements
- Client creates payment authorization
- Retry with
X-PAYMENTheader - Server verifies and processes
- Returns
X-PAYMENT-RESPONSEwith TX hash
Features:
- Email-based wallet creation (no seed phrases)
- EOA wallets for simplicity
- Seamless x402 payment signing
Hooks:
useIsInitialized()- CDP readyuseIsSignedIn()- User authenticateduseCurrentUser()- Get wallet addresses
- Replace in-memory rate limiter with Redis
- Add database for workflow history
- Implement error monitoring (Sentry)
- Store transaction receipts
- Add wallet funding flow (buy USDC)
- SSL/HTTPS for all endpoints
- CORS configuration for domain
- Workflow storage: Vercel (prod) or Postgres
- Rate limiting: Redis/Upstash
- Video storage: CDN or S3 mirror
- Payment tracking: Database with receipts
- Check wallet has sufficient USDC balance
- Verify
USDC_CONTRACT_ADDRESSis correct for Base - Ensure CDP wallet is initialized
- Check workflow logs:
npx workflow logs {runId} - Verify external API availability (Firecrawl, Genbase)
- Check rate limits
- Video generation takes 3-10 minutes (normal)
- Workflow retries up to 8 times (16 minutes max)
- Check Genbase API status
- Vercel Workflow DevKit Docs
- x402 Protocol Spec
- CDP Documentation
- Genbase Documentation
- More Projects
MIT