English | 中文
One-click deploy Sub2API on Railway with PostgreSQL and Redis included.
Railway Deploy Link:
https://railway.com/deploy/sub2api-railway-template
This repository provides a Railway deployment template for Sub2API.
Sub2API is a high-performance AI API gateway built for managing, distributing, and monitoring usage across subscription-based AI accounts. With this template, you can deploy a complete Sub2API stack on Railway in one click, including the core application, PostgreSQL database, and Redis cache.
Railway automatically provisions the required infrastructure and connects all services over its private network, making deployment fast, secure, and easy to manage.
- One-click deployment on Railway
- Includes Sub2API, PostgreSQL, and Redis
- Suitable for production-ready setup
- Private network communication between services
- Simple initialization flow through the Sub2API web interface
This template deploys the following services:
-
Sub2API Gateway
The main application, including backend API and web UI -
PostgreSQL
Used for persistent storage such as users, API keys, billing records, and system configuration -
Redis
Used for caching, rate limiting, queue management, and performance optimization
After deployment, you need to configure the following environment variables for the Sub2API service.
| Variable | Required | Description |
|---|---|---|
ADMIN_EMAIL |
Yes | Email address for the initial administrator account. You can set this freely. |
TOTP_ENCRYPTION_KEY |
Yes | Encryption key used for TOTP-related data. Must be securely generated. |
You can set any email address you want, for example:
ADMIN_EMAIL=admin@example.comGenerate it with:
openssl rand -hex 32Example:
TOTP_ENCRYPTION_KEY=your_generated_64_char_hex_stringRecommended: keep this value secret and do not change it after your instance is initialized unless you know the impact on existing encrypted data.
- Open the Railway deploy link:
https://railway.com/deploy/sub2api-railway-template - Create a new Railway project from this template
- Wait for Railway to provision:
- Sub2API
- PostgreSQL
- Redis
- Open the Sub2API service in your Railway project
- Add the required environment variables:
ADMIN_EMAILTOTP_ENCRYPTION_KEY
- Go to Settings
- Click Generate Domain
- Open the generated domain in your browser
- Complete the Sub2API initialization process
- Share AI subscription quota across team members
- Track token usage and operational costs
- Build a centralized AI API gateway
- Manage upstream routing, rate limiting, and access control
- Railway Deploy: https://railway.com/deploy/sub2api-railway-template
- Sub2API Repository: https://github.com/Wei-Shaw/sub2api
- Docker Image: https://hub.docker.com/r/weishaw/sub2api
- Documentation: https://github.com/Wei-Shaw/sub2api/blob/main/README_CN.md
- Make sure
TOTP_ENCRYPTION_KEYis generated securely before first use ADMIN_EMAILcan be any email address you choose- You can further scale services using Railway if your workload grows
Please refer to the upstream Sub2API project for license details:
https://github.com/Wei-Shaw/sub2api