How jay-luo-jj/sub2api works
Sub2API is a self-hosted AI API gateway for distributing quota from managed upstream subscriptions. The principal workflow is that a user obtains a platform API key, sends an AI request through the gateway, and receives a forwarded upstream response; the platform authenticates, schedules accounts, and tracks billable usage along the way. Separate capabilities include account and key administration, a web dashboard, and user top-ups through integrated payment providers. The README documents the product flow; sampled source offers limited wiring evidence, so undocumented internal calls are omitted.
Main entry points: gateway_handler.go Gateway Requests · App.vue Web Application · usage_handler.go Usage Tracking · payment Payment System
Components 17
User Access
- Web Application
frontend/src/App.vue - Authentication
backend/internal/handler/auth_handler.go - API Keys
backend/internal/handler/api_key_handler.go
AI Gateway
- Gateway Requests
backend/internal/handler/gateway_handler.go - Account Scheduling
backend/internal/repository/channel_repo.go - API Compatibility
backend/internal/pkg/apicompat
Platform Operations
- Upstream Accounts
backend/internal/handler/admin/account_handler.go - Admin Dashboard
backend/internal/handler/admin/dashboard_handler.go - Platform Data
backend/ent - Backend Server
backend/cmd/server/main.go
Billing and Payments
- Usage Tracking
backend/internal/handler/usage_handler.go - Billing
backend/internal/repository/usage_billing_repo.go - Payment System
backend/internal/payment
Other components
- API User
- Administrator
- AI Providers
- Payment Providers
Connections 16
- API User → Web Application: uses dashboard
README.md - Administrator → Web Application: manages platform
README.md - Web Application → Authentication: authenticates
- API User → API Keys: obtains API key
README.md - Administrator → Upstream Accounts: manages accounts
README.md - API User → Gateway Requests: sends AI request
README.md - Gateway Requests → API Keys: authenticates key
- Gateway Requests → Account Scheduling: selects account
README.md - Gateway Requests → API Compatibility: transforms request
- Gateway Requests → AI Providers: forwards request
README.md - Gateway Requests → Usage Tracking: tracks usage
README.md - Usage Tracking → Billing: calculates charges
README.md - API User → Payment System: tops up account
README.md - Payment System → Payment Providers: processes payment
README.md - Administrator → Admin Dashboard: monitors platform
README.md - Backend Server → Platform Data: persists platform data