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
🌐 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.
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
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.
| 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 |
- 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.
- 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-allto heal all degraded accounts simultaneously.
- 💬 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.
- 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.
- 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.
┌──────────────────────────── 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)
- Node.js 20.12+ (v22 LTS recommended)
- MongoDB 6.0+
- (Optional) Docker & Docker Compose
# 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 apiAccess the Interactive Documentation & Admin Studio:
- API Swagger Docs:
http://localhost:8080/docs - Admin Studio & Playground:
http://localhost:8080/admin
# 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 startcurl -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
}'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)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"
}'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"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. |
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.
- 🌐 Official Website: https://suncodevn.com
- 🚀 Live Demo Platform: https://museai.suncodevn.com
- 📧 Business Email: contact@suncodevn.com / suncodevn@gmail.com
- 💬 Telegram: @suncodevn
- 🐙 GitHub Profile: @suncodevn
Contributions, feature requests, and bug reports are welcome!
- Fork this repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'feat: Add AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
Distributed under the MIT License. See LICENSE for more details.