$ show Wei-Shaw/sub2api
This repository is a full-stack, multi-tenant AI API gateway platform (named 'sub2api') that proxies requests to a wide range of AI model providers including OpenAI, Anthropic, Gemini, Grok, DeepSeek, and many others. It provides authentication (JWT, OAuth, API keys), rate limiting, token-level billing, subscription management, user and admin management, payment processing (Alipay, WeChat Pay, Stripe, Airwallex, EasyPay), content moderation, channel monitoring, and operational dashboards. The backend is written in Go using the Gin framework and Ent ORM, with PostgreSQL and Redis for data storage and caching. The frontend is built with Vue 3, TypeScript, and Pinia stores, offering both admin and user interfaces. The system is designed for production deployment with Docker, includes extensive unit and integration tests, and supports a plugin architecture for extensible OAuth transport. Despite its large codebase and many features, the architecture follows a clear service-repository pattern with well-isolated packages, making it a solid example of a complex API gateway implementation.
The LLM identified 7 files worth highlighting for reuse:
Provides a reusable pagination abstraction with sort normalization, limit clamping, and offset calculation. Self-contained and can be extracted into any Go web project.
Implements Server-Timing header collection for measuring and exposing server performance metrics. Demonstrates non-obvious skill in HTTP instrumentation and is reusable across Go services.
Defines a typed error hierarchy with HTTP status mapping, enabling consistent error responses across the API. This pattern is reusable for any Go service that needs structured error handling.
Provides safe body reading with memory limits and lenient JSON parsing. Useful for any HTTP service that needs to handle large or malformed request bodies without crashing.
Implements a Redis-backed session store with multi-instance support, suitable for distributed OAuth session management. Demonstrates a clean abstraction over Redis with TTL and atomic operations.
Provides a unified interface for multiple web search providers (Brave, Tavily) with fallback and configuration. Demonstrates the provider pattern and can be reused in any application needing web search integration.
Translates between OpenAI Chat Completions and Responses API formats, handling complex transformations like tool calls, streaming, and reasoning. This non-trivial protocol translation logic is reusable in any API gateway that needs to bridge different AI provider formats.