Wei-Shaw/sub2apiPublic

Sub2API 一站式开源中转服务,让 Claude、Openai 、Gemini、Grok订阅统一接入,支持拼车共享,更高效分摊成本,原生工具无缝使用。

AI summary: An AI API gateway platform that unifies subscriptions and enables quota distribution and sharing.

Stars
41.2K
+271 today
Forks
8.6K
Watchers
86
Open issues
2.3K
Open PRs
747
Contributors
~399
Commits
6.5K
Branches
32

GoLGPL-3.0Created Dec 18, 2025Last push todayLatest release v0.2.0+1K stars this week+2.1K this month

Star history

since Dec 14, 2025
020K40KDec 2025Mar 2026Jun 2026Sep 2026
41.2K stars as of Sep 10, 2026, tracked back to Dec 14, 2025. Historical curve reconstructed from public GitHub event archives, calibrated to the current total.

Contribution activity

commits per day, last 52 weeks
SepOctNovDecJanFebMarAprMayJunJulAugMonWedFri2025-09-06: 0 commits2025-09-07: 0 commits2025-09-08: 0 commits2025-09-09: 0 commits2025-09-10: 0 commits2025-09-11: 0 commits2025-09-12: 0 commits2025-09-13: 0 commits2025-09-14: 0 commits2025-09-15: 0 commits2025-09-16: 0 commits2025-09-17: 0 commits2025-09-18: 0 commits2025-09-19: 0 commits2025-09-20: 0 commits2025-09-21: 0 commits2025-09-22: 0 commits2025-09-23: 0 commits2025-09-24: 0 commits2025-09-25: 0 commits2025-09-26: 0 commits2025-09-27: 0 commits2025-09-28: 0 commits2025-09-29: 0 commits2025-09-30: 0 commits2025-10-01: 0 commits2025-10-02: 0 commits2025-10-03: 0 commits2025-10-04: 0 commits2025-10-05: 0 commits2025-10-06: 0 commits2025-10-07: 0 commits2025-10-08: 0 commits2025-10-09: 0 commits2025-10-10: 0 commits2025-10-11: 0 commits2025-10-12: 0 commits2025-10-13: 0 commits2025-10-14: 0 commits2025-10-15: 0 commits2025-10-16: 0 commits2025-10-17: 0 commits2025-10-18: 0 commits2025-10-19: 0 commits2025-10-20: 0 commits2025-10-21: 0 commits2025-10-22: 0 commits2025-10-23: 0 commits2025-10-24: 0 commits2025-10-25: 0 commits2025-10-26: 0 commits2025-10-27: 0 commits2025-10-28: 0 commits2025-10-29: 0 commits2025-10-30: 0 commits2025-10-31: 0 commits2025-11-01: 0 commits2025-11-02: 0 commits2025-11-03: 0 commits2025-11-04: 0 commits2025-11-05: 0 commits2025-11-06: 0 commits2025-11-07: 0 commits2025-11-09: 0 commits2025-11-10: 0 commits2025-11-11: 0 commits2025-11-12: 0 commits2025-11-13: 0 commits2025-11-14: 0 commits2025-11-15: 0 commits2025-11-16: 0 commits2025-11-17: 0 commits2025-11-18: 0 commits2025-11-19: 0 commits2025-11-20: 0 commits2025-11-21: 0 commits2025-11-22: 0 commits2025-11-23: 0 commits2025-11-24: 0 commits2025-11-25: 0 commits2025-11-26: 0 commits2025-11-27: 0 commits2025-11-28: 0 commits2025-11-29: 0 commits2025-11-30: 0 commits2025-12-01: 0 commits2025-12-02: 0 commits2025-12-03: 0 commits2025-12-04: 0 commits2025-12-05: 0 commits2025-12-06: 0 commits2025-12-07: 0 commits2025-12-08: 0 commits2025-12-09: 0 commits2025-12-10: 0 commits2025-12-11: 0 commits2025-12-12: 0 commits2025-12-13: 0 commits2025-12-14: 0 commits2025-12-15: 0 commits2025-12-16: 0 commits2025-12-17: 0 commits2025-12-18: 27 commits2025-12-19: 20 commits2025-12-20: 16 commits2025-12-21: 1 commit2025-12-22: 1 commit2025-12-23: 17 commits2025-12-24: 17 commits2025-12-25: 46 commits2025-12-26: 16 commits2025-12-27: 34 commits2025-12-28: 27 commits2025-12-29: 52 commits2025-12-30: 26 commits2025-12-31: 38 commits2026-01-01: 32 commits2026-01-02: 15 commits2026-01-03: 26 commits2026-01-04: 56 commits2026-01-05: 35 commits2026-01-06: 19 commits2026-01-07: 7 commits2026-01-08: 14 commits2026-01-09: 41 commits2026-01-10: 28 commits2026-01-11: 49 commits2026-01-12: 49 commits2026-01-13: 8 commits2026-01-14: 44 commits2026-01-15: 34 commits2026-01-16: 32 commits2026-01-17: 25 commits2026-01-18: 17 commits2026-01-19: 27 commits2026-01-20: 22 commits2026-01-21: 7 commits2026-01-22: 2 commits2026-01-23: 11 commits2026-01-24: 8 commits2026-01-25: 3 commits2026-01-26: 9 commits2026-01-27: 7 commits2026-01-28: 5 commits2026-01-29: 15 commits2026-01-30: 6 commits2026-01-31: 7 commits2026-02-01: 4 commits2026-02-02: 16 commits2026-02-03: 30 commits2026-02-04: 7 commits2026-02-05: 18 commits2026-02-06: 22 commits2026-02-07: 52 commits2026-02-08: 17 commits2026-02-09: 34 commits2026-02-10: 18 commits2026-02-11: 10 commits2026-02-12: 27 commits2026-02-13: 11 commits2026-02-14: 17 commits2026-02-15: 0 commits2026-02-16: 1 commit2026-02-17: 1 commit2026-02-18: 3 commits2026-02-19: 10 commits2026-02-20: 2 commits2026-02-21: 5 commits2026-02-22: 11 commits2026-02-23: 7 commits2026-02-24: 37 commits2026-02-25: 16 commits2026-02-26: 13 commits2026-02-27: 6 commits2026-02-28: 32 commits2026-03-01: 20 commits2026-03-02: 7 commits2026-03-03: 23 commits2026-03-04: 16 commits2026-03-05: 25 commits2026-03-06: 33 commits2026-03-07: 30 commits2026-03-08: 17 commits2026-03-09: 20 commits2026-03-10: 10 commits2026-03-11: 18 commits2026-03-12: 20 commits2026-03-13: 15 commits2026-03-14: 22 commits2026-03-15: 23 commits2026-03-16: 29 commits2026-03-17: 20 commits2026-03-18: 19 commits2026-03-19: 13 commits2026-03-20: 8 commits2026-03-21: 22 commits2026-03-22: 2 commits2026-03-23: 14 commits2026-03-24: 15 commits2026-03-25: 5 commits2026-03-26: 2 commits2026-03-27: 11 commits2026-03-28: 5 commits2026-03-29: 3 commits2026-03-30: 31 commits2026-03-31: 19 commits2026-04-01: 22 commits2026-04-02: 27 commits2026-04-03: 5 commits2026-04-04: 6 commits2026-04-05: 31 commits2026-04-06: 1 commit2026-04-07: 9 commits2026-04-08: 9 commits2026-04-09: 20 commits2026-04-10: 11 commits2026-04-11: 18 commits2026-04-12: 26 commits2026-04-13: 38 commits2026-04-14: 25 commits2026-04-15: 18 commits2026-04-16: 8 commits2026-04-17: 9 commits2026-04-18: 3 commits2026-04-19: 6 commits2026-04-20: 45 commits2026-04-21: 112 commits2026-04-22: 49 commits2026-04-23: 27 commits2026-04-24: 18 commits2026-04-25: 20 commits2026-04-26: 8 commits2026-04-27: 12 commits2026-04-28: 7 commits2026-04-29: 13 commits2026-04-30: 11 commits2026-05-01: 1 commit2026-05-02: 7 commits2026-05-03: 11 commits2026-05-04: 4 commits2026-05-05: 7 commits2026-05-06: 6 commits2026-05-07: 15 commits2026-05-08: 7 commits2026-05-09: 4 commits2026-05-10: 1 commit2026-05-11: 13 commits2026-05-12: 9 commits2026-05-13: 2 commits2026-05-14: 11 commits2026-05-15: 10 commits2026-05-16: 5 commits2026-05-17: 6 commits2026-05-18: 20 commits2026-05-19: 33 commits2026-05-20: 39 commits2026-05-21: 12 commits2026-05-22: 4 commits2026-05-23: 6 commits2026-05-24: 3 commits2026-05-25: 5 commits2026-05-26: 18 commits2026-05-27: 10 commits2026-05-28: 12 commits2026-05-29: 19 commits2026-05-30: 7 commits2026-05-31: 10 commits2026-06-01: 9 commits2026-06-02: 6 commits2026-06-03: 11 commits2026-06-04: 8 commits2026-06-05: 8 commits2026-06-06: 14 commits2026-06-07: 8 commits2026-06-08: 7 commits2026-06-09: 11 commits2026-06-10: 10 commits2026-06-11: 6 commits2026-06-12: 17 commits2026-06-13: 2 commits2026-06-14: 4 commits2026-06-15: 3 commits2026-06-16: 21 commits2026-06-17: 5 commits2026-06-18: 10 commits2026-06-19: 7 commits2026-06-20: 1 commit2026-06-21: 4 commits2026-06-22: 6 commits2026-06-23: 10 commits2026-06-24: 5 commits2026-06-25: 9 commits2026-06-26: 15 commits2026-06-27: 4 commits2026-06-28: 3 commits2026-06-29: 4 commits2026-06-30: 18 commits2026-07-01: 41 commits2026-07-02: 17 commits2026-07-03: 13 commits2026-07-04: 11 commits2026-07-05: 8 commits2026-07-06: 37 commits2026-07-07: 54 commits2026-07-08: 11 commits2026-07-09: 28 commits2026-07-10: 41 commits2026-07-11: 15 commits2026-07-12: 14 commits2026-07-13: 43 commits2026-07-14: 60 commits2026-07-15: 76 commits2026-07-16: 33 commits2026-07-17: 33 commits2026-07-18: 25 commits2026-07-19: 50 commits2026-07-20: 43 commits2026-07-21: 15 commits2026-07-22: 13 commits2026-07-23: 23 commits2026-07-24: 12 commits2026-07-25: 21 commits2026-07-26: 24 commits2026-07-27: 19 commits2026-07-28: 13 commits2026-07-29: 17 commits2026-07-30: 13 commits2026-07-31: 22 commits2026-08-01: 13 commits2026-08-02: 9 commits2026-08-03: 12 commits2026-08-04: 11 commits2026-08-05: 6 commits2026-08-06: 10 commits2026-08-07: 89 commits2026-08-08: 43 commits2026-08-09: 5 commits2026-08-10: 11 commits2026-08-11: 15 commits2026-08-12: 9 commits2026-08-13: 19 commits2026-08-14: 12 commits2026-08-15: 12 commits2026-08-16: 6 commits2026-08-17: 21 commits2026-08-18: 34 commits2026-08-19: 38 commits2026-08-20: 49 commits2026-08-21: 16 commits2026-08-22: 17 commits2026-08-23: 33 commits2026-08-24: 28 commits2026-08-25: 25 commits2026-08-26: 10 commits2026-08-27: 11 commits2026-08-28: 16 commits2026-08-29: 13 commits2026-08-30: 26 commits2026-08-31: 16 commits2026-09-01: 23 commits2026-09-02: 4 commits2026-09-03: 3 commits2026-09-04: 0 commits2026-09-05: 0 commits
4,629 commits in the last yearLessMore

