commons-proxy 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +757 -0
- package/bin/cli.js +146 -0
- package/package.json +97 -0
- package/public/Complaint Details.pdf +0 -0
- package/public/Cyber Crime Portal.pdf +0 -0
- package/public/app.js +229 -0
- package/public/css/src/input.css +523 -0
- package/public/css/style.css +1 -0
- package/public/favicon.png +0 -0
- package/public/index.html +549 -0
- package/public/js/components/account-manager.js +356 -0
- package/public/js/components/add-account-modal.js +414 -0
- package/public/js/components/claude-config.js +420 -0
- package/public/js/components/dashboard/charts.js +605 -0
- package/public/js/components/dashboard/filters.js +362 -0
- package/public/js/components/dashboard/stats.js +110 -0
- package/public/js/components/dashboard.js +236 -0
- package/public/js/components/logs-viewer.js +100 -0
- package/public/js/components/models.js +36 -0
- package/public/js/components/server-config.js +349 -0
- package/public/js/config/constants.js +102 -0
- package/public/js/data-store.js +375 -0
- package/public/js/settings-store.js +58 -0
- package/public/js/store.js +99 -0
- package/public/js/translations/en.js +367 -0
- package/public/js/translations/id.js +412 -0
- package/public/js/translations/pt.js +308 -0
- package/public/js/translations/tr.js +358 -0
- package/public/js/translations/zh.js +373 -0
- package/public/js/utils/account-actions.js +189 -0
- package/public/js/utils/error-handler.js +96 -0
- package/public/js/utils/model-config.js +42 -0
- package/public/js/utils/ui-logger.js +143 -0
- package/public/js/utils/validators.js +77 -0
- package/public/js/utils.js +69 -0
- package/public/proxy-server-64.png +0 -0
- package/public/views/accounts.html +361 -0
- package/public/views/dashboard.html +484 -0
- package/public/views/logs.html +97 -0
- package/public/views/models.html +331 -0
- package/public/views/settings.html +1327 -0
- package/src/account-manager/credentials.js +378 -0
- package/src/account-manager/index.js +462 -0
- package/src/account-manager/onboarding.js +112 -0
- package/src/account-manager/rate-limits.js +369 -0
- package/src/account-manager/storage.js +160 -0
- package/src/account-manager/strategies/base-strategy.js +109 -0
- package/src/account-manager/strategies/hybrid-strategy.js +339 -0
- package/src/account-manager/strategies/index.js +79 -0
- package/src/account-manager/strategies/round-robin-strategy.js +76 -0
- package/src/account-manager/strategies/sticky-strategy.js +138 -0
- package/src/account-manager/strategies/trackers/health-tracker.js +162 -0
- package/src/account-manager/strategies/trackers/index.js +9 -0
- package/src/account-manager/strategies/trackers/quota-tracker.js +120 -0
- package/src/account-manager/strategies/trackers/token-bucket-tracker.js +155 -0
- package/src/auth/database.js +169 -0
- package/src/auth/oauth.js +548 -0
- package/src/auth/token-extractor.js +117 -0
- package/src/cli/accounts.js +648 -0
- package/src/cloudcode/index.js +29 -0
- package/src/cloudcode/message-handler.js +510 -0
- package/src/cloudcode/model-api.js +248 -0
- package/src/cloudcode/rate-limit-parser.js +235 -0
- package/src/cloudcode/request-builder.js +93 -0
- package/src/cloudcode/session-manager.js +47 -0
- package/src/cloudcode/sse-parser.js +121 -0
- package/src/cloudcode/sse-streamer.js +293 -0
- package/src/cloudcode/streaming-handler.js +615 -0
- package/src/config.js +125 -0
- package/src/constants.js +407 -0
- package/src/errors.js +242 -0
- package/src/fallback-config.js +29 -0
- package/src/format/content-converter.js +193 -0
- package/src/format/index.js +20 -0
- package/src/format/request-converter.js +255 -0
- package/src/format/response-converter.js +120 -0
- package/src/format/schema-sanitizer.js +673 -0
- package/src/format/signature-cache.js +88 -0
- package/src/format/thinking-utils.js +648 -0
- package/src/index.js +148 -0
- package/src/modules/usage-stats.js +205 -0
- package/src/providers/anthropic-provider.js +258 -0
- package/src/providers/base-provider.js +157 -0
- package/src/providers/cloudcode.js +94 -0
- package/src/providers/copilot.js +399 -0
- package/src/providers/github-provider.js +287 -0
- package/src/providers/google-provider.js +192 -0
- package/src/providers/index.js +211 -0
- package/src/providers/openai-compatible.js +265 -0
- package/src/providers/openai-provider.js +271 -0
- package/src/providers/openrouter-provider.js +325 -0
- package/src/providers/setup.js +83 -0
- package/src/server.js +870 -0
- package/src/utils/claude-config.js +245 -0
- package/src/utils/helpers.js +51 -0
- package/src/utils/logger.js +142 -0
- package/src/utils/native-module-helper.js +162 -0
- package/src/webui/index.js +1134 -0
package/README.md
ADDED
|
@@ -0,0 +1,757 @@
|
|
|
1
|
+
# CommonsProxy
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/commons-proxy)
|
|
4
|
+
[](https://www.npmjs.com/package/commons-proxy)
|
|
5
|
+
[](https://ghcr.io/aryanvbw/commonsproxy)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
<a href="https://buymeacoffee.com/badrinarayanans" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="50"></a>
|
|
9
|
+
|
|
10
|
+
A **universal AI proxy server** exposing an **Anthropic-compatible API** backed by **multiple providers** (Google Cloud Code, Anthropic, OpenAI, GitHub Models, GitHub Copilot, OpenRouter), enabling you to use Claude, Gemini, GPT, and more with **Claude Code CLI**.
|
|
11
|
+
|
|
12
|
+
> 🎉 **v2.0.0 Released**: Now supporting Anthropic, OpenAI, GitHub Models, GitHub Copilot, and OpenRouter in addition to Google Cloud Code!
|
|
13
|
+
|
|
14
|
+
📚 **Quick Links**: [Installation](#installation) | [Provider Setup](docs/PROVIDERS.md) | [Docker](#option-3-docker-recommended-for-production) | [Contributing](CONTRIBUTING.md)
|
|
15
|
+
|
|
16
|
+
## How It Works
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
┌──────────────────┐ ┌─────────────────────┐ ┌─────────────────────────┐
|
|
20
|
+
│ Claude Code │────▶│ CommonsProxy │────▶│ Multiple Providers: │
|
|
21
|
+
│ (Anthropic │ │ (Universal Router)│ │ • Google Cloud Code │
|
|
22
|
+
│ API format) │ │ │ │ • Anthropic API │
|
|
23
|
+
└──────────────────┘ └─────────────────────┘ │ • OpenAI API │
|
|
24
|
+
│ • GitHub Models │
|
|
25
|
+
│ • GitHub Copilot │
|
|
26
|
+
│ • OpenRouter │
|
|
27
|
+
└─────────────────────────┘
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Request Flow**:
|
|
31
|
+
1. Claude Code CLI sends request in **Anthropic Messages API format**
|
|
32
|
+
2. CommonsProxy routes to appropriate provider based on account configuration
|
|
33
|
+
3. Transforms request to **provider-specific format** (Google Generative AI, Anthropic, OpenAI, GitHub)
|
|
34
|
+
4. Sends to provider's API using OAuth or API Key authentication
|
|
35
|
+
5. Converts response back to **Anthropic format** with full streaming and thinking support
|
|
36
|
+
|
|
37
|
+
**Key Features**:
|
|
38
|
+
- 🔄 **Multi-Provider Support**: Use Google, Anthropic, OpenAI, GitHub Models, GitHub Copilot, and OpenRouter accounts
|
|
39
|
+
- 🔐 **Flexible Authentication**: OAuth 2.0 (Google), Device Auth (Copilot), or API Keys (others)
|
|
40
|
+
- ⚖️ **Intelligent Load Balancing**: Hybrid/Sticky/Round-Robin strategies
|
|
41
|
+
- 📊 **Real-time Quota Tracking**: Dashboard shows usage across all providers
|
|
42
|
+
- 💾 **Prompt Caching**: Maintains cache continuity with sticky account selection
|
|
43
|
+
- 🎨 **Web Management UI**: Easy account management and monitoring
|
|
44
|
+
|
|
45
|
+
## 🎯 Supported Providers
|
|
46
|
+
|
|
47
|
+
| Provider | Auth Method | Available Models | Quota Tracking | Status |
|
|
48
|
+
|----------|-------------|------------------|----------------|--------|
|
|
49
|
+
| **Google Cloud Code** | OAuth 2.0 with PKCE | Claude 3.5 Sonnet/Opus, Gemini 2.0 Flash/Pro | ✅ Real-time via API | ✅ Primary |
|
|
50
|
+
| **Anthropic** | API Key | Claude 3.5 Sonnet/Opus/Haiku | ⚠️ Manual (console) | ✅ Supported |
|
|
51
|
+
| **OpenAI** | API Key | GPT-4 Turbo, GPT-4, GPT-3.5 Turbo | ⚠️ Manual (console) | ✅ Supported |
|
|
52
|
+
| **GitHub Models** | Personal Access Token | GitHub Marketplace models | ⚠️ GitHub API limits | ✅ Supported |
|
|
53
|
+
| **GitHub Copilot** | Device Authorization | GPT-4o, GPT-4, Claude 3.5 Sonnet, o1 | ⚠️ Copilot limits | ✅ Supported |
|
|
54
|
+
| **OpenRouter** | API Key | 100+ models (Claude, GPT, Gemini, Llama, etc.) | ✅ Credit-based | ✅ Supported |
|
|
55
|
+
|
|
56
|
+
**Quota Tracking Legend**:
|
|
57
|
+
- ✅ **Real-time via API**: CommonsProxy automatically fetches and displays quota in WebUI
|
|
58
|
+
- ⚠️ **Manual**: Check quota limits in the provider's web console
|
|
59
|
+
|
|
60
|
+
**Custom Endpoints**: OpenAI provider supports custom API endpoints (Azure OpenAI, self-hosted APIs)
|
|
61
|
+
|
|
62
|
+
📖 **Setup Guides**: See [`docs/PROVIDERS.md`](docs/PROVIDERS.md) for detailed setup instructions for each provider.
|
|
63
|
+
|
|
64
|
+
## Prerequisites
|
|
65
|
+
|
|
66
|
+
- **Node.js** 18 or later
|
|
67
|
+
- **Windsurf/Cursor IDE** installed (for single-account mode) OR Google account(s) for multi-account mode
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
### Option 1: npm (Recommended)
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Run directly with npx (no install needed)
|
|
77
|
+
npx commons-proxy@latest start
|
|
78
|
+
|
|
79
|
+
# Or install globally
|
|
80
|
+
npm install -g commons-proxy@latest
|
|
81
|
+
commons-proxy start
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Option 2: Clone Repository
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
git clone https://github.com/AryanVBW/CommonsProxy.git
|
|
88
|
+
cd CommonsProxy
|
|
89
|
+
npm install
|
|
90
|
+
npm start
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Option 3: Docker 🐳 (Recommended for Production)
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Pull and run from GitHub Container Registry
|
|
97
|
+
docker run -d \
|
|
98
|
+
--name commons-proxy \
|
|
99
|
+
-p 8080:8080 \
|
|
100
|
+
-v ~/.config/commons-proxy:/app/data/.config/commons-proxy \
|
|
101
|
+
ghcr.io/aryanvbw/commonsproxy:latest
|
|
102
|
+
|
|
103
|
+
# Or use docker-compose
|
|
104
|
+
curl -O https://raw.githubusercontent.com/AryanVBW/CommonsProxy/main/docker-compose.yml
|
|
105
|
+
docker-compose up -d
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Access WebUI**: Open `http://localhost:8080` to configure accounts
|
|
109
|
+
|
|
110
|
+
**Environment Variables**:
|
|
111
|
+
```bash
|
|
112
|
+
docker run -d \
|
|
113
|
+
-p 8080:8080 \
|
|
114
|
+
-e PORT=8080 \
|
|
115
|
+
-e DEBUG=true \
|
|
116
|
+
-e WEBUI_PASSWORD=your-password \
|
|
117
|
+
-v ~/.config/commons-proxy:/app/data/.config/commons-proxy \
|
|
118
|
+
ghcr.io/aryanvbw/commonsproxy:latest
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Quick Start
|
|
124
|
+
|
|
125
|
+
### 1. Start the Proxy Server
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# If installed via npm
|
|
129
|
+
commons-proxy start
|
|
130
|
+
|
|
131
|
+
# If using npx
|
|
132
|
+
npx commons-proxy@latest start
|
|
133
|
+
|
|
134
|
+
# If cloned locally
|
|
135
|
+
npm start
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The server runs on `http://localhost:8080` by default.
|
|
139
|
+
|
|
140
|
+
### 2. Link Account(s)
|
|
141
|
+
|
|
142
|
+
CommonsProxy supports multiple AI providers. Add one or more accounts to get started.
|
|
143
|
+
|
|
144
|
+
> 💡 **Tip**: You can mix and match providers! Add multiple Google accounts for load balancing, plus Anthropic/OpenAI as fallbacks.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
#### 🔵 Google Cloud Code (OAuth 2.0)
|
|
149
|
+
|
|
150
|
+
**Best for**: Claude and Gemini models with real-time quota tracking
|
|
151
|
+
|
|
152
|
+
**WebUI Setup** (Recommended):
|
|
153
|
+
1. Navigate to `http://localhost:8080` → **Accounts** tab → **Add Account**
|
|
154
|
+
2. Select **Google Cloud Code** from provider dropdown
|
|
155
|
+
3. Complete OAuth authorization in popup window
|
|
156
|
+
|
|
157
|
+
**CLI Setup**:
|
|
158
|
+
```bash
|
|
159
|
+
# Desktop (opens browser)
|
|
160
|
+
commons-proxy accounts add --provider=google
|
|
161
|
+
|
|
162
|
+
# Headless server (manual code input)
|
|
163
|
+
commons-proxy accounts add --provider=google --no-browser
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**Available Models**: `claude-sonnet-4-5`, `claude-opus-4-5`, `gemini-3-flash`, `gemini-3-pro-low`, `gemini-3-pro-high`
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
#### 🟠 Anthropic (API Key)
|
|
171
|
+
|
|
172
|
+
**Best for**: Direct Claude API access with official rate limits
|
|
173
|
+
|
|
174
|
+
**Prerequisites**: Anthropic account at [console.anthropic.com](https://console.anthropic.com), API key with billing enabled
|
|
175
|
+
|
|
176
|
+
**Setup**:
|
|
177
|
+
1. Get API key: https://console.anthropic.com/settings/keys
|
|
178
|
+
2. In WebUI: **Accounts** → **Add Account** → **Anthropic** → Paste key
|
|
179
|
+
3. Or CLI: `commons-proxy accounts add --provider=anthropic`
|
|
180
|
+
|
|
181
|
+
**Available Models**: `claude-3-5-sonnet-20241022`, `claude-3-5-haiku-20241022`, `claude-3-opus-20240229`
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
#### 🟢 OpenAI (API Key)
|
|
186
|
+
|
|
187
|
+
**Best for**: GPT models and Azure OpenAI integration
|
|
188
|
+
|
|
189
|
+
**Prerequisites**: OpenAI account at [platform.openai.com](https://platform.openai.com), API key with credits
|
|
190
|
+
|
|
191
|
+
**Setup**:
|
|
192
|
+
1. Get API key: https://platform.openai.com/api-keys
|
|
193
|
+
2. In WebUI: **Accounts** → **Add Account** → **OpenAI** → Paste key
|
|
194
|
+
3. Optional: Enable "Custom Endpoint" for Azure OpenAI
|
|
195
|
+
4. Or CLI: `commons-proxy accounts add --provider=openai`
|
|
196
|
+
|
|
197
|
+
**Available Models**: `gpt-4-turbo-preview`, `gpt-4`, `gpt-3.5-turbo`
|
|
198
|
+
|
|
199
|
+
**Azure OpenAI**: Supports custom endpoints for Azure deployments
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
#### 🟣 GitHub Models (Personal Access Token)
|
|
204
|
+
|
|
205
|
+
**Best for**: Access to GitHub Marketplace models (beta)
|
|
206
|
+
|
|
207
|
+
**Prerequisites**: GitHub account, Personal Access Token with `read:packages` scope
|
|
208
|
+
|
|
209
|
+
**Setup**:
|
|
210
|
+
1. Create PAT: https://github.com/settings/tokens
|
|
211
|
+
2. In WebUI: **Accounts** → **Add Account** → **GitHub Models** → Paste token
|
|
212
|
+
3. Or CLI: `commons-proxy accounts add --provider=github`
|
|
213
|
+
|
|
214
|
+
**Available Models**: GitHub Marketplace models (varies by account/region)
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
📚 **Detailed Guides**: For step-by-step instructions with screenshots and troubleshooting, see:
|
|
219
|
+
- [`docs/PROVIDERS.md`](docs/PROVIDERS.md) - Complete provider setup guides
|
|
220
|
+
- [CONTRIBUTING.md](CONTRIBUTING.md) - Adding new providers
|
|
221
|
+
|
|
222
|
+
### 3. Verify It's Working
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# Health check
|
|
226
|
+
curl http://localhost:8080/health
|
|
227
|
+
|
|
228
|
+
# Check account status and quota limits
|
|
229
|
+
curl "http://localhost:8080/account-limits?format=table"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Using with Claude Code CLI
|
|
235
|
+
|
|
236
|
+
### Configure Claude Code
|
|
237
|
+
|
|
238
|
+
You can configure these settings in two ways:
|
|
239
|
+
|
|
240
|
+
#### **Via Web Console (Recommended)**
|
|
241
|
+
|
|
242
|
+
1. Open the WebUI at `http://localhost:8080`.
|
|
243
|
+
2. Go to **Settings** → **Claude CLI**.
|
|
244
|
+
3. Select your preferred models and click **Apply to Claude CLI**.
|
|
245
|
+
|
|
246
|
+
> [!TIP] > **Configuration Precedence**: System environment variables (set in shell profile like `.zshrc`) take precedence over the `settings.json` file. If you use the Web Console to manage settings, ensure you haven't manually exported conflicting variables in your terminal.
|
|
247
|
+
|
|
248
|
+
#### **Manual Configuration**
|
|
249
|
+
|
|
250
|
+
Create or edit the Claude Code settings file:
|
|
251
|
+
|
|
252
|
+
**macOS:** `~/.claude/settings.json`
|
|
253
|
+
**Linux:** `~/.claude/settings.json`
|
|
254
|
+
**Windows:** `%USERPROFILE%\.claude\settings.json`
|
|
255
|
+
|
|
256
|
+
Add this configuration:
|
|
257
|
+
|
|
258
|
+
```json
|
|
259
|
+
{
|
|
260
|
+
"env": {
|
|
261
|
+
"ANTHROPIC_AUTH_TOKEN": "test",
|
|
262
|
+
"ANTHROPIC_BASE_URL": "http://localhost:8080",
|
|
263
|
+
"ANTHROPIC_MODEL": "claude-opus-4-5-thinking",
|
|
264
|
+
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-5-thinking",
|
|
265
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-5-thinking",
|
|
266
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-sonnet-4-5",
|
|
267
|
+
"CLAUDE_CODE_SUBAGENT_MODEL": "claude-sonnet-4-5-thinking",
|
|
268
|
+
"ENABLE_EXPERIMENTAL_MCP_CLI": "true"
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Or to use Gemini models:
|
|
274
|
+
|
|
275
|
+
```json
|
|
276
|
+
{
|
|
277
|
+
"env": {
|
|
278
|
+
"ANTHROPIC_AUTH_TOKEN": "test",
|
|
279
|
+
"ANTHROPIC_BASE_URL": "http://localhost:8080",
|
|
280
|
+
"ANTHROPIC_MODEL": "gemini-3-pro-high[1m]",
|
|
281
|
+
"ANTHROPIC_DEFAULT_OPUS_MODEL": "gemini-3-pro-high[1m]",
|
|
282
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gemini-3-flash[1m]",
|
|
283
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gemini-3-flash[1m]",
|
|
284
|
+
"CLAUDE_CODE_SUBAGENT_MODEL": "gemini-3-flash[1m]",
|
|
285
|
+
"ENABLE_EXPERIMENTAL_MCP_CLI": "true"
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Load Environment Variables
|
|
291
|
+
|
|
292
|
+
Add the proxy settings to your shell profile:
|
|
293
|
+
|
|
294
|
+
**macOS / Linux:**
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
echo 'export ANTHROPIC_BASE_URL="http://localhost:8080"' >> ~/.zshrc
|
|
298
|
+
echo 'export ANTHROPIC_AUTH_TOKEN="test"' >> ~/.zshrc
|
|
299
|
+
source ~/.zshrc
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
> For Bash users, replace `~/.zshrc` with `~/.bashrc`
|
|
303
|
+
|
|
304
|
+
**Windows (PowerShell):**
|
|
305
|
+
|
|
306
|
+
```powershell
|
|
307
|
+
Add-Content $PROFILE "`n`$env:ANTHROPIC_BASE_URL = 'http://localhost:8080'"
|
|
308
|
+
Add-Content $PROFILE "`$env:ANTHROPIC_AUTH_TOKEN = 'test'"
|
|
309
|
+
. $PROFILE
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
**Windows (Command Prompt):**
|
|
313
|
+
|
|
314
|
+
```cmd
|
|
315
|
+
setx ANTHROPIC_BASE_URL "http://localhost:8080"
|
|
316
|
+
setx ANTHROPIC_AUTH_TOKEN "test"
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Restart your terminal for changes to take effect.
|
|
320
|
+
|
|
321
|
+
### Run Claude Code
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
# Make sure the proxy is running first
|
|
325
|
+
commons-proxy start
|
|
326
|
+
|
|
327
|
+
# In another terminal, run Claude Code
|
|
328
|
+
claude
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
> **Note:** If Claude Code asks you to select a login method, add `"hasCompletedOnboarding": true` to `~/.claude.json` (macOS/Linux) or `%USERPROFILE%\.claude.json` (Windows), then restart your terminal and try again.
|
|
332
|
+
|
|
333
|
+
### Multiple Claude Code Instances (Optional)
|
|
334
|
+
|
|
335
|
+
To run both the official Claude Code and CommonsProxy version simultaneously, add this alias:
|
|
336
|
+
|
|
337
|
+
**macOS / Linux:**
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
# Add to ~/.zshrc or ~/.bashrc
|
|
341
|
+
alias claude-commons='CLAUDE_CONFIG_DIR=~/.claude-account-commons ANTHROPIC_BASE_URL="http://localhost:8080" ANTHROPIC_AUTH_TOKEN="test" command claude'
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**Windows (PowerShell):**
|
|
345
|
+
|
|
346
|
+
```powershell
|
|
347
|
+
# Add to $PROFILE
|
|
348
|
+
function claude-commons {
|
|
349
|
+
$env:CLAUDE_CONFIG_DIR = "$env:USERPROFILE\.claude-account-commons"
|
|
350
|
+
$env:ANTHROPIC_BASE_URL = "http://localhost:8080"
|
|
351
|
+
$env:ANTHROPIC_AUTH_TOKEN = "test"
|
|
352
|
+
claude
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Then run `claude` for official API or `claude-commons` for this proxy.
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
## Available Models
|
|
361
|
+
|
|
362
|
+
### Claude Models
|
|
363
|
+
|
|
364
|
+
| Model ID | Description |
|
|
365
|
+
| ---------------------------- | ---------------------------------------- |
|
|
366
|
+
| `claude-sonnet-4-5-thinking` | Claude Sonnet 4.5 with extended thinking |
|
|
367
|
+
| `claude-opus-4-5-thinking` | Claude Opus 4.5 with extended thinking |
|
|
368
|
+
| `claude-sonnet-4-5` | Claude Sonnet 4.5 without thinking |
|
|
369
|
+
|
|
370
|
+
### Gemini Models
|
|
371
|
+
|
|
372
|
+
| Model ID | Description |
|
|
373
|
+
| ------------------- | ------------------------------- |
|
|
374
|
+
| `gemini-3-flash` | Gemini 3 Flash with thinking |
|
|
375
|
+
| `gemini-3-pro-low` | Gemini 3 Pro Low with thinking |
|
|
376
|
+
| `gemini-3-pro-high` | Gemini 3 Pro High with thinking |
|
|
377
|
+
|
|
378
|
+
Gemini models include full thinking support with `thoughtSignature` handling for multi-turn conversations.
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
## Multi-Account Load Balancing
|
|
383
|
+
|
|
384
|
+
When you add multiple accounts, the proxy intelligently distributes requests across them using configurable selection strategies.
|
|
385
|
+
|
|
386
|
+
### Account Selection Strategies
|
|
387
|
+
|
|
388
|
+
Choose a strategy based on your needs:
|
|
389
|
+
|
|
390
|
+
| Strategy | Best For | Description |
|
|
391
|
+
| --- | --- | --- |
|
|
392
|
+
| **Hybrid** (Default) | Most users | Smart selection combining health score, token bucket rate limiting, quota awareness, and LRU freshness |
|
|
393
|
+
| **Sticky** | Prompt caching | Stays on the same account to maximize cache hits, switches only when rate-limited |
|
|
394
|
+
| **Round-Robin** | Even distribution | Cycles through accounts sequentially for balanced load |
|
|
395
|
+
|
|
396
|
+
**Configure via CLI:**
|
|
397
|
+
|
|
398
|
+
```bash
|
|
399
|
+
commons-proxy start --strategy=hybrid # Default: smart distribution
|
|
400
|
+
commons-proxy start --strategy=sticky # Cache-optimized
|
|
401
|
+
commons-proxy start --strategy=round-robin # Load-balanced
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
**Or via WebUI:** Settings → Server → Account Selection Strategy
|
|
405
|
+
|
|
406
|
+
### How It Works
|
|
407
|
+
|
|
408
|
+
- **Health Score Tracking**: Accounts earn points for successful requests and lose points for failures/rate-limits
|
|
409
|
+
- **Token Bucket Rate Limiting**: Client-side throttling with regenerating tokens (50 max, 6/minute)
|
|
410
|
+
- **Quota Awareness**: Accounts with critical quota (<5%) are deprioritized; exhausted accounts trigger emergency fallback
|
|
411
|
+
- **Emergency Fallback**: When all accounts appear exhausted, bypasses checks with throttle delays (250-500ms)
|
|
412
|
+
- **Automatic Cooldown**: Rate-limited accounts recover automatically after reset time expires
|
|
413
|
+
- **Invalid Account Detection**: Accounts needing re-authentication are marked and skipped
|
|
414
|
+
- **Prompt Caching Support**: Session IDs derived from conversation enable cache hits across turns
|
|
415
|
+
|
|
416
|
+
### Monitoring
|
|
417
|
+
|
|
418
|
+
Check account status, subscription tiers, and quota anytime:
|
|
419
|
+
|
|
420
|
+
```bash
|
|
421
|
+
# Web UI: http://localhost:8080/ (Accounts tab - shows tier badges and quota progress)
|
|
422
|
+
# CLI Table:
|
|
423
|
+
curl "http://localhost:8080/account-limits?format=table"
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
#### CLI Management Reference
|
|
427
|
+
|
|
428
|
+
If you prefer using the terminal for management:
|
|
429
|
+
|
|
430
|
+
```bash
|
|
431
|
+
# List all accounts
|
|
432
|
+
commons-proxy accounts list
|
|
433
|
+
|
|
434
|
+
# Verify account health
|
|
435
|
+
commons-proxy accounts verify
|
|
436
|
+
|
|
437
|
+
# Interactive CLI menu
|
|
438
|
+
commons-proxy accounts
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## Web Management Console
|
|
444
|
+
|
|
445
|
+
The proxy includes a built-in, modern web interface for real-time monitoring and configuration. Access the console at: `http://localhost:8080` (default port).
|
|
446
|
+
|
|
447
|
+

|
|
448
|
+
|
|
449
|
+
### Key Features
|
|
450
|
+
|
|
451
|
+
- **Real-time Dashboard**: Monitor request volume, active accounts, model health, and subscription tier distribution.
|
|
452
|
+
- **Visual Model Quota**: Track per-model usage and next reset times with color-coded progress indicators.
|
|
453
|
+
- **Account Management**: Add/remove Google accounts via OAuth, view subscription tiers (Free/Pro/Ultra) and quota status at a glance.
|
|
454
|
+
- **Manual OAuth Mode**: Add accounts on headless servers by copying the OAuth URL and pasting the authorization code.
|
|
455
|
+
- **Claude CLI Configuration**: Edit your `~/.claude/settings.json` directly from the browser.
|
|
456
|
+
- **Persistent History**: Tracks request volume by model family for 30 days, persisting across server restarts.
|
|
457
|
+
- **Time Range Filtering**: Analyze usage trends over 1H, 6H, 24H, 7D, or All Time periods.
|
|
458
|
+
- **Smart Analysis**: Auto-select top 5 most used models or toggle between Family/Model views.
|
|
459
|
+
- **Live Logs**: Stream server logs with level-based filtering and search.
|
|
460
|
+
- **Advanced Tuning**: Configure retries, timeouts, and debug mode on the fly.
|
|
461
|
+
- **Multi-language Interface**: Full support for English, Chinese (中文), Indonesian (Bahasa), and Portuguese (PT-BR).
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
## Advanced Configuration
|
|
466
|
+
|
|
467
|
+
While most users can use the default settings, you can tune the proxy behavior via the **Settings → Server** tab in the WebUI or by creating a `config.json` file.
|
|
468
|
+
|
|
469
|
+
### Configurable Options
|
|
470
|
+
|
|
471
|
+
- **API Key Authentication**: Protect `/v1/*` API endpoints with `API_KEY` env var or `apiKey` in config.
|
|
472
|
+
- **WebUI Password**: Secure your dashboard with `WEBUI_PASSWORD` env var or in config.
|
|
473
|
+
- **Custom Port**: Change the default `8080` port.
|
|
474
|
+
- **Retry Logic**: Configure `maxRetries`, `retryBaseMs`, and `retryMaxMs`.
|
|
475
|
+
- **Rate Limit Handling**: Comprehensive rate limit detection from headers and error messages with intelligent retry-after parsing.
|
|
476
|
+
- **Load Balancing**: Adjust `defaultCooldownMs` and `maxWaitBeforeErrorMs`.
|
|
477
|
+
- **Persistence**: Enable `persistTokenCache` to save OAuth sessions across restarts.
|
|
478
|
+
- **Max Accounts**: Set `maxAccounts` (1-100) to limit the number of Google accounts. Default: 10.
|
|
479
|
+
- **Endpoint Fallback**: Automatic 403/404 endpoint fallback for API compatibility.
|
|
480
|
+
|
|
481
|
+
Refer to `config.example.json` for a complete list of fields and documentation.
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## macOS Menu Bar App
|
|
486
|
+
|
|
487
|
+
For macOS users who prefer a native experience, there's a companion menu bar app that provides quick access to server controls without touching the terminal. Get it from: [commons-proxy-bar](https://github.com/IrvanFza/commons-proxy-bar)
|
|
488
|
+
|
|
489
|
+
> **Note:** This is a GUI wrapper only. You still need to install and setup the proxy server first using one of the [installation methods](#installation) above.
|
|
490
|
+
|
|
491
|
+

|
|
492
|
+
|
|
493
|
+
### Key Features
|
|
494
|
+
|
|
495
|
+
- **Server Control**: Start/stop the proxy server with a single click or ⌘S shortcut.
|
|
496
|
+
- **Status Indicator**: Menu bar icon shows server running state at a glance.
|
|
497
|
+
- **WebUI Access**: Open the web management console directly from the menu.
|
|
498
|
+
- **Port Configuration**: Customize the proxy server port (default: 8080).
|
|
499
|
+
- **Auto-Start Options**: Launch server on app start and launch app at login.
|
|
500
|
+
- **Native Experience**: Clean, native SwiftUI interface designed for macOS.
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
## API Endpoints
|
|
505
|
+
|
|
506
|
+
| Endpoint | Method | Description |
|
|
507
|
+
| ----------------- | ------ | --------------------------------------------------------------------- |
|
|
508
|
+
| `/health` | GET | Health check |
|
|
509
|
+
| `/account-limits` | GET | Account status and quota limits (add `?format=table` for ASCII table) |
|
|
510
|
+
| `/v1/messages` | POST | Anthropic Messages API |
|
|
511
|
+
| `/v1/models` | GET | List available models |
|
|
512
|
+
| `/refresh-token` | POST | Force token refresh |
|
|
513
|
+
|
|
514
|
+
---
|
|
515
|
+
|
|
516
|
+
## Testing
|
|
517
|
+
|
|
518
|
+
Run the test suite (requires server running):
|
|
519
|
+
|
|
520
|
+
```bash
|
|
521
|
+
# Start server in one terminal
|
|
522
|
+
npm start
|
|
523
|
+
|
|
524
|
+
# Run tests in another terminal
|
|
525
|
+
npm test
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
Individual tests:
|
|
529
|
+
|
|
530
|
+
```bash
|
|
531
|
+
npm run test:signatures # Thinking signatures
|
|
532
|
+
npm run test:multiturn # Multi-turn with tools
|
|
533
|
+
npm run test:streaming # Streaming SSE events
|
|
534
|
+
npm run test:interleaved # Interleaved thinking
|
|
535
|
+
npm run test:images # Image processing
|
|
536
|
+
npm run test:caching # Prompt caching
|
|
537
|
+
npm run test:strategies # Account selection strategies
|
|
538
|
+
npm run test:cache-control # Cache control field stripping
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
543
|
+
## Troubleshooting
|
|
544
|
+
|
|
545
|
+
### Windows: OAuth Port Error (EACCES)
|
|
546
|
+
|
|
547
|
+
On Windows, the default OAuth callback port (51121) may be reserved by Hyper-V, WSL2, or Docker. If you see:
|
|
548
|
+
|
|
549
|
+
```
|
|
550
|
+
Error: listen EACCES: permission denied 0.0.0.0:51121
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
The proxy will automatically try fallback ports (51122-51126). If all ports fail, try these solutions:
|
|
554
|
+
|
|
555
|
+
#### Option 1: Use a Custom Port (Recommended)
|
|
556
|
+
|
|
557
|
+
Set a custom port outside the reserved range:
|
|
558
|
+
|
|
559
|
+
```bash
|
|
560
|
+
# Windows PowerShell
|
|
561
|
+
$env:OAUTH_CALLBACK_PORT = "3456"
|
|
562
|
+
commons-proxy start
|
|
563
|
+
|
|
564
|
+
# Windows CMD
|
|
565
|
+
set OAUTH_CALLBACK_PORT=3456
|
|
566
|
+
commons-proxy start
|
|
567
|
+
|
|
568
|
+
# Or add to your .env file
|
|
569
|
+
OAUTH_CALLBACK_PORT=3456
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
#### Option 2: Reset Windows NAT
|
|
573
|
+
|
|
574
|
+
Run as Administrator:
|
|
575
|
+
|
|
576
|
+
```powershell
|
|
577
|
+
net stop winnat
|
|
578
|
+
net start winnat
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
#### Option 3: Check Reserved Ports
|
|
582
|
+
|
|
583
|
+
See which ports are reserved:
|
|
584
|
+
|
|
585
|
+
```powershell
|
|
586
|
+
netsh interface ipv4 show excludedportrange protocol=tcp
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
If 51121 is in a reserved range, use Option 1 with a port outside those ranges.
|
|
590
|
+
|
|
591
|
+
#### Option 4: Permanently Exclude Port (Admin)
|
|
592
|
+
|
|
593
|
+
Reserve the port before Hyper-V claims it (run as Administrator):
|
|
594
|
+
|
|
595
|
+
```powershell
|
|
596
|
+
netsh int ipv4 add excludedportrange protocol=tcp startport=51121 numberofports=1
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
> **Note:** The server automatically tries fallback ports (51122-51126) if the primary port fails.
|
|
600
|
+
|
|
601
|
+
---
|
|
602
|
+
|
|
603
|
+
### "Could not extract token from Cloud Code IDE"
|
|
604
|
+
|
|
605
|
+
If using single-account mode with Windsurf/Cursor:
|
|
606
|
+
|
|
607
|
+
1. Make sure the IDE is installed and running
|
|
608
|
+
2. Ensure you're logged in with your Google account
|
|
609
|
+
|
|
610
|
+
Or add accounts via OAuth instead: `commons-proxy accounts add`
|
|
611
|
+
|
|
612
|
+
### 401 Authentication Errors
|
|
613
|
+
|
|
614
|
+
The token might have expired. Try:
|
|
615
|
+
|
|
616
|
+
```bash
|
|
617
|
+
curl -X POST http://localhost:8080/refresh-token
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
Or re-authenticate the account:
|
|
621
|
+
|
|
622
|
+
```bash
|
|
623
|
+
commons-proxy accounts
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
### Rate Limiting (429)
|
|
627
|
+
|
|
628
|
+
With multiple accounts, the proxy automatically switches to the next available account. With a single account, you'll need to wait for the rate limit to reset.
|
|
629
|
+
|
|
630
|
+
### Account Shows as "Invalid"
|
|
631
|
+
|
|
632
|
+
Re-authenticate the account:
|
|
633
|
+
|
|
634
|
+
```bash
|
|
635
|
+
commons-proxy accounts
|
|
636
|
+
# Choose "Re-authenticate" for the invalid account
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
---
|
|
640
|
+
|
|
641
|
+
## Safety, Usage, and Risk Notices
|
|
642
|
+
|
|
643
|
+
### Intended Use
|
|
644
|
+
|
|
645
|
+
- Personal / internal development only
|
|
646
|
+
- Respect internal quotas and data handling policies
|
|
647
|
+
- Not for production services or bypassing intended limits
|
|
648
|
+
|
|
649
|
+
### Not Suitable For
|
|
650
|
+
|
|
651
|
+
- Production application traffic
|
|
652
|
+
- High-volume automated extraction
|
|
653
|
+
- Any use that violates Acceptable Use Policies
|
|
654
|
+
|
|
655
|
+
### Warning (Assumption of Risk)
|
|
656
|
+
|
|
657
|
+
By using this software, you acknowledge and accept the following:
|
|
658
|
+
|
|
659
|
+
- **Terms of Service risk**: This approach may violate the Terms of Service of AI model providers (Anthropic, Google, etc.). You are solely responsible for ensuring compliance with all applicable terms and policies.
|
|
660
|
+
|
|
661
|
+
- **Account risk**: Providers may detect this usage pattern and take punitive action, including suspension, permanent ban, or loss of access to paid subscriptions.
|
|
662
|
+
|
|
663
|
+
- **No guarantees**: Providers may change APIs, authentication, or policies at any time, which can break this method without notice.
|
|
664
|
+
|
|
665
|
+
- **Assumption of risk**: You assume all legal, financial, and technical risks. The authors and contributors of this project bear no responsibility for any consequences arising from your use.
|
|
666
|
+
|
|
667
|
+
**Use at your own risk. Proceed only if you understand and accept these risks.**
|
|
668
|
+
|
|
669
|
+
---
|
|
670
|
+
|
|
671
|
+
## Legal
|
|
672
|
+
|
|
673
|
+
- **Not affiliated with Google or Anthropic.** This is an independent open-source project and is not endorsed by, sponsored by, or affiliated with Google LLC or Anthropic PBC.
|
|
674
|
+
|
|
675
|
+
- "Gemini", "Google Cloud", and "Google" are trademarks of Google LLC.
|
|
676
|
+
|
|
677
|
+
- "Claude" and "Anthropic" are trademarks of Anthropic PBC.
|
|
678
|
+
|
|
679
|
+
- Software is provided "as is", without warranty. You are responsible for complying with all applicable Terms of Service and Acceptable Use Policies.
|
|
680
|
+
|
|
681
|
+
---
|
|
682
|
+
|
|
683
|
+
## Development
|
|
684
|
+
|
|
685
|
+
### For Developers & Contributors
|
|
686
|
+
|
|
687
|
+
This project uses a local Tailwind CSS build system. CSS is pre-compiled and included in the repository, so you can run the project immediately after cloning.
|
|
688
|
+
|
|
689
|
+
#### Quick Start
|
|
690
|
+
|
|
691
|
+
```bash
|
|
692
|
+
git clone https://github.com/AryanVBW/CommonsProxy.git
|
|
693
|
+
cd CommonsProxy
|
|
694
|
+
npm install # Automatically builds CSS via prepare hook
|
|
695
|
+
npm start # Start server (no rebuild needed)
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
#### Frontend Development
|
|
699
|
+
|
|
700
|
+
If you need to modify styles in `public/css/src/input.css`:
|
|
701
|
+
|
|
702
|
+
```bash
|
|
703
|
+
# Option 1: Build once
|
|
704
|
+
npm run build:css
|
|
705
|
+
|
|
706
|
+
# Option 2: Watch for changes (auto-rebuild)
|
|
707
|
+
npm run watch:css
|
|
708
|
+
|
|
709
|
+
# Option 3: Watch both CSS and server (recommended)
|
|
710
|
+
npm run dev:full
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
**File Structure:**
|
|
714
|
+
- `public/css/src/input.css` - Source CSS with Tailwind `@apply` directives (edit this)
|
|
715
|
+
- `public/css/style.css` - Compiled & minified CSS (auto-generated, don't edit)
|
|
716
|
+
- `tailwind.config.js` - Tailwind configuration
|
|
717
|
+
- `postcss.config.js` - PostCSS configuration
|
|
718
|
+
|
|
719
|
+
#### Backend-Only Development
|
|
720
|
+
|
|
721
|
+
If you're only working on backend code and don't need frontend dev tools:
|
|
722
|
+
|
|
723
|
+
```bash
|
|
724
|
+
npm install --production # Skip devDependencies (saves ~20MB)
|
|
725
|
+
npm start
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
**Note:** Pre-compiled CSS is committed to the repository, so you don't need to rebuild unless modifying styles.
|
|
729
|
+
|
|
730
|
+
#### Project Structure
|
|
731
|
+
|
|
732
|
+
See [CLAUDE.md](./CLAUDE.md) for detailed architecture documentation, including:
|
|
733
|
+
- Request flow and module organization
|
|
734
|
+
- Frontend architecture (Alpine.js + Tailwind)
|
|
735
|
+
- Service layer patterns (`ErrorHandler.withLoading`, `AccountActions`)
|
|
736
|
+
- Dashboard module documentation
|
|
737
|
+
|
|
738
|
+
---
|
|
739
|
+
|
|
740
|
+
## Credits
|
|
741
|
+
|
|
742
|
+
This project is based on insights and code from:
|
|
743
|
+
|
|
744
|
+
- [opencode-antigravity-auth](https://github.com/NoeFabris/opencode-antigravity-auth) - CommonsProxy OAuth plugin for OpenCode
|
|
745
|
+
- [claude-code-proxy](https://github.com/1rgs/claude-code-proxy) - Anthropic API proxy using LiteLLM
|
|
746
|
+
|
|
747
|
+
---
|
|
748
|
+
|
|
749
|
+
## License
|
|
750
|
+
|
|
751
|
+
MIT
|
|
752
|
+
|
|
753
|
+
---
|
|
754
|
+
|
|
755
|
+
## Star History
|
|
756
|
+
|
|
757
|
+
[](https://www.star-history.com/#badrisnarayanan/commons-proxy&type=date&legend=top-left)
|