Skip to content

Latest commit

Β 

History

History
305 lines (229 loc) Β· 14.5 KB

README.md

File metadata and controls

305 lines (229 loc) Β· 14.5 KB

⚑ Muse AI Gateway & Distributed Cluster API

Enterprise-Grade RESTful API, SSE Streaming & SaaS Gateway for Meta AI / Imagine Diffusion & Video Generation

Direct Noise Protocol (Noise_XX_25519_AESGCM_SHA256) & WebSocket Connection β€’ Up to 2,000 Concurrency β€’ Self-Healing WSS Auto-Recovery

GitHub Stars Official Website Live Platform Node.js Docker Ready License: MIT

🌐 Official Website β€’ πŸš€ Live Studio Demo β€’ πŸ“– Interactive API Docs (/docs) β€’ πŸ’Ό Hire Us / Commercial Support


⭐ If this project helped you or saved you time, please give it a Star! It inspires continuous updates and community feature drops.


πŸ“Œ Global SEO Keywords & Topics

meta-ai, meta-ai-api, ai-gateway, imagine-api, video-generation, image-generation, text-to-video, text-to-image, openai-compatible, sse-streaming, multi-account-pool, high-concurrency, self-healing, reverse-engineered, websocket-proxy, ai-cluster, suncodevn


🌟 What is Muse AI Gateway?

Muse AI Gateway is a production-grade, reverse-engineered API server that transforms Meta AI's proprietary end-to-end encrypted Noise Protocol (Noise_XX_25519_AESGCM_SHA256) and WebSocket architecture into a clean, developer-friendly OpenAI-compatible REST API and Server-Sent Events (SSE) gateway.

Whether you want to build autonomous AI agents, Telegram/Discord bots, automated video/image generation pipelines (n8n/Make), or high-throughput SaaS applications, Muse AI Gateway handles account pooling, proxy routing, token streaming, and datacenter IP bypass with extreme performance.


⚑ Why Muse AI Gateway? (Comparison)

Feature Standard Scraping / Basic Wrappers ⚑ Muse AI Gateway (This Project)
Concurrency Ceiling 1 - 2 requests (easily blocked) Up to 2,000 concurrent threads per account / global cluster
Connection Method Cookie-based HTTP scraping (Fragile) Direct WebSocket + Noise Protocol straight to Meta VM
Datacenter IP Ban ❌ 99% blocked on AWS/Hetzner/Vultr βœ… 100% Bypassed via direct WSS streaming
WSS Auto-Recovery ❌ Manual re-login when token dies βœ… Self-Healing Watchdog (Auto-renews via Headless Chromium)
Chat API Custom, non-standard JSON βœ… 100% OpenAI-Compatible (/v1/chat/completions + SSE)
Media Generation Blocking / High timeout rate βœ… Durable Queue Dispatcher + Webhooks + Signed CDN links
Web GUI None or basic playground βœ… Full Web Studio with Non-blocking Live Render Queue
Reliability Restarts lose in-flight tasks βœ… MongoDB-backed idempotency, circuit breakers, graceful drain

πŸš€ Key Highlights & Capabilities

