feat: add Sub2API application for AI API gateway platform

- Add Sub2API 1Panel application configuration
- Support subscription quota distribution, API Key management, billing and load balancing
- Include docker-compose.yml, data.yml, README documentation and logo
- Support amd64 and arm64 architectures
This commit is contained in:
arch3rPro
2026-03-24 19:00:29 +08:00
parent e1104e4dcf
commit 69ad9e1a76
9 changed files with 280 additions and 0 deletions

61
apps/sub2api/README.md Normal file
View File

@@ -0,0 +1,61 @@
# Sub2API
AI API 网关平台,用于分发和管理 AI 产品订阅的 API 配额。
## 功能特点
- 多账号管理 - 支持多种上游账号类型OAuth、API Key
- API Key 分发 - 为用户生成和管理 API Key
- 精确计费 - Token 级别使用追踪和费用计算
- 智能调度 - 智能账号选择,支持粘性会话
- 并发控制 - 支持用户级和账号级并发限制
- 限流 - 可配置的请求和 Token 限流
- 管理后台 - Web 界面用于监控和管理
- 外部系统集成 - 支持通过 iframe 嵌入外部系统
## 快速开始
### 默认端口
- Web 界面: 8080
### 初始化配置
部署完成后,访问 `http://YOUR_SERVER_IP:8080` 进入设置向导。
**数据库连接设置:**
- PostgreSQL 主机: `postgres`Docker 网络内使用服务名,不是 localhost
- Redis 主机: `redis`Docker 网络内使用服务名,不是 localhost
- PostgreSQL 密码: 请使用强密码
**JWT 密钥要求:**
- 长度必须至少 32 字符
- 生产环境请使用随机生成的强密码
### 数据目录
应用数据存储在 Docker 命名卷中:
- `postgres_data` - PostgreSQL 数据库数据
- `redis_data` - Redis 缓存数据
- `./data` - 应用配置和数据
## 相关链接
- 官方网站: https://sub2api.org
- GitHub: https://github.com/Wei-Shaw/sub2api
- 在线演示: https://demo.sub2api.org/
## 注意事项
1. **数据库连接**:在 Docker 部署中PostgreSQL 和 Redis 使用服务名(`postgres``redis`)进行连接,请勿使用 `localhost`
2. **JWT 密钥**:必须至少 32 字符,建议使用随机字符串
3. **首次部署**:如果遇到数据库连接错误,请确保:
- PostgreSQL 容器已完全启动(等待约 10-30 秒)
- 旧的损坏数据卷已清除(使用 `docker compose down -v`
4. **安全提醒**
- 本项目仅供个人学习使用
- 使用者必须在遵循 Anthropic、OpenAI 等服务条款的情况下使用
- 请勿用于非法用途

61
apps/sub2api/README_en.md Normal file
View File

@@ -0,0 +1,61 @@
# Sub2API
AI API Gateway Platform for subscription quota distribution.
## Features
- Multi-Account Management - Support multiple upstream account types (OAuth, API Key)
- API Key Distribution - Generate and manage API Keys for users
- Precise Billing - Token-level usage tracking and cost calculation
- Smart Scheduling - Intelligent account selection with sticky sessions
- Concurrency Control - Per-user and per-account concurrency limits
- Rate Limiting - Configurable request and token rate limits
- Admin Dashboard - Web interface for monitoring and management
- External System Integration - Embed external systems via iframe
## Quick Start
### Default Port
- Web UI: 8080
### Initial Setup
After deployment, access `http://YOUR_SERVER_IP:8080` to run the setup wizard.
**Database Connection Settings:**
- PostgreSQL Host: `postgres` (use service name in Docker network, NOT localhost)
- Redis Host: `redis` (use service name in Docker network, NOT localhost)
- PostgreSQL Password: Please use a strong password
**JWT Secret Requirements:**
- Length must be at least 32 characters
- Use a randomly generated strong password for production
### Data Directory
Application data is stored in Docker named volumes:
- `postgres_data` - PostgreSQL database data
- `redis_data` - Redis cache data
- `./data` - Application configuration and data
## Links
- Website: https://sub2api.org
- GitHub: https://github.com/Wei-Shaw/sub2api
- Demo: https://demo.sub2api.org/
## Important Notes
1. **Database Connection**: In Docker deployment, PostgreSQL and Redis use service names (`postgres`, `redis`) for connection. Do NOT use `localhost`
2. **JWT Secret**: Must be at least 32 characters, use a random string recommended
3. **First Deployment**: If you encounter database connection errors, ensure:
- PostgreSQL container has fully started (wait about 10-30 seconds)
- Old corrupted data volumes are cleared (use `docker compose down -v`)
4. **Disclaimer**:
- This project is for personal learning purposes only
- Users must comply with the Terms of Service of Anthropic, OpenAI, etc.
- Do not use for illegal purposes

22
apps/sub2api/data.yml Normal file
View File

@@ -0,0 +1,22 @@
name: Sub2API
tags:
- AI / 大模型
title: Sub2API - AI API 网关平台
description: Sub2API - AI API 网关平台
additionalProperties:
key: sub2api
name: Sub2API
tags:
- AI
shortDescZh: AI API 网关平台支持订阅配额分发、API Key 管理、计费和负载均衡
shortDescEn: AI API gateway platform for subscription quota distribution
type: website
crossVersionUpdate: true
limit: 0
recommend: 0
website: https://sub2api.org
github: https://github.com/Wei-Shaw/sub2api
document: https://github.com/Wei-Shaw/sub2api
architectures:
- amd64
- arm64

View File

@@ -0,0 +1,20 @@
server:
host: "0.0.0.0"
port: 8080
mode: "release"
database:
host: "postgres"
port: 5432
user: "sub2api"
password: "${POSTGRES_PASSWORD}"
dbname: "sub2api"
redis:
host: "redis"
port: 6379
password: ""
jwt:
secret: "sub2api_jwt_secret_change_in_production_32chars"
expire_hour: 24

View File

@@ -0,0 +1,33 @@
additionalProperties:
formFields:
- default: 8080
edit: true
envKey: PANEL_APP_PORT_HTTP
labelEn: Web Port
labelZh: Web 端口
required: true
rule: paramPort
type: number
- default: Asia/Shanghai
edit: true
envKey: TZ
labelEn: Time Zone
labelZh: 时区
required: true
type: text
- default: sub2api_secure_jwt_secret_change_in_production
edit: true
envKey: JWT_SECRET
labelEn: JWT Secret
labelZh: JWT 密钥
required: true
rule: paramCommon
type: password
- default: sub2api_secure_db_password_change_in_production
edit: true
envKey: POSTGRES_PASSWORD
labelEn: PostgreSQL Password
labelZh: PostgreSQL 密码
required: true
rule: paramCommon
type: password

View File

View File

@@ -0,0 +1,26 @@
server:
host: "0.0.0.0"
port: 8080
mode: "release"
database:
host: "postgres"
port: 5432
user: "sub2api"
password: "${POSTGRES_PASSWORD}"
dbname: "sub2api"
redis:
host: "redis"
port: 6379
password: ""
jwt:
secret: "${JWT_SECRET}"
expire_hour: 24
default:
user_concurrency: 5
user_balance: 0
api_key_prefix: "sk-"
rate_multiplier: 1.0

View File

@@ -0,0 +1,57 @@
services:
sub2api:
image: weishaw/sub2api:latest
container_name: ${CONTAINER_NAME}
restart: always
networks:
- 1panel-network
ports:
- "${PANEL_APP_PORT_HTTP}:8080"
volumes:
- ./data:/app/data
- ./config.yaml:/app/config.yaml:ro
environment:
- TZ=${TZ}
- POSTGRES_CONN_STRING=postgres://sub2api:${POSTGRES_PASSWORD}@postgres:5432/sub2api?sslmode=disable
- REDIS_CONN_STRING=redis://redis:6379/0
- JWT_SECRET=${JWT_SECRET}
labels:
createdBy: "Apps"
depends_on:
- postgres
- redis
postgres:
image: postgres:15-alpine
container_name: ${CONTAINER_NAME}-postgres
restart: always
networks:
- 1panel-network
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=sub2api
- POSTGRES_USER=sub2api
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
labels:
createdBy: "Apps"
redis:
image: redis:7-alpine
container_name: ${CONTAINER_NAME}-redis
restart: always
networks:
- 1panel-network
volumes:
- redis_data:/data
command: redis-server --appendonly yes
labels:
createdBy: "Apps"
networks:
1panel-network:
external: true
volumes:
postgres_data:
redis_data:

BIN
apps/sub2api/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB