How I Built an AI Product Photography Pipeline with 30+ Models (Next.js + Express + Replicate/FAL)

Published: (February 8, 2026 at 04:11 PM EST)
4 min read
Source: Dev.to

Source: Dev.to

Overview

PixelMotion is a SaaS that transforms a single product photo into enhanced images and AI‑generated videos. The platform abstracts away the complexities of 30+ AI models, handling everything from background removal to video generation.

Stack

LayerTechnologies
FrontendNext.js 15 (App Router) • TailwindCSS
BackendExpress.js • TypeScript • PostgreSQL (Sequelize ORM)
AI ProvidersReplicate • FAL AI • OpenAI
StorageGoogle Cloud Storage
PaymentsStripe (usage‑based credits)

Architecture Flow

User Upload → Website Scraper → AI Analysis → Model Selection → Enhancement/Generation → Storage → Delivery

Unified LLM Service

A single service normalizes the differing APIs of each provider.

// Simplified model orchestration
const result = await llmService.generate({
  provider: model.provider, // 'replicate' | 'fal' | 'openai'
  model: model.id,
  input: normalizedParams,
  webhook: callbackUrl,
});

Each provider adapter implements its own retry logic, timeout handling, and error mapping, so adding a new model is just a configuration change.

Fallback Chains

AI models can fail due to rate limits, cold starts, or updates. A fallback chain ensures continuity.

const ENHANCEMENT_CHAIN = [
  { model: 'flux-pro-v2', provider: 'replicate' },
  { model: 'flux-pro', provider: 'fal' },
  { model: 'stable-diffusion-xl', provider: 'replicate' },
];

If the primary model fails or times out, the system automatically tries the next one, keeping the user experience seamless.

Credit System

Different models have varying costs. Instead of flat subscriptions, a credit system assigns a credit cost per generation.

ModelCreditsApprox. Cost
Flux 2 Pro (photo)2~ $0.05
Kling 1.6 (video)5~ $0.13
Sora 2 (video)20~ $0.50
Veo 3.1 (video)25~ $0.65

Users can select models based on budget and quality requirements.

Store Integration & Prompt Generation

When a user connects their e‑commerce store, the platform:

  1. Scrapes product data.
  2. Uses GPT‑4o to analyze:
    • Product category & type
    • Target audience
    • Brand aesthetic
    • Optimal AI models for the product

The analysis feeds into prompt generation, allowing, for example, a luxury watch to receive a different treatment than a kitchen gadget.

Job Queue & Frontend Polling

AI generation takes 30–120 seconds. A job‑queue pattern manages the workflow:

  1. User submits request → job created (pending status).
  2. Backend dispatches to the selected AI provider.
  3. Frontend polls every 3 seconds via a custom hook.
  4. Webhook or poll marks the job as completed.
// Frontend polling hook (simplified)
const useGenerationStatus = (jobId: string) => {
  const [status, setStatus] = useState('pending');

  useEffect(() => {
    const interval = setInterval(async () => {
      const res = await api.get(`/jobs/${jobId}`);
      setStatus(res.data.status);
      if (res.data.status === 'completed') clearInterval(interval);
    }, 3000);
    return () => clearInterval(interval);
  }, [jobId]);

  return status;
};

Lessons Learned

  1. Validate model output – Blank images, corrupted files, or completely wrong results must be filtered before serving.
  2. Cost management – Implement per‑user rate limits and daily cost alerts; otherwise expenses can explode quickly.
  3. Prompt engineering outweighs model selection – A well‑crafted prompt on a cheaper model often beats a poor prompt on an expensive one.
  4. Webhooks are unreliable – Always have a polling fallback for both Replicate and FAL.
  5. Users care about results, not the model – Auto‑selecting the best model based on product type improves satisfaction more than exposing the model list to users.

Current Work

  • Multi‑photo video generation (combining several angles).
  • UGC‑style video generation with AI avatars.
  • Direct publishing to TikTok/YouTube from the platform.

Call to Action

If you’re building with AI APIs and want to discuss multi‑provider orchestration, fallback patterns, or credit systems, feel free to drop a comment. I’m happy to dive deeper into any of these topics.

Live Demo

Check out the product at pixelmotion.io.

Built with: Next.js 15, Express.js, PostgreSQL, Replicate, FAL AI, and OpenAI.

0 views
Back to Blog

Related posts

Read more »

Happy women in STEM day!! <3

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as we...