Signals and awards

derived from tracked data
  • Widely adopted

    41,152 stars

  • Very active

    4,629 commits in 52 weeks

  • Community-driven

    ~399 contributors

What sub2api does

Sub2API serves as a centralized gateway for managing multiple AI provider subscriptions, including Anthropic, OpenAI, Gemini, and Grok. It converts direct subscription access into standard API endpoints, allowing users to integrate these powerful models seamlessly into native tools and applications. The platform introduces a quota distribution system designed to facilitate subscription sharing and cost splitting among multiple users. By pooling resources, it maximizes the utility of premium AI subscriptions while providing a unified, standardized interface for developers. It effectively lowers the barrier to accessing top-tier models by enabling efficient, shared consumption.

Geared towards developers, small teams, and AI enthusiasts looking to optimize the costs of premium AI subscriptions through secure, organized sharing and unified API access. Users are expected to have a basic understanding of the relevant underlying technologies.

  • Unified API gateway: Standardizes access to various AI providers into a single, cohesive API interface.
  • Subscription pooling: Allows multiple users to share a single premium AI subscription to significantly reduce individual costs.
  • Quota management system: Distributes and tracks API usage across different users to ensure fair access and prevent abuse.
  • Native tool integration: Enables direct connection to existing AI-powered developer tools without requiring custom adapters.
  • Multi-provider support: Connects simultaneously to Anthropic, OpenAI, Gemini, and Grok through a centralized hub.

Where teams use it

Cost-sharing communities

Small teams or developer communities pooling funds to share the cost of expensive premium AI subscriptions.

Unified tool integration

Developers pointing their local AI coding assistants to a single endpoint that routes to multiple underlying providers.

Subscription management

Centralizing the billing and API key management for various AI services into one manageable dashboard.

Quota distribution

Allocating specific usage limits to different team members sharing a single corporate AI account.

Getting started: docker-compose up -d

README

main branch
Sub2API Logo

Sub2API

Go Vue PostgreSQL Redis Docker

Wei-Shaw%2Fsub2api | Trendshift

AI API Gateway Platform for Subscription Quota Distribution

English | 中文 | 日本語

⚠️ Important Notice

Please read the following carefully before using this project:

  • 🚨 Terms of Service Risk: Using this project may violate the terms of service of Anthropic and other upstream providers. Please review the relevant providers' user agreements before use; all risks arising from such use are borne solely by the user.
  • ⚖️ Compliant Use: Use this project only in compliance with the laws and regulations of your country or region. Any unlawful use is strictly prohibited.
  • 📖 Disclaimer: This project is provided for technical learning and research purposes only. The authors assume no liability for account bans, service interruptions, data loss, or any other direct or indirect damages resulting from the use of this project.
  • 🚫 No Commercial Authorization: The developers of this project have never authorized any individual or organization to conduct any form of commercial operation based on this project. Any commercial activity conducted in the name of or based on this project is unrelated to this project and its developers, and all resulting disputes, losses, and legal liabilities shall be borne solely by the party conducting such activity.

❤️ Sponsors

Want to appear here?

CCTK.AI Thanks to CCTK.AI for sponsoring this project! CCTK.AI is an AI API gateway focused on stability and cost-effectiveness, offering fast relay services for Claude, OpenAI, Gemini, and other popular models. It works seamlessly with Claude Code, Codex, and other mainstream coding tools, delivering the same model capabilities at a fraction of the official cost. Register via this link for faster, more stable, and more affordable AI API access.
openmodel One API, every top model! OpenModel is a production-grade, high-availability AI API gateway that makes your applications truly fast and stable: automatic failover, smart routing to the best-performing channel, and a production-grade SLA. An SLA that far surpasses any single provider — making stability your core competitive advantage. Works directly with Claude Code, Codex, and Gemini CLI. Register via this link to get started.
ETok Thanks to ETok.ai for sponsoring this project! ETok.ai is dedicated to building a one-stop AI programming tool service platform. We offer professional Claude Code packages and technical community services, with support for Google Gemini and OpenAI Codex. Through carefully designed plans and a professional tech community, we provide developers with reliable service guarantees and continuous technical support, making AI-assisted programming a true productivity tool. Click here to register!
APIKEY.FUN Thanks to APIKEY.FUN for sponsoring this project! APIKEY.FUN is one of the core contributors to the sub2api open-source project, dedicated to providing open, stable, and cost-effective AI API access. The platform supports API relay services for Claude, OpenAI, Gemini, and other popular models, with pricing starting from as low as 7% of the original rate. Register via the exclusive link: APIKEY to enjoy up to 5% off on all recharges.
AIGoCode Thanks to AIGoCode for sponsoring this project! AIGoCode is an all-in-one platform that integrates Claude Code, Codex, and the latest Gemini models, providing you with stable, efficient, and highly cost-effective AI coding services. The platform offers flexible subscription plans, zero risk of account suspension, direct access with no VPN required, and lightning-fast responses. AIGoCode has prepared a special benefit for sub2api users: if you register via this link, you'll receive an extra 10% bonus credit on your first top-up!
CodexEverywhere Real GPT-5.6 series at 3% of OpenAI pricing — CodexEverywhere is democratizing access to frontier models for developers worldwide. We believe in transparency and honesty, with model quality verified by active community oversight for months. USD and crypto friendly. Start with a free $20 trial at codex-everywhere.com.
bmoplus Huge thanks to BmoPlus for sponsoring this project! BmoPlus is a highly reliable AI account provider built strictly for heavy AI users and developers. They offer rock-solid, ready-to-use accounts and official top-up services for ChatGPT Plus / ChatGPT Pro (Full Warranty) / Claude Pro / Super Grok / Gemini Pro. By registering and ordering through BmoPlus - Premium AI Accounts & Top-ups, users can unlock the mind-blowing rate of 10% of the official GPT subscription price (90% OFF)
bestproxy Thanks to Bestproxy for sponsoring this project! Bestproxy provides high-purity residential IPs with dedicated one-IP-per-account support. By combining real home networks with fingerprint isolation, it enables link environment isolation and reduces the probability of association-based risk control.
pateway Thanks to PatewayAI for sponsoring this project! PatewayAI is a premium API relay built for heavy AI developers, offering the full Claude and Codex series sourced 100% from official providers, with transparent token-level billing. Enterprise plans include high concurrency, dedicated management, contracts, and invoicing. Register now to get $3 in trial credits, top-ups from 60% off, and referral bonuses up to $150.
pptoken Thanks to PPToken.cc for sponsoring this project! PPToken.cc specializes in GPT model API relay services, supporting Codex, Claude Code, OpenAI-compatible clients, and Gemini CLI integration. Top-ups are 1:1 (¥1 = $1 credit); GPT models start at 0.16x rate multiplier, with overall cost at roughly 2.2% of official pricing and first-token latency around 1 second — ideal for developers seeking low-cost, high-speed access to GPT model capabilities. Technical support: 24/7 real human responses (no bots), @tech in the group chat and get a reply within 10 minutes. Sponsor benefit: the first 200 users who register via the exclusive registration link and enter promo code `SUB2API` can claim free Codex / Claude Code trial credits — no minimum spend, no card required.
veilx Thanks to Veilx for sponsoring this project! Veilx CDN is purpose-built for large-scale AI API traffic, deeply optimized for relay services and call chains across OpenAI, Claude, Gemini, and scenarios like chat, image generation, embeddings, and streaming — delivering lower latency and higher stability under heavy concurrency. It also offers China three-network optimized return lines, making it ideal for global AI relay platforms, overseas AI SaaS, and cross-border high-concurrency deployments.
veilx Thanks to RoxyBrowser for sponsoring this project! RoxyBrowser RoxyBrowser is the perfect partner for Sub2API: it features a built-in native Roxy AI Agent and high-quality native residential IPs, supports batch automation via simple commands, and significantly boosts security and efficiency for multi-account management! Click this link to sign up and receive a free residential IP package plus a 10% lifetime discount.
proxy4free Thanks to Proxy4Free for sponsoring this project! Proxy4Free is a data proxy service provider for developers and AI applications, offering residential proxies, static residential proxies, ISP proxies, and datacenter proxies for scenarios such as Web Scraping, Browser Automation, and AI Agents. With global IP resources, stable connections, and flexible switching, it helps developers improve data collection success rates and reduce the risk of IP bans. Register via this link to get started and easily build more stable and efficient automation workflows.
fastaitoken 🎉 Thanks to FastAIToken for sponsoring this project! FastAIToken is an AI API aggregation platform for developers, supporting mainstream large models such as OpenAI, Claude, and Gemini. Top-up at 1:1 — 1 CNY = 1 USD of API credit — letting developers use the world's leading large model services at lower cost and with greater convenience.

