Introduction
Sub2API is an open-source relay platform written in Go that consolidates multiple AI provider subscriptions into a single unified API endpoint. It supports Claude, OpenAI, Gemini, and other providers, enabling teams to share and manage AI access through one gateway.
What Sub2API Does
- Proxies requests to multiple AI providers through a single endpoint
- Supports load balancing across multiple subscription accounts
- Provides token usage tracking and quota management per account
- Offers an OpenAI-compatible API format for broad tool compatibility
- Enables team access sharing with per-user rate limiting
Architecture Overview
Sub2API is a stateless Go binary that acts as a reverse proxy. Incoming API requests are routed to the appropriate provider based on model name and configuration rules. Account credentials are stored in a YAML config file and rotated automatically when rate limits are hit. The relay translates between provider-specific API formats and presents a unified OpenAI-compatible interface.
Self-Hosting & Configuration
- Build from source with Go 1.21+ or use pre-built Docker images
- Configure provider accounts and credentials in config.yaml
- Set per-account rate limits and priority ordering
- Enable optional authentication for downstream clients
- Deploy behind a reverse proxy for TLS termination
Key Features
- Single endpoint for Claude, OpenAI, Gemini, and more
- Automatic failover and load balancing across accounts
- OpenAI-compatible API format for broad tool compatibility
- Per-user and per-account usage tracking
- Lightweight Go binary with minimal resource requirements
Comparison with Similar Tools
- LiteLLM — Python-based proxy with more features; Sub2API is Go-native and lighter
- OpenRouter — managed service; Sub2API is fully self-hosted
- Portkey AI Gateway — enterprise-focused; Sub2API is simpler to deploy
- one-api — similar concept; Sub2API focuses on subscription-based account management
FAQ
Q: Does Sub2API store my API keys securely? A: Keys are stored in the config file. Use file permissions and secrets management for production deployments.
Q: Can I use it with tools that expect an OpenAI API? A: Yes. Sub2API exposes an OpenAI-compatible endpoint, so most tools work without modification.
Q: How does load balancing work? A: Requests are distributed across configured accounts based on priority and remaining quota.
Q: Is there a web dashboard? A: The project focuses on the API relay. Usage metrics are available via API endpoints for integration with external dashboards.