1. πŸ”Œ Multi-Account Pooling with Extreme Concurrency (Up to 2,000 Threads)

  • Zero Datacenter IP Blocking: Meta strictly limits requests originating from cloud VPS/datacenter IPs. By feeding a direct WebSocket link (wss://...), the backend connects straight to the assigned Meta VM, 100% bypassing datacenter IP restrictions.
  • Dynamic Load Balancing: Connect multiple Meta accounts. The built-in client pool dynamically balances loads using least-loaded round-robin selection with configurable concurrency slots.
  • Configurable Concurrency: Concurrency limits can scale up to 2,000 parallel threads per account for large-scale enterprise clusters.

2. πŸ›‘οΈ Self-Healing WSS Auto-Recovery Watchdog

  • Active Health Monitoring: Runs a background diagnostic loop every 45 seconds to inspect all connected account sockets.
  • Automated Headless Browser Renewal: If an account's WSS token expires or is dropped by Meta, the gateway automatically launches a lightweight headless Chromium process (auto-detected on Linux & Windows) to re-authenticate and derive a fresh WebSocket connection without human intervention.
  • One-Click Bulk Recovery: REST endpoint POST /api/accounts/recover-all to heal all degraded accounts simultaneously.

3. 🎨 3-in-1 Generative AI Engine

  • πŸ’¬ OpenAI-Compatible Chat (/v1/chat/completions): Low-latency token-by-token SSE streaming, multi-turn conversations pinned to accounts, and reference media attachments.
  • πŸ–ΌοΈ Photorealistic Image Generation (/v1/images/generations): High-res Imagine Diffusion (Aspect ratios: 1:1, 16:9, 9:16, 4:3, 3:2) with Image-to-Image reference support.
  • 🎬 Motion Video Synthesis (/v1/videos/generations): Motion-coherent MP4 video creation (5s standard, 10s extended, 16:9 widescreen, 9:16 vertical reels) with Image-to-Video and synchronous/asynchronous polling.

4. πŸ–₯️ AI Studio & Non-Blocking Render Queue

  • Non-Blocking Submission: Click "Render Video" or "Generate Image" and continue submitting prompts without waiting 60–90 seconds for each job to complete.
  • Live Active Render Queue: Real-time table tracking all queued/rendering/completed jobs with live progress percentage bars.
  • Interactive Output Stage: Click "View on Stage" on any job in the queue to preview live progress or immediately play the finished MP4 video.
  • Direct Download & Signed Links: HMAC-SHA256 signed expiring URLs with HTTP Range support for seamless video seeking.

5. 🏒 Enterprise Queue Dispatcher & Webhooks

  • Durable MongoDB Queue: Survives server restarts; jobs are claimed atomically (findOneAndUpdate) across multi-node clusters.
  • Signed Webhooks: HMAC-SHA256 signed delivery with exponential backoff retries and SSRF protection.
  • Stripe-Style Error Envelopes: Standardized JSON responses, cursor pagination, and idempotency key support.

πŸ›οΈ System Architecture

                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ API Node ─────────────────────────────┐
  Clients / Apps / SaaS / Bots ───► β”‚ Express  ─► Auth / Rate Limit / Validation ─► Route Handlers       β”‚
                                    β”‚                                    β”‚                 β”‚             β”‚
                                    β”‚                          Chat (direct)        Image/Video Jobs     β”‚
                                    β”‚                                    β”‚                 β”‚             β”‚
                                    β”‚                                    β–Ό                 β–Ό             β”‚
                                    β”‚                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
                                    β”‚                         β”‚  Account Pool  │◄──│  Dispatcher   β”‚     β”‚
                                    β”‚                         β”‚ (2000 Concurr, β”‚   β”‚ (Claim Queue, β”‚     β”‚
                                    β”‚                         β”‚  WSS Watchdog) β”‚   β”‚  Retry/Heart) β”‚     β”‚
                                    β”‚                         β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β–²β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                                      β”‚ WebSocket          β”‚
                                                                      β–Ό                    β”‚
                                                              Upstream Meta AI        MongoDB (Jobs,
                                                               (Noise Protocol)      Accounts, Keys)

⚑ Quick Start (1 Minute Setup)

Prerequisites

  • Node.js 20.12+ (v22 LTS recommended)
  • MongoDB 6.0+
  • (Optional) Docker & Docker Compose

Method A: Docker Compose (Fastest)

# 1. Clone repository
git clone https://github.com/suncodevn/muse-api-server.git
cd muse-api-server

# 2. Setup environment variables
cp .env.example .env

# Set secure secrets:
# node -e "console.log(require('crypto').randomBytes(32).toString('base64url'))"

# 3. Start full stack (API + MongoDB)
docker compose up -d --build

# 4. View logs
docker compose logs -f api

Access the Interactive Documentation & Admin Studio:

  • API Swagger Docs: http://localhost:8080/docs
  • Admin Studio & Playground: http://localhost:8080/admin

Method B: Local Node.js Setup

# 1. Install dependencies
npm ci

# 2. Setup environment
cp .env.example .env
# Edit .env and configure MONGODB_URI, ADMIN_API_KEY, SIGNING_SECRET

# 3. Start development server
npm run dev

# Or start production server
npm start

πŸ“š API Usage Examples

1. OpenAI-Compatible Chat Completion (cURL)

curl -X POST http://localhost:8080/v1/chat/completions \
  -H "Authorization: Bearer mk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "muse-1",
    "messages": [
      {"role": "system", "content": "You are a helpful AI assistant."},
      {"role": "user", "content": "Explain quantum computing in 2 sentences."}
    ],
    "stream": false
  }'

