Wei-Shaw / sub2api
Sub2API-CRS2 一站式开源中转服务,让 Claude、Openai 、Gemini、Antigravity订阅统一接入,支持拼车共享,更高效分摊成本,原生工具无缝使用。
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing Wei-Shaw/sub2api in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler viewSub2API **AI API Gateway Platform for Subscription Quota Distribution** English | 中文 --- Demo Try Sub2API online: **https://demo.sub2api.org/** Demo credentials (shared demo environment; **not** created automatically for self-hosted installs): | Email | Password | |-------|----------| | admin@sub2api.com | admin123 | Overview Sub2API is an AI API gateway platform designed to distribute and manage API quotas from AI product subscriptions (like Claude Code $200/month). Users can access upstream AI services through platform-generated API Keys, while the platform handles authentication, billing, load balancing, and request forwarding. 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 (e.g. payment, ticketing) via iframe to extend the admin dashboard Ecosystem Community projects that extend or integrate with Sub2API: | Project | Description | Features | |---------|-------------|----------| | Sub2ApiPay | Self-service payment system | Self-service top-up and subscription purchase; supports YiPay protocol, WeChat Pay, Alipay, Stripe; embeddable via iframe | | sub2api-mobile | Mobile admin console | Cross-platform app (iOS/Android/Web) for user management, account management, monitoring dashboard, and multi-backend switching; built with Expo + React Native | Tech Stack | Component | Technology | |-----------|------------| | Backend | Go 1.25.7, Gin, Ent | | Frontend | Vue 3.4+, Vite 5+, TailwindCSS | | Database | PostgreSQL 15+ | | Cache/Queue | Redis 7+ | --- Documentation • Dependency Security: • Admin Payment Integration API: --- Deployment Method 1: Script Installation (Recommended) One-click installation script that downloads pre-built binaries from GitHub Releases. Prerequisites • Linux server (amd64 or arm64) • PostgreSQL 15+ (installed and running) • Redis 7+ (installed and running) • Root privileges Installation Steps The script will: • Detect your system architecture • Download the latest release • Install binary to • Create systemd service • Configure system user and permissions Post-Installation The Setup Wizard will guide you through: • Database configuration • Redis configuration • Admin account creation Upgrade You can upgrade directly from the **Admin Dashboard** by clicking the **Check for Updates** button in the top-left corner. The web interface will: • Check for new versions automatically • Download and apply updates with one click • Support rollback if needed Useful Commands --- Method 2: Docker Compose (Recommended) Deploy with Docker Compose, including PostgreSQL and Redis containers. Prerequisites • Docker 20.10+ • Docker Compose v2+ Quick Start (One-Click Deployment) Use the automated deployment script for easy setup: **What the script does:** • Downloads (saved as ) and • Generates secure credentials (JWT_SECRET, TOTP_ENCRYPTION_KEY, POSTGRES_PASSWORD) • Creates file with auto-generated secrets • Creates data directories (uses local directories for easy backup/migration) • Displays generated credentials for your reference Manual Deployment If you prefer manual setup: **Required configuration in :** **Generate secure secrets:** Deployment Versions | Version | Data Storage | Migration | Best For | |---------|-------------|-----------|----------| | **docker-compose.local.yml** | Local directories | ✅ Easy (tar entire directory) | Production, frequent backups | | **docker-compose.yml** | Named volumes | ⚠️ Requires docker commands | Simple setup | **Recommendation:** Use (deployed by script) for easier data management. Access Open in your browser. If admin password was auto-generated, find it in logs: Upgrade Easy Migration (Local Directory Version) When using , migrate to a new server easily: Useful Commands --- Method 3: Build from Source Build and run from source code for development or customization. Prerequisites • Go 1.21+ • Node.js 18+ • PostgreSQL 15+ • Redis 7+ Build Steps > **Note:** The flag embeds the frontend into the binary. Without this flag, the binary will not serve the frontend UI. **Key configuration in :** Sora Status (Temporarily Unavailable) > ⚠️ Sora-related features are temporarily unavailable due to technical issues in upstream integration and media delivery. > Please do not rely on Sora in production at this time. > Existing configuration keys are reserved and may not take effect until these issues are resolved. Additional security-related options are available in : • for CORS allowlist • for upstream/pricing/CRS host allowlists • to disable URL validation (use with caution) • to allow HTTP URLs when validation is disabled • to allow private/local IP addresses • to enable configurable response header filtering (disabled uses default allowlist) • to control Content-Security-Policy headers • to fail closed on billing errors • to enable X-Forwarded-For parsing • to require Turnstile in release mode **⚠️ Security Warning: HTTP URL Configuration** When , the system performs minimal URL validation by default, **rejecting HTTP URLs** and only allowing HTTPS. To allow HTTP URLs (e.g., for development or internal testing), you must explicitly set: **Or via environment variable:** **Risks of allowing HTTP:** • API keys and data transmitted in **plaintext** (vulnerable to interception) • Susceptible to **man-in-the-middle (MITM) attacks** • **NOT suitable for production** environments **When to use HTTP:** • ✅ Development/testing with local servers (http://localhost) • ✅ Inte…