
Deploy MaxAPI
API Distribution System (New API Customized Version)
MySQL
Just deployed
/var/lib/mysql
Max API
Just deployed
Redis
Just deployed
/data
Deploy and Host MaxAPI on Railway
MaxAPI is a self-hosted AI API gateway built with Go that provides a unified, OpenAI-compatible interface for routing requests to multiple AI providers. Based on the New API project with an enhanced user interface, it includes user management, API key management, quota tracking, model routing, Redis caching, MySQL support, Midjourney integration, Suno integration, payment gateway support, Telegram authentication, and an administrative dashboard. MaxAPI allows you to centrally manage multiple AI services while exposing a single API endpoint for your applications.
About Hosting MaxAPI
Deploying MaxAPI on Railway provides a production-ready AI gateway without the complexity of managing virtual machines or Docker hosts. Railway automatically provisions your application, managed MySQL database, and managed Redis instance while connecting them through secure private networking. The application can be deployed directly from the official Docker image and exposed through Railway's generated public domain or a custom domain.
During deployment, you'll configure a small number of environment variables, including the database connection, Redis connection, session secret, and timezone. Railway automatically manages networking, persistent database storage, service restarts, and infrastructure scaling, allowing you to focus on configuring AI providers rather than maintaining servers.
After deployment, you can log into the administrative dashboard, change the default administrator password, configure upstream AI providers such as OpenAI, Anthropic, Gemini, Ollama, Midjourney, or Suno, create API keys, manage users, configure pricing and quotas, and begin serving OpenAI-compatible API requests through a single endpoint.
Common Use Cases
- Deploy a centralized OpenAI-compatible API gateway for teams, organizations, or personal projects.
- Manage multiple AI providers, API keys, user quotas, billing, and model routing through a single administration dashboard.
- Integrate OpenAI, Anthropic Claude, Google Gemini, Ollama, Midjourney, Suno, and other supported AI services behind one unified API endpoint.
- Provide internal AI services with authentication, usage tracking, and centralized access control.
- Self-host an AI gateway for applications requiring provider failover, request routing, and usage monitoring.
Dependencies for MaxAPI Hosting
MaxAPI requires the following services for a production deployment on Railway:
- Railway MySQL – Stores application data including users, API keys, channels, quotas, configuration, logs, and system settings.
- Railway Redis – Provides caching, session storage, and improves request retry performance.
- Railway Public Networking – Exposes the web interface and API endpoints over HTTPS.
- Railway Secret Management – Securely stores sensitive configuration such as the session secret.
Deployment Dependencies
The following resources are used during deployment:
- GitHub Repository: https://github.com/z3042653234/MAX-API
- Official Docker Image:
pochacco/max-api:latest - Railway MySQL Service
- Railway Redis Service
Required Railway environment variables:
SQL_DSN=${{MySQL.MYSQLUSER}}:${{MySQL.MYSQLPASSWORD}}@tcp(${{MySQL.MYSQLHOST}}:${{MySQL.MYSQLPORT}})/${{MySQL.MYSQLDATABASE}}
REDIS_CONN_STRING=${{Redis.REDIS_URL}}
SESSION_SECRET=${{secret(64, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")}}
TZ=Asia/Shanghai
Optional variables:
MEMORY_CACHE_ENABLED=true
The application listens on the following internal port:
8080
Implementation Details
Deploy the application using the official Docker image. Railway automatically connects the application to the managed MySQL and Redis services through Railway Reference Variables, eliminating the need to configure container networking or hardcoded hostnames.
Once deployment is complete:
-
Open the Railway-generated public URL.
-
Sign in using the default administrator credentials:
- Username:
root - Password:
123456
- Username:
-
Immediately change the administrator password.
-
Navigate to the administration dashboard.
-
Configure your AI provider channels (OpenAI, Anthropic, Gemini, Ollama, Midjourney, Suno, or other supported providers).
-
Create API keys for your users or applications.
-
Configure quotas, pricing, retry policies, caching, and model routing as needed.
-
Begin sending OpenAI-compatible requests to your Railway deployment.
For improved performance, configure Redis by setting REDIS_CONN_STRING. When Redis is available, MaxAPI automatically uses it for caching and retry optimization. If Redis is unavailable, optional in-memory caching can be enabled using MEMORY_CACHE_ENABLED=true.
The application supports both MySQL and SQLite. While SQLite is suitable for testing, Railway's managed MySQL service is recommended for production deployments to ensure reliability, scalability, and managed backups.
Why Deploy MaxAPI on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying MaxAPI on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