🚀 The platform offers a variety of channels to choose from: an ultra-low-price 0.02x OpenAI promotional group (limited time), groups as low as 0.25x OpenAI, 0.7x Claude with 95% fixed cache, and a 1.2x Claude Max channel. It also provides a public status page showing real-time availability, latency, and operating status of each group for transparent and reliable service, plus 7×24 human technical support (not bots) with fast responses to developer needs.

aimzoon Thanks to Aimzoon for sponsoring this project! Aimzoon provides stable, cost-effective AI API access services, enabling developers to quickly connect popular AI services to coding tools such as Codex, Claude Code, and Gemini CLI. No complex configuration — faster onboarding, more stable calls, and lower costs. Ongoing promotions including discounted Codex rates and special pricing, with free trial credits upon registration, bringing AI coding into your daily workflow. Click here to register and try it out!
Nagora Nagora is a multi-model AI API gateway built for developers and teams. With a single account and API key, you can access more than 26 leading text and image models through one unified interface. It is compatible with OpenAI, Anthropic, and Gemini protocols and integrates seamlessly with development tools such as Claude Code, Codex, and Gemini CLI. The platform provides intelligent routing, automatic failover, transparent pricing, and consolidated billing, along with budget management, rate limiting, and concurrency controls. This makes AI usage more reliable and manageable across individual development, team collaboration, and production environments. No changes to your existing application are required. Simply replace the Base URL and API key to complete the integration in as little as one minute.
Qiniu AI Thanks to Qiniu AI for sponsoring this project! Qiniu AI is the enterprise-grade large-model MaaS platform under Qiniu Cloud (02567.HK), offering one-stop access to 150+ mainstream models worldwide, compatible with the protocols of major global model providers, and covering full-modality capabilities including text, image, audio, video, and file processing, serving over 1.69 million enterprises and developers. Qiniu AI offers an exclusive benefit for Sub2API users: register via this link — enterprise users get 12 million tokens free, and developers get 3 million tokens free.
FennoAI Thanks to FennoAI for sponsoring this project! FennoAI is a high-stability, high-performance API relay provider for enterprise R&D teams and developers, compatible with the OpenAI and Anthropic protocols and seamlessly integrating with mainstream AI coding tools such as Codex, Claude Code, and OpenCode. The platform delivers enterprise-grade stability, supporting call volumes of 100 billion tokens per day, and supports business-to-business settlement and invoicing for both domestic and overseas entities to meet enterprise R&D and procurement needs. As an exclusive benefit for Sub2API users, purchase a subscription via the exclusive link to get $50 worth of Coding Plan credit for only $1.99. Referral rewards are also available: invite friends to purchase and earn up to 20% commission — the more you invite, the more you earn.
LanoX AI Thank you to LanoX AI for sponsoring this project! LanoX AI provides stable, cost-effective global model access services for developers, teams, and enterprises. 🎁 New User Benefits — Claim millions of free tokens, plus 500+ free models for easier low-cost testing, validation, and deployment 🧠 Global Leading Models — GPT · Claude · Gemini · Qwen · Grok... 🎬 Multimodal Creation — Seedance 2.0 · GPT Image · Gemini Nano Banana 🛡️ Enterprise-Grade Reliability — High availability 💎 native capability output 💎 no intelligence degradation 💎 no model mixing 💎 transparent usage and billing 💎 💰 Lower API Costs — Top-tier models from as low as 10% of official pricing, with clear documentation, simple integration, invoicing support, and enterprise-scale batch usage 🏢 Enterprise Choice — Ideal for AI products, Agents, content platforms, and R&D teams with high-volume model usage
RapidProxy RapidProxy is a data collection proxy solution built for developers, providing stable and reliable residential proxy services. With 90M+ global residential IPs and 200+ country coverage, intelligent rotation, and precise geo-targeting, it helps projects such as web scraping, AI data training, SEO monitoring, and e-commerce data analysis break through access restrictions and improve data collection efficiency. It supports mainstream automation frameworks such as Playwright, Selenium, and Puppeteer, with prices as low as $0.65/GB — start your free test now.
hao.ai hao.ai is a high-speed, stable unified large-model API gateway for developers and teams. With a single API Key and a unified interface, you can access mainstream models such as GPT, Claude, and xAI Grok, with compatibility for common protocols and SDKs including OpenAI and Anthropic. The platform provides model routing, failover, team management, and complete request logs, with model prices as low as 15% of official reference pricing, helping users build AI applications more simply, more reliably, and at lower cost.
Swiftproxy Swiftproxy is a high-performance proxy solution built for developers, providing stable and reliable residential and static residential proxy services. With 90M+ clean residential IPs, global coverage, flexible rotation, and precise geo-targeting, it helps projects such as web scraping, AI automation, browser automation, SEO monitoring, and multi-account management overcome access restrictions and improve workflow efficiency. It supports HTTP(S) and SOCKS5 protocols, integrates with popular automation tools like Playwright, Selenium, and Puppeteer, with dynamic proxy traffic that never expires until used and free testing available — start your free test now!
DuckIP DuckIP - 90M+ global residential network resources across 195+ countries and regions, with rotation and sticky sessions for public data collection, RAG updates, model evaluation, and multi-region data workloads. 🟢Residential Proxy - 20% Off; 🟢Static Residential Proxy - Starting at ¥50.00/IP; 🟢Unlimited Residential Proxy - Starting at ¥19.8/Hour. ✅Get 500M Free Trial.
APIMart Thanks to APIMart for sponsoring this project! APIMart is a low-cost API platform for AI image and video generation — GPT-Image-2 from $0.006 per image, with 160+ images per dollar. One async API covers both image and video: submit a task, get an ID, and retrieve results via polling or callback. Batch tens of thousands of images without timeouts, and switch models without changing code. Pay as you go with no monthly fee — sign up here to get started.
AxisNow Thanks to AxisNow for sponsoring this project! AxisNow protects and accelerates websites and APIs, delivering an optimal access experience across mainland China and globally, while extending acceleration and security capabilities to native/mobile apps through client SDKs — self-hosted private-deployment CDN | subscription-based DDoS-protected CDN | autonomous, flexibly composable CDN network.

Overview

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 API Keys, while the platform handles authentication, billing, load balancing, and request forwarding.

Features

  • Multi-Account Management - Support multiple upstream account types (OAuth, API Key)
  • API Key Distribution - Generate and manage API Keys for users
  • Precise Billing - Token-level usage tracking and cost calculation
  • Smart Scheduling - Intelligent account selection with sticky sessions
  • Concurrency Control - Per-user and per-account concurrency limits
  • Rate Limiting - Configurable request and token rate limits
  • Built-in Payment System - Supports EasyPay, Alipay, WeChat Pay, and Stripe for user self-service top-up, no separate payment service needed (Configuration Guide)
  • Admin Dashboard - Web interface for monitoring and management
  • Composite Groups - Admin routing layer that resolves requested models to concrete providers for multi-provider groups (Operator Guide)
  • External System Integration - Embed external systems (e.g. ticketing) via iframe to extend the admin dashboard

Ecosystem

