ai-tools

I Built a Self-Hosted Midjourney + Kling Alternative in One Weekend (Open Source)

GitHub's #1 trending repo + 3 custom AI pipelines = your own unlimited creative studio

I Built a Self-Hosted Midjourney + Kling Alternative in One Weekend (Open Source)
⚑ FEATURED PARTNERStrategic Developer Ad Placement Slot (top_banner)Set NEXT_PUBLIC_ADSENSE_CLIENT_ID in .env to activate live ad delivery

Why I Stopped Paying for Midjourney

Last month I was running four different AI subscriptions simultaneously β€” Midjourney ($30/mo), Runway ($35/mo), Kling ($25/mo), and a Stable Diffusion cloud service. That's nearly $1,200 a year just to generate images and videos for my projects.

Then I found Open-Generative-AI β€” the repository that hit #1 on GitHub trending in April 2026 β€” and everything changed.

In one weekend, I built a fully self-hosted alternative. And in this post, I'm going to show you exactly how, including the three advanced generative AI loops I engineered on top of it that make the result dramatically better than any off-the-shelf subscription.

---

What Is Open-Generative-AI?

Open-Generative-AI is an MIT-licensed Next.js project by developer Anil Matcha. It connects to MuAPI.ai β€” a unified API that gives you access to 500+ AI models (Flux Pro, Kling, Luma Dream, SDXL, and many more) through one API key.

The key advantages:

  • βœ… No monthly subscriptions β€” pay only for what you generate (fractions of a cent per image)
  • βœ… 200+ models under one interface
  • βœ… Self-hosted on Vercel β€” your data stays private
  • βœ… MIT license β€” modify and sell commercially
But here's the thing: using it as a raw model wrapper is just the beginning. The real power comes from chaining models together in loops.

---

The Problem With Basic Prompting

Every AI image generator has the same issue: the quality of your output is directly proportional to the quality of your input prompt. A basic prompt like:

"a warrior standing in a forest"

...yields a generic, forgettable image every time.

A professional cinematographer would write something like:

"Battle-hardened samurai warrior in a misty ancient cedar forest, shot on 85mm f/1.4 lens, low-angle hero shot, Rembrandt lighting with a single shaft of golden sunlight piercing through the canopy, Kodak Vision3 cinematic grain, shallow depth of field, atmospheric fog, photorealistic, 8K, award-winning photography"

The difference? Night and day. So instead of making users manually craft expert prompts, I built 3 loops that handle this automatically.

---

Loop 1: The Cinematic Prompt Expansion Loop

This is the foundational loop. Here's the architecture:

code
User's basic idea
    ↓
Gemini AI Cinematic Prompter Agent
    ↓  (adds camera, lighting, texture, atmosphere specs)
Professional expanded prompt
    ↓
Flux Pro 1.1 image generation
    ↓
Cinematic, publication-quality image

How the Gemini Agent Works

I wrote a system prompt that instructs Gemini to behave like a professional cinematographer:

javascript
// app/api/expand-prompt/route.js
const systemInstruction = `You are an elite AI prompt engineer and cinematic director. 
Transform a basic user input into a masterfully crafted prompt.

RULES:
- Output ONLY the enhanced prompt β€” no preamble, no explanation.
- Add precise camera details: lens (e.g., "shot on 85mm f/1.4"), angle, and movement.
- Add precise lighting specs: golden hour, rim lighting, volumetric rays, etc.
- Add specific environmental details that anchor the scene in reality.`;

The result? Users type 5 words. They get a 100-word cinematic masterpiece sent to Flux. Every single time.

The key insight: The LLM doesn't replace the image model β€” it optimizes the input to the image model. Separating these two stages gives you dramatically better results than just using a single all-in-one model.

---

Loop 2: The Character Consistency Pipeline

⚑ SPONSORED TUTORIAL ADStrategic Developer Ad Placement Slot (mid_article)Set NEXT_PUBLIC_ADSENSE_CLIENT_ID in .env to activate live ad delivery

This solves one of the hardest problems in generative AI: maintaining the same character across different scenes.

Every time you generate an image, the AI produces a different face. My solution is a 2-stage pipeline:

code
Stage 1: Generate the scene (Flux Pro)
             ↓
         Scene Image (with any random face)
             ↓
Stage 2: Apply reference face (FaceSwap API via MuAPI)
             ↓
         Character-consistent scene image

Here's the actual API route code:

javascript
// Stage 1: Generate the scene
const sceneJob = await muapiPost('/images/generations', {
  model: 'flux-pro-1.1',
  prompt: scenePrompt,
  width: 1344, height: 768,
});
const sceneImageUrl = await pollForResult(sceneJob.id);

// Stage 2: Apply the reference character face
const faceSwapJob = await muapiPost('/images/faceswap', {
  source_image: referenceImageUrl,  // User's saved character face
  target_image: sceneImageUrl,      // Generated scene
  face_restore: true,
});
const finalImageUrl = await pollForResult(faceSwapJob.id);

Content creators are using this to produce entire comic strips and ad campaigns in minutes.

---

Loop 3: The Text-to-Movie Storyboard

This is a 3-stage multi-model pipeline that converts a written story into a 4-panel animated storyboard:

code
Your Story
    ↓
Stage 1: Gemini splits into 4 sequential frames
    ↓
Stage 2: Flux generates all 4 keyframe images (in PARALLEL)
    ↓
Stage 3: Kling animates each image into a 5-second video clip
    ↓
Full cinematic storyboard

Parallel Image Generation

The critical performance optimization: all 4 images are submitted simultaneously using Promise.all, cutting generation time from ~4 minutes to ~1 minute:

javascript
// Submit all 4 image jobs AT THE SAME TIME
const imageJobs = await Promise.all(
  frames.map(f => submitImageJob(f.scenePrompt))
);

// Wait for ALL to complete
const imageResults = await Promise.all(
  imageJobs.map(job => pollTask(job.id))
);

---

How to Deploy It Yourself (90 Seconds)

Step 1: Get your API keys

Step 2: Clone and run
bash
git clone <repo>
cd ai-creative-studio
npm install
cp .env.example .env.local
# Add your keys
npm run dev

Step 3: Deploy to Vercel

bash
npx vercel --prod
Done. Your studio is live.

---

Cost Comparison

ServiceMonthly CostImagesVideo
Midjourney Pro$30~8,000❌
Runway Gen-3$35❌~150 clips
Kling Pro$25❌~300 clips
AI Creative Studio$0 baseUnlimitedUnlimited

Pay per generation via MuAPI. At typical usage ~$10/month covers most creators.

---

Get the Full Template

I've packaged the complete codebase β€” all 3 loops, 5 API routes, the premium UI, and the full deployment guide β€” as a downloadable template in the Vibe Coding Codex Shop.

The template is MIT licensed, meaning you can modify it and sell your customized version commercially.

---

Found this useful? Star the Open-Generative-AI repo and share this post with your dev community.

πŸš€ VIBE CODING CODEX ACADEMY

Ready to Stop Typing Code & Start Directing AI Systems?

Join 5,000+ developers building real production software with AI. Learn the 7-Stage Vibe Coding OS, harness engineering, and earn your verified Build DNA Certificate.

⚑ SPONSORED ADVERTISEMENTStrategic Developer Ad Placement Slot (bottom_banner)Set NEXT_PUBLIC_ADSENSE_CLIENT_ID in .env to activate live ad delivery
#AI#Open Source#Next.js#Generative AI#Flux#Kling#Self-Hosted#MuAPI#Image Generation#Video Generation

Related Posts

Qwen 2.5-Coder: The Open-Source AI Coding Benchmark Champion
ai-tools

Qwen 2.5-Coder: The Open-Source AI Coding Benchmark Champion

8 min read
The Qwen3.8 Blueprint: How to Harness 2.4T Parameters for Autonomous Vibe Coding
ai-tools

The Qwen3.8 Blueprint: How to Harness 2.4T Parameters for Autonomous Vibe Coding

10 min read
Building Native iOS & macOS AI Agents with Qwen & Apple Intelligence
ai-tools

Building Native iOS & macOS AI Agents with Qwen & Apple Intelligence

11 min read