A production-ready, Railway-optimized proxy service for Midjourney Discord API that provides REST API endpoints for AI image generation.
- π¨ Complete Midjourney Integration - Imagine, Upscale, Variations, Blend, Describe
- π Railway Optimized - Multi-stage Docker build, health checks, auto-scaling
- π Secure Configuration - Environment variables, no hardcoded secrets
- π Monitoring Ready - Health endpoints, metrics, structured logging
- π οΈ Developer Friendly - Automated scripts, comprehensive documentation
- π Production Ready - Optimized JVM settings, error handling, rate limiting
- Click the "Deploy on Railway" button above
- Connect your GitHub account and fork this repository
- Set the required environment variables (see below)
- Deploy automatically
- Fork this repository to your GitHub account
- Go to railway.app and create a new project
- Connect your GitHub repository
- Set environment variables in Railway dashboard
- Deploy
Set these in your Railway dashboard under Variables:
DISCORD_GUILD_ID=your_discord_server_id
DISCORD_CHANNEL_ID=your_discord_channel_id
DISCORD_USER_TOKEN=your_discord_user_token
MJ_API_SECRET=your_secure_api_secret_keySPRING_PROFILES_ACTIVE=railway
MJ_CORE_SIZE=3
MJ_QUEUE_SIZE=10
MJ_TIMEOUT_MINUTES=5
MJ_TASK_STORE_TYPE=in_memory
MJ_TRANSLATE_WAY=null
MJ_NOTIFY_POOL_SIZE=10- Create a new Discord server or use existing one
- Add Midjourney bot to your server
- Create a dedicated channel for Midjourney
- Enable Developer Mode in Discord (User Settings > Advanced > Developer Mode)
- Right-click your server β Copy ID (this is
DISCORD_GUILD_ID) - Right-click your channel β Copy ID (this is
DISCORD_CHANNEL_ID)
- Open Discord in browser
- Press F12 β Network tab
- Send any message in Discord
- Look for requests to
discord.com/api - Copy the
authorizationheader value (this isDISCORD_USER_TOKEN)
All API requests require the mj-api-secret header:
curl -H "mj-api-secret: your_api_secret" https://your-app.railway.app/mj/task/listcurl -X POST https://your-app.railway.app/mj/submit/imagine \
-H "Content-Type: application/json" \
-H "mj-api-secret: your_api_secret" \
-d '{
"prompt": "a beautiful sunset over mountains, photorealistic, 4k"
}'curl -H "mj-api-secret: your_api_secret" \
https://your-app.railway.app/mj/task/{task-id}/fetchcurl -X POST https://your-app.railway.app/mj/submit/action \
-H "Content-Type: application/json" \
-H "mj-api-secret: your_api_secret" \
-d '{
"taskId": "your-task-id",
"action": "UPSCALE",
"index": 1
}'Once deployed, access interactive API documentation at:
https://your-app.railway.app/doc.html
GET /health- Health checkGET /mj/task/list- List all tasksPOST /mj/submit/imagine- Submit imagine requestPOST /mj/submit/blend- Blend multiple imagesPOST /mj/submit/describe- Describe image (image to text)GET /mj/task/{id}/fetch- Get task statusPOST /mj/submit/action- Submit action (upscale, variation, etc.)
- Clone the repository
- Copy
.env.exampleto.envand fill in your values - Run with Maven:
mvn spring-boot:run - Or use Docker:
docker build -t mjproxy . && docker run -p 8080:8080 mjproxy
Use the provided test script:
chmod +x test-api.sh
./test-api.sh https://your-app.railway.app your-api-secretUse the deployment script:
chmod +x deploy-to-railway.sh
./deploy-to-railway.sh- Builder Stage: Maven with OpenJDK 17 for compilation
- Runtime Stage: Lightweight JRE for production
- Size Optimization: ~60% smaller final image
- Port Binding: Automatic
PORTenvironment variable support - Health Checks:
/healthendpoint for Railway monitoring - Logging: Structured logging for Railway dashboard
- JVM Tuning: Optimized for cloud containers
- Environment Variables: No secrets in code
- API Authentication: Required
mj-api-secretheader - Input Validation: Sanitized prompts and parameters
- Rate Limiting: Built-in request throttling
- Endpoint:
GET /health - Railway Integration: Automatic restart on failures
- Custom Checks: Discord connection, memory usage
- Endpoint:
GET /actuator/metrics - Available Metrics: JVM stats, HTTP requests, custom counters
- Integration: Compatible with Railway metrics
- Structured Format: JSON logs for better parsing
- Log Levels: Configurable via environment variables
- Request Tracing: Full request/response logging
Railway pricing for typical usage:
- Free Tier: $5 credit/month (good for testing)
- Light Usage: $10-15/month (occasional use)
- Medium Usage: $20-30/month (regular use)
- Heavy Usage: $40-60/month (high volume)
- Never commit Discord tokens to version control
- Use strong API secrets (minimum 32 characters)
- Regularly rotate tokens for security
- Monitor usage to prevent abuse
- Respect Midjourney limits to avoid account warnings
- Monitor request frequency in Railway logs
- Implement client-side throttling for high-volume usage
- User tokens can expire - monitor for authentication errors
- Consider Discord bot tokens for production use
- Set up alerts for token failures
-
Deployment Fails
# Check Railway build logs railway logs --deployment -
Discord Connection Issues
- Verify token is valid and not expired
- Check server and channel IDs are correct
- Ensure Midjourney bot is in your server
-
API Authentication Fails
- Verify
MJ_API_SECRETenvironment variable is set - Check request includes
mj-api-secretheader - Ensure header value matches exactly
- Verify
-
Health Check Failures
- Check
/healthendpoint responds with 200 - Verify all required environment variables are set
- Review application logs for startup errors
- Check
Enable verbose logging:
railway variables set SPRING_PROFILES_ACTIVE=railway,debug- Check Railway deployment logs
- Review application logs in Railway dashboard
- Test API endpoints with provided scripts
- Verify environment variables are set correctly
- Railway Documentation: https://docs.railway.app
- Midjourney Documentation: https://docs.midjourney.com
- Discord Developer Portal: https://discord.com/developers
- Spring Boot Actuator: https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
If this project helps you, please give it a star! β
π Ready to deploy? Click the Railway button above and start generating amazing AI images in minutes!