Deploy Sub2API
AI API Gateway for quota management and multi-provider routing.
Just deployed
/var/lib/postgresql/data
Redis
Just deployed
/data
Sub2API
Just deployed
/app/data
Deploy and Host Sub2API on Railway
Sub2API is a self-hosted AI API Gateway platform designed for quota management, user control, and multi-provider routing. It helps manage API keys, distribute quotas, and control access across multiple AI providers.
Important Notice
Please read the following carefully before using this template:
- Terms of Service Risk: Using this project may violate the Terms of Service of Anthropic, OpenAI, and other upstream AI providers. All risks arising from such use are borne solely by the user.
- Compliant Use: Use this project only in compliance with the laws and regulations of your country or region. Any unlawful use is strictly prohibited.
- Disclaimer: This project is provided for technical learning and research purposes only. The authors and template creator assume no liability for account bans, service interruptions, or any damages resulting from the use of this project.
- No Commercial Authorization: This template is not authorized for commercial operations based on this project.
About Hosting Sub2API on Railway
This template deploys Sub2API with PostgreSQL for data persistence and Redis for job queuing and caching. It is configured for simple deployment where users only need to set an admin password via the ADMIN_PASSWORD environment variable before deploying. The template includes all necessary services (PostgreSQL + Redis) and is designed to be production-ready with minimal configuration. Railway handles infrastructure, HTTPS, scaling, and monitoring automatically.
Key Features of This Template
- Self-hosted AI API Gateway with quota management
- User management and role-based access control
- Multi-provider routing and load balancing
- Simple deployment — user only needs to set
ADMIN_PASSWORD - Includes PostgreSQL + Redis (pre-configured)
- Built-in usage tracking and quota control
- Production-ready with automatic scaling on Railway
Comparison with Alternatives
| Feature | This Template (Sub2API on Railway) | Manual Self-Hosting | One-API | LiteLLM Proxy |
|---|---|---|---|---|
| One-click deployment | ✅ Yes | ❌ No | ✅ Yes | ✅ Yes |
| Includes PostgreSQL + Redis | ✅ Yes (pre-configured) | ❌ Manual setup | ❌ SQLite only | ❌ No |
| Simple admin password setup | ✅ Yes (ADMIN_PASSWORD) | ❌ Complex | ✅ Yes | ✅ Yes |
| Quota management & user control | ✅ Strong | ❌ Manual | ✅ Good | ⚠️ Limited |
| Multi-provider routing | ✅ Excellent | ✅ Depends | ✅ Good | ✅ Good |
| Automatic HTTPS & Scaling | ✅ Fully managed | ❌ Self-managed | ✅ Yes | ✅ Yes |
| Ease of deployment | ✅ Very easy | ❌ Difficult | ✅ Easy | ✅ Easy |
| Best for production workloads | ✅ Strong | ❌ High effort | ✅ Good | ✅ Good |
Common Use Cases
- Managing and distributing AI API quotas across multiple users or teams
- Building internal AI API gateways with access control
- Creating a unified routing layer for multiple LLM providers
- Self-hosting an API management platform with usage tracking
- Controlling and monitoring AI API consumption
Dependencies for Sub2API Hosting
- PostgreSQL (for storing users, channels, and usage data)
- Redis (for caching and job queue)
Deployment Dependencies
- Official Sub2API Docker image (
ghcr.io/wei-shaw/sub2api:latest) - Railway PostgreSQL service
- Railway Redis service
- Environment variable
ADMIN_PASSWORDfor initial admin setup
Implementation Details
This template is designed for simplicity:
- Initial Admin Setup: Set
ADMIN_PASSWORDbefore deploying. After first login, you can create additional users and manage roles from the admin panel. - Database & Redis: Both PostgreSQL and Redis are included and pre-connected.
- Default Login (after deployment):
- Access the public URL provided by Railway
- Login using the admin credentials you set
Important: After first login, immediately change the default admin password and review security settings.
Why Deploy Sub2API 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 Sub2API 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
Redis
redis:8.2.1ADMIN_PASSWORD
