π¬ MediaRouter
October 8, 2025 Β· View on GitHub
π¬ MediaRouter
Open Source Video Generation Gateway
A unified API for multiple AI video generation providers
Features β’ Quick Start β’ Screenshots β’ Documentation β’ Contributing
π Why MediaRouter?
Own Your Video Generation Stack - MediaRouter is the only 100% open source video generation gateway that gives you:
- π No Vendor Lock-in: Switch between Sora, Runway, Kling, and more with a single API
- π Bring Your Own Keys: Your API keys, your data, your control
- π° Cost Transparency: Real-time cost tracking across all providers
- π Run Anywhere: Docker-based deployment in 30 seconds
- π οΈ Fully Customizable: Add your own providers, modify workflows, extend functionality
π Latest: OpenAI's Sora 2 API support with synced audio generation!
The Open Source Advantage
Unlike proprietary solutions, MediaRouter gives you:
- β Complete source code access
- β Self-hosted deployment
- β No usage limits or restrictions
- β Community-driven development
- β MIT licensed - use it anywhere
β¨ Features
- π Unified API: Single OpenAI-compatible endpoint for multiple providers
- π¨ Beautiful Playground: Modern React UI with shadcn/ui components
- π BYOK Model: Bring Your Own Keys - no vendor lock-in
- π― Multiple Providers: Support for Sora 2, Runway, Kling, and more
- π Usage Tracking: Monitor costs, generation times, and success rates
- π¬ Video Gallery: Browse and manage your generated videos
- π One Command Setup: Get started instantly with Docker Compose
- π Secure: Encrypted API key storage with industry-standard encryption
π₯ Supported Providers
| Provider | Models | Image-to-Video | Audio | API Status | Pricing |
|---|---|---|---|---|---|
| OpenAI Sora | Sora 2, Sora 1 | β | β | β Public | $0.10/sec |
| Runway | Gen-3, Gen-4 | β | β | β Public | Usage-based |
| Kling AI | v1.5, v1.0 | β | β | β Public | Credit-based |
| Pika Labs | Coming soon | β | - | π§ Planned | - |
| Luma Dream Machine | Coming soon | β | - | π§ Planned | - |
All Three Providers Working: Sora 2, Runway, and Kling all have public APIs available now!
π Quick Start
Get MediaRouter running in 3 commands:
git clone https://github.com/samagra14/mediagateway.git
cd mediagateway
./setup.sh
That's it! β‘ The script automatically:
- β Pulls pre-built Docker images (no build time!)
- β Generates secure encryption keys
- β Creates storage directories
- β Starts all services
Setup time: ~30 seconds
π― Next Steps
- Open http://localhost:3000
- Add API Keys β Go to Settings β Add your provider keys
- Generate Videos β Go to Playground β Enter a prompt β Generate!
That's it! You're ready to create videos.
π Access Points
| Service | URL | Description |
|---|---|---|
| Frontend | http://localhost:3000 | Beautiful web interface |
| Backend API | http://localhost:3001 | REST API endpoint |
| API Docs | http://localhost:3001/docs | Interactive API documentation |
π Prerequisites
- Docker installed
- API keys from supported providers
Manual Setup (Without Docker)
Backend
cd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Create .env file
cp .env.example .env
# Edit .env and add your encryption keys
# Run server
python run.py
Frontend
cd frontend
# Install dependencies
npm install
# Run development server
npm run dev
π Usage
1. Add API Keys
- Navigate to Settings page
- Click "Add API Key"
- Select your provider (OpenAI, Runway, or Kling)
- Paste your API key
- Click "Add Key" to validate and save
2. Generate Videos
- Go to the Playground page
- Enter your prompt (e.g., "A serene sunset over mountains")
- Select your desired model
- Configure parameters:
- Duration: 1-10 seconds
- Aspect Ratio: 16:9, 9:16, or 1:1
- Seed: Optional, for reproducibility
- Click "Generate Video"
- Wait for generation to complete
- Download or view your video
3. Browse Gallery
- Visit the Gallery page
- View all your generated videos
- Filter by provider or status
- Download or delete videos
π API Reference
Generate Video
POST /v1/video/generations
Content-Type: application/json
{
"model": "sora-2",
"prompt": "A serene sunset over mountains",
"duration": 5,
"aspect_ratio": "16:9",
"seed": 12345
}
Response:
{
"id": "gen_abc123",
"object": "video.generation",
"created": 1728234567,
"model": "sora-2",
"provider": "openai",
"status": "processing",
"prompt": "A serene sunset over mountains",
"video": null,
"usage": null
}
Check Status
GET /v1/video/generations/{generation_id}
List Generations
GET /v1/video/generations?limit=50&provider=openai&status=completed
Full API Documentation
Visit http://localhost:3001/docs for interactive API documentation.
π Getting API Keys
OpenAI (Sora)
- Visit OpenAI Platform
- Sign up or log in
- Navigate to API Keys section
- Create new API key
- Note: Sora access may require waitlist approval
Runway
- Visit Runway
- Sign up for an account
- Go to Settings β API Keys
- Generate new API key
Kling AI
- Visit Kling AI
- Create an account
- Navigate to API section
- Generate API key
ποΈ Architecture
mediarouter/
βββ backend/ # FastAPI backend
β βββ src/
β β βββ api/ # API routes and schemas
β β βββ providers/ # Provider adapters
β β βββ services/ # Business logic
β β βββ models/ # Database models
β β βββ db/ # Database setup
β βββ requirements.txt
β βββ run.py
βββ frontend/ # React frontend
β βββ src/
β β βββ components/ # UI components
β β βββ pages/ # Page components
β β βββ lib/ # Utilities and API client
β βββ package.json
βββ storage/ # Video storage
βββ docker-compose.yml # Docker orchestration
βββ setup.sh # Setup script
π οΈ Development
Using Pre-built Images (Recommended)
# Pull latest images and start
docker compose pull
docker compose up -d
# View logs
docker compose logs -f
Building Locally (For Development)
If you want to build from source:
# Use the local development compose file
docker compose -f docker-compose.local.yml up --build
# Or build manually
docker compose build
docker compose up -d
Backend Development (Without Docker)
cd backend
# Install dev dependencies
pip install -r requirements.txt
# Run with hot reload
uvicorn src.main:app --reload --port 3001
# Run tests
pytest
Frontend Development (Without Docker)
cd frontend
# Install dependencies
npm install
# Run dev server
npm run dev
# Build for production
npm run build
# Lint
npm run lint
Adding a New Provider
- Create a new provider file in
backend/src/providers/ - Implement the
VideoProviderinterface - Add provider to
PROVIDERSdict in__init__.py - Add model mappings to
MODEL_PROVIDER_MAP - Test the provider integration
Example:
# backend/src/providers/newprovider.py
from .base import VideoProvider, VideoRequest, VideoResponse
class NewProvider(VideoProvider):
@property
def name(self) -> str:
return "newprovider"
@property
def models(self) -> list[str]:
return ["model-v1"]
async def validate_key(self) -> bool:
# Implement key validation
pass
async def generate_video(self, request: VideoRequest) -> VideoResponse:
# Implement video generation
pass
async def check_status(self, job_id: str) -> VideoResponse:
# Implement status checking
pass
π Security
- API keys are encrypted using Fernet (symmetric encryption)
- Encryption keys are stored in
.env(never commit to git) - HTTPS recommended for production deployments
- CORS is configured for allowed origins only
π Troubleshooting
Cannot Pull Docker Images
If you see "denied" errors when pulling images:
# The images might not be public yet, or the build is still running
# Check build status: https://github.com/samagra14/mediagateway/actions
# Option 1: Wait for the build to complete, then try again
docker compose pull
# Option 2: Build locally instead
docker compose -f docker-compose.local.yml up --build
Port Already in Use
# Stop existing containers
docker compose down
# Check what's using the ports
lsof -i :3000 # Frontend
lsof -i :3001 # Backend
# Or change ports in docker-compose.yml
Database Issues
# Reset database
rm storage/db.sqlite
# Restart backend
docker compose restart backend
Video Generation Stuck
- Check provider API status
- Verify API key validity in Settings
- Check backend logs:
docker compose logs -f backend - Some providers have rate limits
- Sora may require waitlist approval
Services Not Starting
# Check logs
docker compose logs
# Restart everything
docker compose down
docker compose up -d
# Check service health
docker compose ps
πΈ Screenshots
Playground - Generate Videos
Generate videos with any provider using a beautiful, intuitive interface
Gallery - Manage Your Videos
Browse, filter, and manage all your generated videos in one place
Usage Analytics - Track Costs
Monitor spending, generation times, and success rates across all providers
Settings - Manage API Keys
Securely add and manage API keys for multiple providers
π Usage Statistics
View detailed usage statistics in the Settings page:
- Total generations
- Cost breakdown by provider/model
- Average generation times
- Success/failure rates
π€ Contributing
We love contributions! MediaRouter is built by the community, for the community.
Ways to Contribute
- π Report bugs and issues
- π‘ Suggest new features or providers
- π Improve documentation
- π§ Submit pull requests
- β Star the repo to show support
Quick Start for Contributors
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Test locally with
docker compose -f docker-compose.local.yml up --build - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Guidelines
- Follow existing code style (FastAPI for backend, React for frontend)
- Add tests for new features
- Update documentation
- Ensure Docker builds succeed
- Add provider integrations using the
VideoProviderinterface
See CLAUDE.md for detailed development guide.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
What this means:
- β Commercial use allowed
- β Modification allowed
- β Distribution allowed
- β Private use allowed
- β No warranty provided
- β No liability accepted
π Support the Project
If MediaRouter is helpful to you:
- β Star this repo - It helps others discover the project
- π¦ Share on social media - Spread the word
- π¬ Join discussions - Share your use cases and ideas
- π€ Contribute - Code, docs, or ideas welcome
- π Report bugs - Help us improve
π Community & Support
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π Documentation: Full Documentation
πΊοΈ Roadmap
Coming Soon
- Additional providers (Pika, Luma, Haiper)
- Image-to-video support
- Video-to-video transformations
- Batch generation
- Webhook notifications
- CLI tool
- Python/TypeScript SDKs
Completed β
- Sora 2 API integration
- Runway Gen-3/Gen-4 support
- Kling AI v1.5 support
- Usage tracking and analytics
- Pre-built Docker images
- OpenAI-compatible API
π Acknowledgments
Built with amazing open source technologies:
- FastAPI - Modern Python web framework
- React - UI library
- shadcn/ui - Beautiful UI components
- Tailwind CSS - Utility-first CSS
- Docker - Containerization
Built with β€οΈ by the open source community