Community projects that extend or integrate with Sub2API:

Project Description Features
Sub2ApiPay Self-service payment system Now Built-in — Payment is now integrated into Sub2API, no separate deployment needed. See Payment Configuration Guide
sub2api-mobile Mobile admin console Cross-platform app (iOS/Android/Web) for user management, account management, monitoring dashboard, and multi-backend switching; built with Expo + React Native

Tech Stack

Component Technology
Backend Go 1.27.0, Gin, Ent
Frontend Vue 3.4+, Vite 5+, TailwindCSS
Database PostgreSQL 15+
Cache/Queue Redis 7+

Nginx Reverse Proxy Note

When using Nginx as a reverse proxy for Sub2API (or CRS) with Codex CLI, add the following to the http block in your Nginx configuration:

underscores_in_headers on;

Nginx drops headers containing underscores by default (e.g. session_id), which breaks sticky session routing in multi-account setups.


Deployment

Method 1: Script Installation (Recommended)

One-click installation script that downloads pre-built binaries from GitHub Releases.

Prerequisites

  • Linux server (amd64 or arm64)
  • PostgreSQL 15+ (installed and running)
  • Redis 7+ (installed and running)
  • Root privileges

Installation Steps

curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash

The script will:

  1. Detect your system architecture
  2. Download the latest release
  3. Install binary to /opt/sub2api
  4. Create systemd service
  5. Configure system user and permissions

Post-Installation

# 1. Start the service
sudo systemctl start sub2api

# 2. Enable auto-start on boot
sudo systemctl enable sub2api

# 3. Open Setup Wizard in browser
# http://YOUR_SERVER_IP:8080

The Setup Wizard will guide you through:

  • Database configuration
  • Redis configuration
  • Admin account creation

Upgrade

You can upgrade directly from the Admin Dashboard by clicking the Check for Updates button in the top-left corner.

The web interface will:

  • Check for new versions automatically
  • Download and apply updates with one click
  • Support rollback if needed

Useful Commands

# Check status
sudo systemctl status sub2api

# View logs
sudo journalctl -u sub2api -f

# Restart service
sudo systemctl restart sub2api

# Uninstall
curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash -s -- uninstall -y

Method 2: Docker Compose (Recommended)

Deploy with Docker Compose, including PostgreSQL and Redis containers.

Prerequisites

  • Docker 20.10+
  • Docker Compose v2+

Quick Start (One-Click Deployment)

Use the automated deployment script for easy setup:

# Create deployment directory
mkdir -p sub2api-deploy && cd sub2api-deploy

# Download and run deployment preparation script
curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/docker-deploy.sh | bash

# Start services
docker compose up -d

# View logs
docker compose logs -f sub2api

What the script does:

  • Downloads docker-compose.local.yml (saved as docker-compose.yml) and .env.example
  • Generates secure credentials (JWT_SECRET, TOTP_ENCRYPTION_KEY, POSTGRES_PASSWORD)
  • Creates .env file with auto-generated secrets
  • Creates data directories (uses local directories for easy backup/migration)
  • Displays generated credentials for your reference

Manual Deployment

If you prefer manual setup:

# 1. Clone the repository
git clone https://github.com/Wei-Shaw/sub2api.git
cd sub2api/deploy

# 2. Copy environment configuration
cp .env.example .env
chmod 600 .env

# 3. Edit configuration (generate secure passwords)
nano .env

Required configuration in .env:

# PostgreSQL password (REQUIRED)
POSTGRES_PASSWORD=your_secure_password_here

# JWT Secret (RECOMMENDED - keeps users logged in after restart)
JWT_SECRET=your_jwt_secret_here

# TOTP Encryption Key (RECOMMENDED - preserves 2FA after restart)
TOTP_ENCRYPTION_KEY=your_totp_key_here

# Optional: Admin account
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=your_admin_password

# Optional: Custom port
SERVER_PORT=8080

Generate secure secrets:

# Generate JWT_SECRET
openssl rand -hex 32

# Generate TOTP_ENCRYPTION_KEY
openssl rand -hex 32

# Generate POSTGRES_PASSWORD
openssl rand -hex 32
# 4. Create data directories (for local version)
mkdir -p data postgres_data redis_data

# 5. Start all services
# Option A: Local directory version (recommended - easy migration)
docker compose -f docker-compose.local.yml up -d

# Option B: Named volumes version (simple setup)
docker compose up -d

# 6. Check status
docker compose -f docker-compose.local.yml ps

# 7. View logs
docker compose -f docker-compose.local.yml logs -f sub2api

Deployment Versions

Version Data Storage Migration Best For
docker-compose.local.yml Local directories ✅ Easy (tar entire directory) Production, frequent backups
docker-compose.yml Named volumes ⚠️ Requires docker commands Simple setup

Recommendation: Use docker-compose.local.yml (deployed by script) for easier data management.

Access

Open http://YOUR_SERVER_IP:8080 in your browser.

If admin password was auto-generated, find it in logs:

docker compose -f docker-compose.local.yml logs sub2api | grep "admin password"

Upgrade

# Pull latest image and recreate container
docker compose -f docker-compose.local.yml pull
docker compose -f docker-compose.local.yml up -d

Easy Migration (Local Directory Version)

When using docker-compose.local.yml, migrate to a new server easily:

# On source server
docker compose -f docker-compose.local.yml down
cd ..
tar czf sub2api-complete.tar.gz sub2api-deploy/

# Transfer to new server
scp sub2api-complete.tar.gz user@new-server:/path/

# On new server
tar xzf sub2api-complete.tar.gz
cd sub2api-deploy/
docker compose -f docker-compose.local.yml up -d

Useful Commands

# Stop all services
docker compose -f docker-compose.local.yml down

# Restart
docker compose -f docker-compose.local.yml restart

# View all logs
docker compose -f docker-compose.local.yml logs -f

# Remove all data (caution!)
docker compose -f docker-compose.local.yml down
rm -rf data/ postgres_data/ redis_data/

Method 3: Apple container (macOS)

Apple-silicon Macs running macOS 26 can run the full Sub2API, PostgreSQL, and Redis stack with Apple container 1.1.0 or newer:

git clone https://github.com/Wei-Shaw/sub2api.git
cd sub2api/deploy
./apple-container.sh init
./apple-container.sh up
./apple-container.sh status

This is an operator-managed local workflow; Docker Compose remains the recommended production path. See deploy/APPLE_CONTAINER.md for lifecycle commands, persistence, upgrades, and runtime limitations.


Method 4: Build from Source

Build and run from source code for development or customization.

Prerequisites

  • Go 1.21+
  • Node.js 18+
  • PostgreSQL 15+
  • Redis 7+

Build Steps

# 1. Clone the repository
git clone https://github.com/Wei-Shaw/sub2api.git
cd sub2api

# 2. Install pnpm (if not already installed)
npm install -g pnpm

# 3. Build frontend
cd frontend
pnpm install
pnpm run build
# Output will be in ../backend/internal/web/dist/

# 4. Build backend with embedded frontend
cd ../backend
VERSION="$(./scripts/resolve-version.sh)"
go build -tags embed -ldflags="-X main.Version=${VERSION}" -o sub2api ./cmd/server

# 5. Create configuration file
cp ../deploy/config.example.yaml ./config.yaml

# 6. Edit configuration
nano config.yaml

Note: The -tags embed flag embeds the frontend into the binary. Without this flag, the binary will not serve the frontend UI.

Key configuration in config.yaml:

server:
  host: "0.0.0.0"
  port: 8080
  mode: "release"

database:
  host: "localhost"
  port: 5432
  user: "postgres"
  password: "your_password"
  dbname: "sub2api"

redis:
  host: "localhost"
  port: 6379
  username: ""
  password: ""

jwt:
  secret: "change-this-to-a-secure-random-string"
  expire_hour: 24

default:
  user_concurrency: 5
  user_balance: 0
  api_key_prefix: "sk-"
  rate_multiplier: 1.0

Additional security-related options are available in config.yaml:

  • cors.allowed_origins for CORS allowlist
  • security.url_allowlist for upstream/pricing/CRS host allowlists
  • security.url_allowlist.enabled to disable URL validation (use with caution)
  • security.url_allowlist.allow_insecure_http to allow HTTP URLs when validation is disabled
  • security.url_allowlist.allow_private_hosts to allow private/local IP addresses
  • security.response_headers.enabled to enable configurable response header filtering (disabled uses default allowlist)
  • security.csp to control Content-Security-Policy headers
  • billing.circuit_breaker to fail closed on billing errors
  • security.trust_forwarded_ip_for_api_key_acl enables legacy raw forwarded-header takeover (enabled by default for upgrade compatibility); disable it to enforce server.trusted_proxies, which should contain only the exact proxy CIDRs that connect directly to Sub2API
  • security.forwarded_client_ip_headers configures up to 16 third-party CDN client-IP header names; they are checked in order before the built-in headers only while legacy takeover is enabled
  • turnstile.required to require Turnstile in release mode

Custom client-IP headers can be set in YAML or as a comma-separated environment variable:

SECURITY_FORWARDED_CLIENT_IP_HEADERS=True-Client-IP,X-CDN-Client-IP