Using Official OpenAI Python SDK:

from openai import OpenAI

client = OpenAI(
    api_key="mk_live_YOUR_API_KEY",
    base_url="http://localhost:8080/v1"
)

response = client.chat.completions.create(
    model="muse-1",
    messages=[
        {"role": "user", "content": "Hello, write a haiku about the ocean."}
    ],
    stream=True
)

for chunk in response:
    content = chunk.choices[0].delta.content or ""
    print(content, end="", flush=True)

2. Generate Photorealistic Image

curl -X POST http://localhost:8080/v1/images/generations \
  -H "Authorization: Bearer mk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Cyberpunk street market in Tokyo with neon rain reflections, ultra-realistic 8k",
    "aspect_ratio": "16:9",
    "response_format": "url"
  }'

3. Generate Motion Video (MP4)

curl -X POST http://localhost:8080/v1/videos/generations \
  -H "Authorization: Bearer mk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A glowing jellyfish floating through a cosmic nebula with shimmering starlight, 4k cinematic slow motion",
    "aspect_ratio": "16:9",
    "duration": 5
  }'

Returns immediately with a durable Job ID:

{
  "id": "job_9b3e1f0a2c",
  "object": "job",
  "status": "queued",
  "type": "video",
  "created_at": "2026-10-29T10:00:00.000Z"
}

Poll job progress or use Webhooks:

curl http://localhost:8080/v1/jobs/job_9b3e1f0a2c \
  -H "Authorization: Bearer mk_live_YOUR_API_KEY"

πŸ› οΈ Configuration Guide

Key environment variables in .env:

Variable Default Description
PORT 8080 HTTP listener port.
MONGODB_URI mongodb://localhost:27017/muse_ai MongoDB connection URI.
ADMIN_API_KEY (Required) Master admin secret key (β‰₯ 32 chars).
SIGNING_SECRET (Required) Secret key for signed media URLs (β‰₯ 32 chars).
PUBLIC_BASE_URL http://localhost:8080 Public CDN URL prefix for signed media.
DEFAULT_MAX_CONCURRENT_JOBS 20 Max queued/running jobs per API key.
ACCOUNT_MAX_CONCURRENCY 2000 Maximum concurrency ceiling per account.
QUEUE_MAX_PENDING 2000 Global queue limit before backpressure.
CHROMIUM_PATH auto-detected Custom executable path for Chromium/Chrome.

πŸ’Ό Commercial Support & Enterprise Services

Need custom development, automated account farming, or enterprise-scale deployment? SunCodeVN provides full-lifecycle engineering services for AI startups and enterprises:

  • πŸš€ Turnkey Private API Gateway Deployment: Complete setup on AWS, Hetzner, Vultr, OVH, or bare-metal servers.
  • πŸ”„ Meta Account Pool & Proxy Farm Setup: 100% Ban-resistant Datacenter IP bypass with automatic rotating residential/mobile proxies.
  • ⚑ High-Throughput Concurrency Scaling: Architectural optimization for 1,000 – 10,000+ Requests Per Minute.
  • πŸ€– Custom AI SaaS & Automation Integration: Custom Telegram bots, Discord bots, n8n/Make workflows, and white-label AI platforms.
  • πŸ›‘οΈ Custom Protocols & Anti-Detection Engineering: Reverse-engineering proprietary AI platforms and building secure API bridges.

πŸ“ž Contact & Inquiries


🀝 Contributing

Contributions, feature requests, and bug reports are welcome!

  1. Fork this repository.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'feat: Add AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

πŸ“œ License

Distributed under the MIT License. See LICENSE for more details.


Built with ❀️ by SunCodeVN.Com β€’ Powering Next-Gen AI Gateways.