wei-shaw/sub2api is a self-hosted AI API gateway for accessing upstream AI services through platform-generated API keys. It handles authentication, billing, load balancing, and request forwarding.
Project overview
It brings multi-account management, token-level billing, routing controls, and user API-key distribution into one gateway for teams operating access to multiple upstream AI services.
Project type
Infrastructure
Deployment
Refer to project documentation
License
LGPL-3.0
Best for
Operations teams and developers that need a self-hosted gateway for shared access to upstream AI services, platform-generated API keys, account routing, and usage-based billing.
Key capabilities
Manages multiple upstream account types, including OAuth and API key accounts, for gateway use.
Generates and manages API keys for users accessing upstream services through the platform.
Tracks usage at token level and calculates associated costs for platform billing.
Selects upstream accounts intelligently and supports sticky sessions for request routing.
Applies per-user and per-account concurrency limits to gateway traffic.
Configures request and token rate limits for gateway traffic.
Provides user self-service top-up through EasyPay, Alipay, WeChat Pay, and Stripe without a separate payment-service deployment.
Provides a web interface for monitoring and management of the gateway.
Limitations and risks
The gateway depends on upstream AI services and does not itself provide those services. Requested models must be provided by upstream AI services.
xAI quota remains unknown before the first usable upstream response.
Nginx reverse-proxy deployments require special header configuration for sticky-session routing when used with Codex CLI.
Before adoption, check the terms of service of Anthropic and other upstream providers because the source states that use of the project may violate those terms.
Adoption planning should account for the source’s disclaimer regarding account bans, service interruptions, data loss, and other direct or indirect damages.
Confirm that the planned use complies with applicable laws and regulations; the source prohibits unlawful use.
Getting started
Install the documented prerequisites, choose the script installation or Docker Compose deployment, start the service, complete the Setup Wizard for database, Redis, and administrator account configuration, and open the service at the documented server address.
Evidence and sources
GitHub project description
README: Sub2API is an AI API gateway platform designed to distribute and manage API quotas from AI product subscriptions. Users can access upstream AI services through platform-generated…
README: **AI API Gateway Platform for Subscription Quota Distribution**