Header names are validated, canonicalized, and de-duplicated. The admin security settings can update the list without a restart; new installations persist YAML/environment defaults and existing installations backfill a missing database value. When legacy takeover is disabled, all custom and built-in raw forwarding headers are ignored and Gin uses only server.trusted_proxies. While takeover is enabled, firewall the origin to CDN/proxy addresses and make the edge overwrite every trusted client-IP header. See deploy/EDGE_SECURITY.md for the complete migration and trust-boundary rules.

⚠️ Security Warning: HTTP URL Configuration

When security.url_allowlist.enabled=false, the system performs minimal URL validation and allows HTTP URLs by default (dev-friendly mode; Docker Compose deployments use the same default). For production, explicitly tighten this to HTTPS-only:

security:
  url_allowlist:
    enabled: false                # Disable allowlist checks
    allow_insecure_http: false    # HTTPS only (recommended for production)

Or via environment variable:

SECURITY_URL_ALLOWLIST_ENABLED=false
SECURITY_URL_ALLOWLIST_ALLOW_INSECURE_HTTP=false

Risks of allowing HTTP:

  • API keys and data transmitted in plaintext (vulnerable to interception)
  • Susceptible to man-in-the-middle (MITM) attacks
  • NOT suitable for production environments

When to use HTTP:

  • ✅ Development/testing with local servers (http://localhost)
  • ✅ Internal networks with trusted endpoints
  • ✅ Testing account connectivity before obtaining HTTPS
  • ❌ Production environments (use HTTPS only)

Example error for HTTP URLs when allow_insecure_http: false is set:

Invalid base URL: invalid url scheme: http

If you disable URL validation or response header filtering, harden your network layer:

  • Enforce an egress allowlist for upstream domains/IPs
  • Block private/loopback/link-local ranges
  • Enforce TLS-only outbound traffic
  • Strip sensitive upstream response headers at the proxy

OpenAI Responses WebSocket ingress limits

gateway.openai_ws bounds the lifetime and aggregate count of client-facing Responses WebSocket sessions. These safeguards apply independently from per-turn user and account concurrency slots, which are released between turns.

gateway:
  openai_ws:
    # Total time to receive and decompress the first client message.
    client_first_message_timeout_seconds: 30
    # Close a client socket idle between completed turns; 0 disables this safeguard.
    ingress_inter_turn_idle_timeout_seconds: 300
    # Distributed API-key limit for live client ingress sessions; 0 disables it.
    max_ingress_connections_per_api_key: 64

The first-message timeout is a total read deadline. Deployments that accept large contexts or image-heavy requests over slower links can raise it to 120-300 seconds. It expires before HTTP bridge routing, so bridge mode does not override this limit.

The connection cap is coordinated through Redis using a 60-second lease that is refreshed every 20 seconds. A process that cannot confirm a lease for a full lease lifetime closes its local WebSocket rather than continuing outside the global cap.

Enable the v2 mode router before selecting an account-level WS mode such as http_bridge:

gateway:
  openai_ws:
    mode_router_v2_enabled: true

Or set GATEWAY_OPENAI_WS_MODE_ROUTER_V2_ENABLED=true in the environment. Use http_bridge for client-WebSocket/upstream-HTTP operation when rolling out or mitigating upstream WebSocket issues.

Force OpenAI upstream HTTP/SSE

When an egress proxy or network repeatedly reconnects OpenAI Responses WebSockets, set the global fallback in the persisted deployment configuration:

gateway:
  openai_ws:
    force_http: true

For Compose and Apple container deployments, the equivalent .env setting is:

GATEWAY_OPENAI_WS_FORCE_HTTP=true

This selects HTTP/SSE for OpenAI upstream Responses traffic that would otherwise use WebSocket. It does not change the client-facing protocol or force HTTP/1.1; configure gateway.openai_http2.enabled (or GATEWAY_OPENAI_HTTP2_ENABLED=false) separately when a proxy is incompatible with HTTP/2. Unlike the account-level http_bridge mode, this global fallback takes effect without enabling mode_router_v2_enabled. Keep the setting in the deployment's persisted .env or config.yaml, rather than inside a running container, so it is read again after an image update or container recreation.

⚠️ Important: Creating the Admin Account

The initial admin account is only created via the setup wizard (served at http://<host>:8080 on first run). The default.admin_email / default.admin_password fields in config.yaml are not used to create it — they exist in the template for historical reasons.

Because step 5 above pre-creates config.yaml, the setup wizard will be skipped on first run: the server detects an existing config and boots straight into normal mode with an empty users table, so the first login attempt fails with invalid email or password.

Two ways to create the admin account:

  1. Recommended — let the wizard generate config.yaml: Skip step 5 (do not run the cp). Start ./sub2api directly; the setup wizard at http://localhost:8080 walks you through database, Redis, and admin account setup, then writes config.yaml for you.

  2. If you already created config.yaml: Temporarily move it aside so the wizard can trigger on first run, then restore it afterwards:

    mv config.yaml config.yaml.bak
    ./sub2api        # wizard runs at http://localhost:8080 and writes a fresh config.yaml
    # stop the server (Ctrl+C) once the wizard completes, then restore your config:
    mv config.yaml.bak config.yaml
    ./sub2api        # restart in normal mode and log in with the admin you just created
# 6. Run the application
./sub2api

Development Mode

# Backend (with hot reload)
cd backend
go run ./cmd/server

# Frontend (with hot reload)
cd frontend
pnpm run dev

Code Generation

When editing backend/ent/schema, regenerate Ent + Wire:

cd backend
go generate ./ent
go generate ./cmd/server

Simple Mode

Simple Mode is designed for individual developers or internal teams who want quick access without full SaaS features.

  • Enable: Set environment variable RUN_MODE=simple
  • Difference: Hides SaaS-related features and skips billing process
  • Security note: In production, you must also set SIMPLE_MODE_CONFIRM=true to allow startup

Asynchronous Image Tasks

Long-running OpenAI/Grok image generation and editing can be submitted through /v1/images/generations/async or /v1/images/edits/async, then polled at /v1/images/tasks/{task_id} without holding a CDN connection open. See Asynchronous Image Tasks for request and response examples.


Grok / xAI Support

Sub2API supports both Grok subscription accounts through xAI OAuth and standard xAI API-key accounts. Both account types forward OpenAI-compatible Responses traffic to xAI.

Supported Scope

  • Platform name: grok
  • Account types: OAuth subscription accounts and xAI API-key accounts
  • Public Responses targets: /v1/responses, /responses, and /backend-api/codex/responses, forwarded to the Grok subscription proxy for OAuth accounts or https://api.x.ai/v1/responses for API-key accounts
  • Public Claude-compatible target: /v1/messages, converted to xAI Responses and returned as Anthropic Messages output for Claude CLI style clients
  • Public Chat Completions targets: /v1/chat/completions and /chat/completions, forwarded to the account-type-specific xAI upstream
  • Codex CLI style Responses WebSocket ingress is accepted on the Responses targets and bridged to xAI HTTP/SSE Responses upstream
  • Text models: grok-4.5, grok-4.3, grok-build-0.1, grok-composer-2.5-fast, grok-4.20-0309-reasoning, grok-4.20-0309-non-reasoning, and grok-4.20-multi-agent-0309
  • Media targets for Grok groups: /v1/images/generations, /images/generations, /v1/images/edits, /images/edits, /v1/videos/generations, /videos/generations, /v1/videos/edits, /videos/edits, /v1/videos/extensions, /videos/extensions, /v1/videos/{request_id}, and /videos/{request_id}. Generation, editing, and extension requests require the group image-generation permission.
  • Media models: grok-imagine, grok-imagine-image-quality, grok-imagine-image, grok-imagine-image-2.0, grok-imagine-edit, grok-imagine-video, and grok-imagine-video-1.5
  • JSON image-edit and video-generation requests accept image references in image, images, reference_images, and mask objects. Use url for xAI-compatible payloads; the legacy image_url field remains accepted and is normalized to url before forwarding.
  • Out of scope for this provider: TTS, transcription, browser automation, cookies, and Grok web scraping

OAuth Configuration

The Grok OAuth flow uses PKCE and does not require committing private secrets. The default client details follow the public xAI OAuth flow used by compatible clients, and every value can be overridden by environment variable:

Variable Default
XAI_OAUTH_CLIENT_ID Public xAI OAuth client ID
XAI_OAUTH_SCOPE openid profile email offline_access grok-cli:access api:access
XAI_OAUTH_REDIRECT_URI http://127.0.0.1:56121/callback
XAI_OAUTH_AUTHORIZE_URL https://auth.x.ai/oauth2/authorize
XAI_OAUTH_TOKEN_URL https://auth.x.ai/oauth2/token
XAI_BASE_URL https://api.x.ai/v1; runtime-diagnostics override (account base_url controls request forwarding)
XAI_GROK_CLI_VERSION 0.2.114; optional override for the client identity sent to cli-chat-proxy.grok.com. The pinned value is also the floor: an override below it is dropped

Administrators can create Grok OAuth or API-key accounts from the dashboard. OAuth authorization and reauthorization are also available through the admin API:

Endpoint Purpose
POST /api/v1/admin/grok/oauth/auth-url Generate an xAI OAuth authorization URL
POST /api/v1/admin/grok/oauth/exchange-code Exchange a callback URL, query string, or code for OAuth credentials
POST /api/v1/admin/grok/oauth/refresh-token Validate or refresh a Grok refresh token
POST /api/v1/admin/grok/accounts/:id/refresh Refresh an existing Grok account

OAuth credential storage reuses the existing account JSON fields: access_token, refresh_token, token_type, expires_at, base_url, optional email, optional subscription_tier, and entitlement_status. OAuth inference defaults to https://cli-chat-proxy.grok.com/v1; existing OAuth accounts that stored the old https://api.x.ai/v1 default are redirected to the subscription proxy at runtime. Explicit custom upstreams remain unchanged.

For API-key accounts, select Grok → API Key in the create-account dialog. The official base URL defaults to https://api.x.ai/v1; credentials use the existing base_url and api_key account fields. OAuth accounts continue to use the subscription flow above.

Grok Build CLI Configuration

  1. In the Sub2API admin dashboard, add either a grok OAuth account and complete xAI authorization, or add a Grok API-key account.
  2. Create a Grok group, attach the account to it, then create a Sub2API API key assigned to that group.
  3. In the user API-key page, click Use Key and select Grok CLI. The modal generates the correct file and base URL for macOS/Linux or Windows. It also provides an OpenCode configuration on the OpenCode tab.
  4. If configuring manually, save the following as ~/.grok/config.toml (Windows: %USERPROFILE%\.grok\config.toml):
[models]
default = "grok"
web_search = "grok"

[model."grok"]
model = "grok-4.5"
base_url = "https://your-sub2api.example.com/v1"
name = "Grok 4.5"
api_key = "sk-your-sub2api-key"
api_backend = "responses"
context_window = 1000000
supports_backend_search = true

Back up an existing config.toml before merging the entry. The file contains a Sub2API API key, so keep it private and restrict its permissions where supported. Verify the effective configuration and make a smoke request:

grok inspect
grok -p "Reply with sub2api-ok" -m grok

The base_url above is the public Sub2API URL ending in /v1, not api.x.ai or the internal xAI OAuth proxy URL.

Usage And Quota Display

xAI quota is passive. Sub2API does not invent subscription quota values; it records whitelisted xAI rate-limit headers from successful or rate-limited upstream responses when xAI sends them. Before the first usable upstream response, the dashboard shows quota as unknown and still displays local Sub2API usage stats.

401 responses temporarily remove accounts with invalid credentials from scheduling. 403 responses are treated as access or entitlement failures instead of token-refresh loops. 429 responses use Retry-After or a short cooldown to temporarily remove the account from scheduling.

New Grok image and video generation requests use a media-specific eligibility check. API-key accounts remain eligible. OAuth accounts require positive paid-entitlement evidence from the xAI billing probe; Free, forbidden, missing, malformed, and inconclusive billing observations are excluded from new media generation. Unobserved OAuth accounts are probed before the first media request is forwarded, and imports run the billing-first quota probe proactively. Chat requests and video status lookups are not affected by this media-only quarantine. If no eligible account remains, the media endpoint returns HTTP 503 with error type grok_media_no_eligible_account.

Administrators can override automatic media eligibility through the account create/update API by setting extra.grok_media_eligible to false (exclude) or true (force eligible). On update, set it to null to remove the override and return to automatic probe-based behavior; omitting the field preserves the current override. A weekly allowance period alone is not treated as a paid tier signal. Successful image responses must contain at least one actual image output; empty HTTP 200 responses trigger account failover instead of being counted and returned as successful generations.


Antigravity Support

Sub2API supports Antigravity accounts. After authorization, dedicated endpoints are available for Claude and Gemini models.

Dedicated Endpoints

Endpoint Model
/antigravity/v1/messages Claude models
/antigravity/v1beta/ Gemini models

Claude Code Configuration

export ANTHROPIC_BASE_URL="http://localhost:8080/antigravity"
export ANTHROPIC_AUTH_TOKEN="sk-xxx"

Hybrid Scheduling Mode

Antigravity accounts support optional hybrid scheduling. When enabled, the general endpoints /v1/messages and /v1beta/ will also route requests to Antigravity accounts.

⚠️ Warning: Anthropic Claude and Antigravity Claude cannot be mixed within the same conversation context. Use groups to isolate them properly.


Project Structure

sub2api/
├── backend/                  # Go backend service
│   ├── cmd/server/           # Application entry
│   ├── internal/             # Internal modules
│   │   ├── config/           # Configuration
│   │   ├── model/            # Data models
│   │   ├── service/          # Business logic
│   │   ├── handler/          # HTTP handlers
│   │   └── gateway/          # API gateway core
│   └── resources/            # Static resources
│
├── frontend/                 # Vue 3 frontend
│   └── src/
│       ├── api/              # API calls
│       ├── stores/           # State management
│       ├── views/            # Page components
│       └── components/       # Reusable components
│
└── deploy/                   # Deployment files
    ├── docker-compose.yml    # Docker Compose configuration
    ├── .env.example          # Environment variables for Docker Compose
    ├── config.example.yaml   # Full config file for binary deployment
    └── install.sh            # One-click installation script

Star History

Star History Chart

License

This project is licensed under the GNU Lesser General Public License v3.0 (or later).

Copyright (c) 2026 Wesley Liddick


If you find this project useful, please give it a star!

View on GitHub

Recent activity

commits and pull requests

Releases and announcements

46 total
  1. Sub2API 0.2.0v0.2.0Sep 2, 202624K downloads

    > AI API Gateway Platform - 将 AI 订阅配额分发和管理 新增 OpenAI Fast 分组策略、按模型配置 reasoning effort,以及 Kimi 原生 Responses API 转发支持。 ## 新增功能 - 分组支持配置 OpenAI Fast,并支持将免费 Fast 请求按 Standard 价格计费 - 支持按模型设置 OpenAI reasoning effort 映射,并可配置超限时拒绝或降级 - 支持转发 Kimi 原生 OpenAI Responses API - 支持 Claude Fable 5.1 - 支持没有 call ID 的定时自动化启动请求 ## 优化改进 - 优化分组模型定价弹窗布局 - 保留调度器快照中的 OpenAI passthrough 配置 - 改进 OpenAI API Key 对话缓存身份处理 ## Bug 修复 - 修复 WebSocket 在收到 terminal event 前关闭时的处理问题 - 修复模型级冷却导致 `model_not_found` 被错误转换为 `429` 的问题 - 修复未启用 server-side-fallback beta 时仍透传 Anthropic fallback 的问题 --- ## 📥 Installation **Docker:** ```bash # Docker Hub docker pull weishaw/sub2api:0.2.0 # GitHub Container Registry docker pull ghcr.io/wei-shaw/sub2api:0.2.0 ``` **One-line install (Linux):** ```bash curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash ``` **Manual download:** Download the appropriate archive for your platform from the assets below. ## 📚 Documentation - [GitHub Repository](https://github.com/Wei-Shaw/sub2api) - [Installation Guide](https://github.com/Wei-Shaw/sub2api/blob/main/deploy/README.md)

  2. Sub2API 0.1.185v0.1.185Sep 1, 202615.2K downloads

    > AI API Gateway Platform - 将 AI 订阅配额分发和管理 升级价格目录与长上下文计费体系,并增强 Codex/OpenAI 网关兼容性和连接稳定性。 ## 新增功能 - 价格目录支持通过 `pricing.override_file` 使用 JSON 补丁覆盖官方价格数据。 - 长上下文阶梯计价改为由价格目录驱动,支持不同模型和渠道的动态定价策略。 - Codex 快速模型支持展示 priority service tier。 ## 优化改进 - 优化账号统计成本计算,统一应用模型定价策略及 DeepSeek 峰谷价格。 - 优化数据库启动时的瞬时错误重试机制,提升服务启动稳定性。 - 优化 OpenAI WebSocket 连接池,自动回收过期空闲连接。 - 优化 Codex 模型能力目录,保留已知的图像输入能力。 - 优化 Gemini Pro 缓存写入价格及价格目录契约校验。 ## Bug 修复 - 修复 API Key 请求被错误合成 instructions 的问题。 - 修复 Codex 模型目录中持续禁用账号仍被选中的问题。 - 修复 ctx_pool WebSocket 入口未改写上游容量降载错误码,避免客户端错误终止会话。 - 修复 OpenAI delegation bootstrap 缺少 call id 时无法正常处理的问题。 --- ## 📥 Installation **Docker:** ```bash # Docker Hub docker pull weishaw/sub2api:0.1.185 # GitHub Container Registry docker pull ghcr.io/wei-shaw/sub2api:0.1.185 ``` **One-line install (Linux):** ```bash curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash ``` **Manual download:** Download the appropriate archive for your platform from the assets below. ## 📚 Documentation - [GitHub Repository](https://github.com/Wei-Shaw/sub2api) - [Installation Guide](https://github.com/Wei-Shaw/sub2api/blob/main/deploy/README.md)

  3. Sub2API 0.1.184v0.1.184Aug 31, 202610.6K downloads

    > AI API Gateway Platform - 将 AI 订阅配额分发和管理 完善 Codex 路由模型目录与能力同步,新增多项账号、用量统计及网关稳定性改进。 ## 新增功能 - Codex 路由模型目录:支持按实际路由展示模型及能力,并支持精确账号模型别名。 - 用量记录:新增原生 compaction 请求统计,并展示映射前的推理强度。 - 公共分组访问控制:管理员可限制用户可访问的公共分组。 - 新增智谱团队 GLM Coding Plan 用量查询。 - Ollama Cloud 用量窗口支持挂载到国产三家平台账号。 - OpenAI 图像工具冷却策略支持后台配置。 - TTFT 指标模式调整为管理员可配置。 ## 优化改进 - 优化 Codex 模型目录缓存、能力同步及模型发现策略。 - 优化 OpenAI 多渠道 service tier 传递、计费和配额重置处理。 - 优化账号过期时间的本地时区解析与展示。 - 优化上游倍率探测,避免触发账号列表整页刷新。 - 优化 DeepSeek 高峰/非高峰计费价格。 - 优化 WebSocket、消息粘性会话及大请求转发处理。 - 优化图像能力异常账号的调度冷却,减少重复选中不可用账号。 ## Bug 修复 - 修复 Anthropic 转 Responses 流式输出时 thinking 内容块顺序及索引问题。 - 修复 Anthropic/Bedrock 传输层错误未正确触发故障转移的问题。 - 修复 Grok Responses 工具输出、无效工具联合类型及图像工具结果处理问题。 - 修复 OpenAI 流式失败、配额重置和客户端正常断开时的错误判定。 - 修复 OAuth 重新授权及 OAuth 注册优惠码保留问题。 - 修复 SMTP TLS 测试接口覆盖已保存配置的问题。 - 修复支付回调相对地址及充值汇率币种展示问题。 - 修复渠道定价对带后缀模型名的计费覆盖问题。 - 修复 Claude 归因请求头及 Anthropic 工具参数透传问题。 --- ## 📥 Installation **Docker:** ```bash # Docker Hub docker pull weishaw/sub2api:0.1.184 # GitHub Container Registry docker pull ghcr.io/wei-shaw/sub2api:0.1.184 ``` **One-line install (Linux):** ```bash curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash ``` **

  4. Sub2API 0.1.183v0.1.183Aug 25, 202633K downloads

    > AI API Gateway Platform - 将 AI 订阅配额分发和管理 本版本集中修复 OpenAI、Kimi、Antigravity、邮箱绑定及频道监控等场景的调度、会话与兼容性问题,提升请求成功率和账号状态判断准确性。 ## Bug 修复 - OpenAI OAuth:识别 5 小时/7 天配额耗尽的 429,并按重置时间暂停账号;普通瞬时 429 继续重试。 - Kimi:并发限制 403 改为临时冷却并保留故障转移,避免误将账号永久禁用。 - OpenAI:支持 Codex `session-id` 请求头,保持重连请求的粘性会话;容量溢出时不迁移持久绑定。 - OpenAI Responses:修正 custom tool/tool search 调用恢复后的项目 ID 前缀,避免后续请求因 ID 校验失败。 - 邮箱换绑:支持别名占用检测并增加事务级并发保护,避免并发换绑导致重复绑定。 - Antigravity:将兼容模式最大 token 限制为 64000,避免超出上游限制。 - 频道监控 v2:修复 composite 平台错误聚合的 SQL 条件,确保监控统计归属正确。 --- ## 📥 Installation **Docker:** ```bash # Docker Hub docker pull weishaw/sub2api:0.1.183 # GitHub Container Registry docker pull ghcr.io/wei-shaw/sub2api:0.1.183 ``` **One-line install (Linux):** ```bash curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash ``` **Manual download:** Download the appropriate archive for your platform from the assets below. ## 📚 Documentation - [GitHub Repository](https://github.com/Wei-Shaw/sub2api) - [Installation Guide](https://github.com/Wei-Shaw/sub2api/blob/main/deploy/README.md)

  5. Sub2API 0.1.182v0.1.182Aug 25, 202610.1K downloads

    > AI API Gateway Platform - 将 AI 订阅配额分发和管理 提升 OpenAI Responses Lite 在不同账号类型及传输方式下的兼容性,并修复计费、渠道监控和支付结果同步问题。 ## Bug 修复 - OpenAI Responses Lite:统一 OAuth、API Key、HTTP 和 WebSocket 请求处理,固定并行工具调用模式并保留数值精度 - OpenAI 图片生成:确保 OAuth 图片生成请求原样保留用户提示词 - OpenCode Go:正确解析用量限制的重置时长,避免账号过早恢复调度 - Anthropic 缓存计费:修复缓存创建明细重复累计导致的重复计费 - Antigravity:修正 Sonnet 4.5 兼容模型路由,同时保留显式 Sonnet 4.5 请求 - Composite 分组:支持 Kimi Code K3 模型标识的正确路由 - 渠道监控 V2:修复 Composite 分组错误未归属到真实账号平台的问题 - 支付结果:余额充值完成后及时刷新用户余额 --- ## 📥 Installation **Docker:** ```bash # Docker Hub docker pull weishaw/sub2api:0.1.182 # GitHub Container Registry docker pull ghcr.io/wei-shaw/sub2api:0.1.182 ``` **One-line install (Linux):** ```bash curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/install.sh | sudo bash ``` **Manual download:** Download the appropriate archive for your platform from the assets below. ## 📚 Documentation - [GitHub Repository](https://github.com/Wei-Shaw/sub2api) - [Installation Guide](https://github.com/Wei-Shaw/sub2api/blob/main/deploy/README.md)

Code frequency

additions and deletions
+166.1K-166.1KWeek of 2025-12-14: +95,915 linesWeek of 2025-12-14: -4,067 linesWeek of 2025-12-21: +52,057 linesWeek of 2025-12-21: -17,025 linesWeek of 2025-12-28: +160,678 linesWeek of 2025-12-28: -38,390 linesWeek of 2026-01-04: +90,067 linesWeek of 2026-01-04: -32,555 linesWeek of 2026-01-11: +51,431 linesWeek of 2026-01-11: -9,576 linesWeek of 2026-01-18: +29,557 linesWeek of 2026-01-18: -3,601 linesWeek of 2026-01-25: +55,194 linesWeek of 2026-01-25: -2,047 linesWeek of 2026-02-01: +89,535 linesWeek of 2026-02-01: -28,733 linesWeek of 2026-02-08: +45,921 linesWeek of 2026-02-08: -7,213 linesWeek of 2026-02-15: +10,578 linesWeek of 2026-02-15: -797 linesWeek of 2026-02-22: +78,686 linesWeek of 2026-02-22: -42,092 linesWeek of 2026-03-01: +33,326 linesWeek of 2026-03-01: -10,248 linesWeek of 2026-03-08: +37,426 linesWeek of 2026-03-08: -5,203 linesWeek of 2026-03-15: +17,565 linesWeek of 2026-03-15: -3,923 linesWeek of 2026-03-22: +17,434 linesWeek of 2026-03-22: -1,935 linesWeek of 2026-03-29: +19,445 linesWeek of 2026-03-29: -4,801 linesWeek of 2026-04-05: +61,550 linesWeek of 2026-04-05: -38,003 linesWeek of 2026-04-12: +18,717 linesWeek of 2026-04-12: -5,483 linesWeek of 2026-04-19: +166,075 linesWeek of 2026-04-19: -33,568 linesWeek of 2026-04-26: +12,702 linesWeek of 2026-04-26: -3,074 linesWeek of 2026-05-03: +30,528 linesWeek of 2026-05-03: -3,291 linesWeek of 2026-05-10: +17,027 linesWeek of 2026-05-10: -1,495 linesWeek of 2026-05-17: +21,018 linesWeek of 2026-05-17: -3,736 linesWeek of 2026-05-24: +35,687 linesWeek of 2026-05-24: -5,671 linesWeek of 2026-05-31: +18,164 linesWeek of 2026-05-31: -1,630 linesWeek of 2026-06-07: +12,138 linesWeek of 2026-06-07: -1,619 linesWeek of 2026-06-14: +10,267 linesWeek of 2026-06-14: -898 linesWeek of 2026-06-21: +10,198 linesWeek of 2026-06-21: -1,089 linesWeek of 2026-06-28: +74,030 linesWeek of 2026-06-28: -6,500 linesWeek of 2026-07-05: +104,920 linesWeek of 2026-07-05: -64,504 linesWeek of 2026-07-12: +118,535 linesWeek of 2026-07-12: -9,702 linesWeek of 2026-07-19: +34,522 linesWeek of 2026-07-19: -2,945 linesWeek of 2026-07-26: +32,134 linesWeek of 2026-07-26: -2,630 linesWeek of 2026-08-02: +55,493 linesWeek of 2026-08-02: -7,881 linesWeek of 2026-08-09: +22,950 linesWeek of 2026-08-09: -2,015 linesWeek of 2026-08-16: +56,353 linesWeek of 2026-08-16: -7,961 linesWeek of 2026-08-23: +30,735 linesWeek of 2026-08-23: -3,302 linesWeek of 2026-08-30: +21,326 linesWeek of 2026-08-30: -13,490 linesDec 14, 2025Aug 30, 2026
+1.8M lines added, -432.7K removed over the last year.

Commits per week

last 52 weeks
2840Week of 2025-09-06: 0 commitsWeek of 2025-09-13: 0 commitsWeek of 2025-09-20: 0 commitsWeek of 2025-09-27: 0 commitsWeek of 2025-10-04: 0 commitsWeek of 2025-10-11: 0 commitsWeek of 2025-10-18: 0 commitsWeek of 2025-10-25: 0 commitsWeek of 2025-11-01: 0 commitsWeek of 2025-11-09: 0 commitsWeek of 2025-11-16: 0 commitsWeek of 2025-11-23: 0 commitsWeek of 2025-11-30: 0 commitsWeek of 2025-12-07: 0 commitsWeek of 2025-12-14: 63 commitsWeek of 2025-12-21: 132 commitsWeek of 2025-12-28: 216 commitsWeek of 2026-01-04: 200 commitsWeek of 2026-01-11: 241 commitsWeek of 2026-01-18: 94 commitsWeek of 2026-01-25: 52 commitsWeek of 2026-02-01: 149 commitsWeek of 2026-02-08: 134 commitsWeek of 2026-02-15: 22 commitsWeek of 2026-02-22: 122 commitsWeek of 2026-03-01: 154 commitsWeek of 2026-03-08: 122 commitsWeek of 2026-03-15: 134 commitsWeek of 2026-03-22: 54 commitsWeek of 2026-03-29: 113 commitsWeek of 2026-04-05: 99 commitsWeek of 2026-04-12: 127 commitsWeek of 2026-04-19: 277 commitsWeek of 2026-04-26: 59 commitsWeek of 2026-05-03: 54 commitsWeek of 2026-05-10: 51 commitsWeek of 2026-05-17: 120 commitsWeek of 2026-05-24: 74 commitsWeek of 2026-05-31: 66 commitsWeek of 2026-06-07: 61 commitsWeek of 2026-06-14: 51 commitsWeek of 2026-06-21: 53 commitsWeek of 2026-06-28: 107 commitsWeek of 2026-07-05: 194 commitsWeek of 2026-07-12: 284 commitsWeek of 2026-07-19: 177 commitsWeek of 2026-07-26: 121 commitsWeek of 2026-08-02: 180 commitsWeek of 2026-08-09: 83 commitsWeek of 2026-08-16: 181 commitsWeek of 2026-08-23: 136 commitsWeek of 2026-08-30: 72 commitsSep 6, 2025Aug 30, 2026
4.6K commits in the last 52 weeks.

When work happens

weekday and hour
SunMonTueWedThuFriSat036912151821Sun 0:00 — 13 commitsSun 1:00 — 19 commitsSun 2:00 — 16 commitsSun 3:00 — 6 commitsSun 4:00 — 6 commitsSun 5:00 — 3 commitsSun 6:00 — 4 commitsSun 7:00 — 4 commitsSun 8:00 — 16 commitsSun 9:00 — 9 commitsSun 10:00 — 21 commitsSun 11:00 — 23 commitsSun 12:00 — 19 commitsSun 13:00 — 33 commitsSun 14:00 — 30 commitsSun 15:00 — 28 commitsSun 16:00 — 37 commitsSun 17:00 — 29 commitsSun 18:00 — 48 commitsSun 19:00 — 21 commitsSun 20:00 — 39 commitsSun 21:00 — 47 commitsSun 22:00 — 46 commitsSun 23:00 — 31 commitsMon 0:00 — 30 commitsMon 1:00 — 12 commitsMon 2:00 — 8 commitsMon 3:00 — 12 commitsMon 4:00 — 5 commitsMon 5:00 — 2 commitsMon 6:00 — 11 commitsMon 7:00 — 8 commitsMon 8:00 — 20 commitsMon 9:00 — 30 commitsMon 10:00 — 42 commitsMon 11:00 — 47 commitsMon 12:00 — 24 commitsMon 13:00 — 26 commitsMon 14:00 — 44 commitsMon 15:00 — 45 commitsMon 16:00 — 66 commitsMon 17:00 — 59 commitsMon 18:00 — 41 commitsMon 19:00 — 51 commitsMon 20:00 — 47 commitsMon 21:00 — 45 commitsMon 22:00 — 43 commitsMon 23:00 — 12 commitsTue 0:00 — 47 commitsTue 1:00 — 29 commitsTue 2:00 — 11 commitsTue 3:00 — 6 commitsTue 4:00 — 22 commitsTue 5:00 — 5 commitsTue 6:00 — 10 commitsTue 7:00 — 13 commitsTue 8:00 — 14 commitsTue 9:00 — 40 commitsTue 10:00 — 52 commitsTue 11:00 — 51 commitsTue 12:00 — 33 commitsTue 13:00 — 47 commitsTue 14:00 — 44 commitsTue 15:00 — 58 commitsTue 16:00 — 47 commitsTue 17:00 — 44 commitsTue 18:00 — 28 commitsTue 19:00 — 51 commitsTue 20:00 — 51 commitsTue 21:00 — 34 commitsTue 22:00 — 44 commitsTue 23:00 — 31 commitsWed 0:00 — 31 commitsWed 1:00 — 15 commitsWed 2:00 — 11 commitsWed 3:00 — 13 commitsWed 4:00 — 4 commitsWed 5:00 — 6 commitsWed 6:00 — 5 commitsWed 7:00 — 6 commitsWed 8:00 — 15 commitsWed 9:00 — 35 commitsWed 10:00 — 42 commitsWed 11:00 — 47 commitsWed 12:00 — 21 commitsWed 13:00 — 27 commitsWed 14:00 — 49 commitsWed 15:00 — 40 commitsWed 16:00 — 55 commitsWed 17:00 — 42 commitsWed 18:00 — 32 commitsWed 19:00 — 26 commitsWed 20:00 — 23 commitsWed 21:00 — 29 commitsWed 22:00 — 37 commitsWed 23:00 — 30 commitsThu 0:00 — 30 commitsThu 1:00 — 20 commitsThu 2:00 — 26 commitsThu 3:00 — 8 commitsThu 4:00 — 16 commitsThu 5:00 — 4 commitsThu 6:00 — 16 commitsThu 7:00 — 9 commitsThu 8:00 — 27 commitsThu 9:00 — 25 commitsThu 10:00 — 26 commitsThu 11:00 — 33 commitsThu 12:00 — 23 commitsThu 13:00 — 20 commitsThu 14:00 — 33 commitsThu 15:00 — 52 commitsThu 16:00 — 50 commitsThu 17:00 — 40 commitsThu 18:00 — 42 commitsThu 19:00 — 42 commitsThu 20:00 — 38 commitsThu 21:00 — 54 commitsThu 22:00 — 21 commitsThu 23:00 — 26 commitsFri 0:00 — 19 commitsFri 1:00 — 12 commitsFri 2:00 — 11 commitsFri 3:00 — 6 commitsFri 4:00 — 6 commitsFri 5:00 — 4 commitsFri 6:00 — 4 commitsFri 7:00 — 10 commitsFri 8:00 — 22 commitsFri 9:00 — 37 commitsFri 10:00 — 45 commitsFri 11:00 — 39 commitsFri 12:00 — 23 commitsFri 13:00 — 39 commitsFri 14:00 — 42 commitsFri 15:00 — 36 commitsFri 16:00 — 46 commitsFri 17:00 — 44 commitsFri 18:00 — 32 commitsFri 19:00 — 25 commitsFri 20:00 — 47 commitsFri 21:00 — 34 commitsFri 22:00 — 24 commitsFri 23:00 — 28 commitsSat 0:00 — 30 commitsSat 1:00 — 44 commitsSat 2:00 — 9 commitsSat 3:00 — 4 commitsSat 4:00 — 5 commitsSat 5:00 — 5 commitsSat 6:00 — 12 commitsSat 7:00 — 4 commitsSat 8:00 — 19 commitsSat 9:00 — 22 commitsSat 10:00 — 41 commitsSat 11:00 — 37 commitsSat 12:00 — 23 commitsSat 13:00 — 23 commitsSat 14:00 — 45 commitsSat 15:00 — 33 commitsSat 16:00 — 37 commitsSat 17:00 — 43 commitsSat 18:00 — 19 commitsSat 19:00 — 25 commitsSat 20:00 — 35 commitsSat 21:00 — 35 commitsSat 22:00 — 28 commitsSat 23:00 — 21 commits
Commit volume by weekday and hour (UTC). Larger dots mean more commits.

Who is committing

last 52 weeks
Maintainer commits2,310 (36%)
Community commits4,174 (64%)

6,484 commits in total over the last year.

DateListRankStars gained
Aug 24, 2026daily#2+278
Aug 23, 2026daily#2+278
  • affaan-m/ECC

    The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

    255.9K stars · JavaScript

  • NousResearch/hermes-agent

    The agent that grows with you

    244.2K stars · Python

  • affaan-m/ECC

    The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

    234.7K stars · JavaScript

  • Significant-Gravitas/AutoGPT

    AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

    187.2K stars · Python

  • avelino/awesome-go

    A curated list of awesome Go frameworks, libraries and software

    183.7K stars · Go

  • f/prompts.chat

    f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.

    169.9K stars · HTML