How ranxi2001/sub2api works
Sub2API is an AI API gateway for distributing managed upstream account capacity. The main workflow is a client API-key request, gateway authentication and account selection, protocol adaptation and upstream forwarding, followed by usage-based billing. The README also documents account and key administration, user authentication, payments, and Mihomo egress management. Some links reflect README-described capabilities because their implementation was not sampled; uncertain internal wiring is omitted.
Main entry points: gateway_handler.go Gateway handlers · openai_gateway_handler.go OpenAI gateway · provider Payment providers · payment_handler.go Payment handlers
Components 22
API gateway
- Gateway handlers
backend/internal/handler/gateway_handler.go - OpenAI gateway
backend/internal/handler/openai_gateway_handler.go - CC pipeline
backend/internal/service/openai_gateway_cc_pipeline.go - Protocol adapters
backend/internal/pkg/apicompat
Accounts and access
- Account management
backend/internal/handler/admin/account_handler.go - API keys
backend/internal/handler/api_key_handler.go - User authentication
backend/internal/handler/auth_handler.go - OpenAI OAuth
backend/internal/handler/admin/openai_oauth_handler.go
Billing and payments
- Payment handlers
backend/internal/handler/payment_handler.go - Payment webhooks
backend/internal/handler/payment_webhook_handler.go - Payment providers
backend/internal/payment/provider
Operations
- Application database
backend/ent - Redis
- Mihomo egress
backend/internal/mihomo/manager.go - Web search
backend/internal/pkg/websearch/manager.go - Image storage settings
backend/internal/service/image_storage_settings.go - S3 image storage
backend/internal/repository/image_storage_s3.go
Other components
- API client
- AI providers
- Platform user
- Administrator
- S3-compatible storage
Connections 21
- API client → Gateway handlers: sends API request
- Gateway handlers → OpenAI gateway: dispatches request
- OpenAI gateway → Protocol adapters: adapts protocol
- OpenAI gateway → CC pipeline: handles CC requests
- CC pipeline → AI providers: forwards request
- OpenAI gateway → AI providers: forwards request
- Administrator → Account management: manages accounts
- Administrator → API keys: manages keys
- Platform user → User authentication: authenticates
- Administrator → OpenAI OAuth: manages OAuth
- Platform user → Payment handlers: initiates payment
- Payment handlers → Payment providers: requests payment
- Payment providers → Payment handlers: returns payment status
- Payment providers → Payment webhooks: sends payment event
- Gateway handlers → Application database: reads account data
- Gateway handlers → Redis: uses cache and limits
- Gateway handlers → Mihomo egress: uses configured egress
- Web search → Redis: reserves quota
- Administrator → Image storage settings: configures storage
- Image storage settings → S3 image storage: creates uploader
- S3 image storage → S3-compatible storage: uploads images