Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7a2e0f3
feat: add usage statistics tracking service
bbbugg Mar 25, 2026
51d7750
feat: enhance usage stats with IP tracking and detailed attempt display
bbbugg Apr 3, 2026
40fc456
feat: improve account column styling with wrapping and hover effects,…
bbbugg Apr 3, 2026
0658f7e
feat: improve account column styling with wrapping and hover effects,…
bbbugg Apr 3, 2026
f08b4b4
feat: enhance usage stats with dynamic stream mode and refine status …
bbbugg Apr 3, 2026
0a6f8c5
feat: add failed requests metric and enhance status card styling
bbbugg Apr 6, 2026
aa9fc8e
style: enhance usage stats filters with additional options and UI imp…
bbbugg Apr 9, 2026
ba01b21
style: enhance filter UI with custom search options and placeholder text
bbbugg Apr 9, 2026
fca1434
style: refine account key generation for improved uniqueness in stats…
bbbugg Apr 9, 2026
93ad50f
style: correct failed requests calculation in status page
bbbugg Apr 9, 2026
3eaaaa0
docs: update documentation for data persistence and mount paths
bbbugg Apr 9, 2026
8ca6408
style: enhance mobile responsiveness and usability of stats filters s…
bbbugg Apr 10, 2026
fd6e671
style: add tooltip for client IP display in status page for better us…
bbbugg Apr 10, 2026
c3adab8
style: enhance dropdown usability in stats filters with improved popp…
bbbugg Apr 10, 2026
f22468c
style: add custom time range filter to stats section for enhanced usa…
bbbugg Apr 10, 2026
20eb18d
style: implement pagination controls and localization for records dis…
bbbugg Apr 10, 2026
5f2d9ea
style: enhance usage tags with improved styling and error display in …
bbbugg Apr 10, 2026
d288c7c
style: simplify tag label structure and improve scrollbar styling in …
bbbugg Apr 10, 2026
d65bb3b
style: optimize usage stats record handling and improve error logging
bbbugg Apr 11, 2026
baab4a0
style: adjust records scroll wrapper to remove max-height restriction
bbbugg Apr 11, 2026
b2748fd
feat: add configuration for enabling/disabling usage statistics and u…
bbbugg Apr 11, 2026
957d30a
Update docs/zh/claw-cloud-run.md
bbbugg Apr 11, 2026
ee284f9
Update docs/en/claw-cloud-run.md
bbbugg Apr 11, 2026
0cba5e6
chore: improve error handling in RequestHandler and remove unused pat…
bbbugg Apr 11, 2026
affed9a
style: update i18n keys to use camelCase format for consistency
bbbugg Apr 11, 2026
1852953
fix: enhance early exit handling in RequestHandler for better service…
bbbugg Apr 11, 2026
fd2cd54
chore: normalize duration and outcome handling in UsageStatsService
bbbugg Apr 11, 2026
a3f8ac0
style: add success alpha variable for usage tags in variables.less
bbbugg Apr 11, 2026
408344b
chore: change log level from info to debug for request parts in Reque…
bbbugg Apr 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ FORCE_URL_CONTEXT=false
# Default: true
ENABLE_AUTH_UPDATE=true

# Enable request usage statistics
# When disabled, the service will not load local stats, will not write stats,
# and /api/usage-stats will return an empty payload
# Default: true
ENABLE_USAGE_STATS=true

# ===================================
# Account Switching Configuration
# ===================================
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ auth-*.json
users.csv
cache/

# Usage statistics data
data/

# Temporary files
tmp/
temp/
ui/dist/
*.css
test/
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
API 服务将在 `http://localhost:7860` 上运行。

服务启动后,您可以在浏览器中访问 `http://localhost:7860` 打开 Web 控制台主页,在这里可以查看账号状态和服务状态。
请求统计数据会持久化保存到 `/data/usage-stats.jsonl`。
Comment thread
bbbugg marked this conversation as resolved.

Comment thread
bbbugg marked this conversation as resolved.
5. 更新到最新版本(已有本地部署时):

Expand All @@ -73,6 +74,7 @@ docker run -d \
--name aistudio-to-api \
-p 7860:7860 \
-v /path/to/auth:/app/configs/auth \
-v /path/to/data:/app/data \
Comment thread
bbbugg marked this conversation as resolved.
-e API_KEYS=your-api-key-1,your-api-key-2 \
-e TZ=Asia/Shanghai \
--restart unless-stopped \
Expand All @@ -83,8 +85,9 @@ docker run -d \

参数说明:

- `-p 7860:7860`:API 服务器端口(如果使用反向代理,强烈建议改成 127.0.0.1:7860)
- `-p 7860:7860`:API 服务器端口(如果使用反向代理,强烈建议改成 `127.0.0.1:7860`
- `-v /path/to/auth:/app/configs/auth`:挂载包含认证文件的目录
- `-v /path/to/data:/app/data`:挂载统计数据持久化目录(`/app/data/usage-stats.jsonl`)
Comment thread
bbbugg marked this conversation as resolved.
- `-e API_KEYS`:用于身份验证的 API 密钥列表(使用逗号分隔)
- `-e TZ=Asia/Shanghai`:时区设置(可选,默认使用系统时区)

Expand All @@ -106,6 +109,8 @@ services:
volumes:
# 挂载包含认证文件的目录
- ./auth:/app/configs/auth
# 挂载统计数据持久化目录
- ./data:/app/data
environment:
# 用于身份验证的 API 密钥列表(使用逗号分隔)
API_KEYS: your-api-key-1,your-api-key-2
Expand All @@ -132,6 +137,7 @@ services:
--name aistudio-to-api \
-p 7860:7860 \
-v /path/to/auth:/app/configs/auth \
-v /path/to/data:/app/data \
-e API_KEYS=your-api-key-1,your-api-key-2 \
-e TZ=Asia/Shanghai \
--restart unless-stopped \
Expand Down Expand Up @@ -235,6 +241,7 @@ services:
| :------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-------- |
| `INITIAL_AUTH_INDEX` | 启动时使用的初始身份验证索引。 | `0` |
| `ENABLE_AUTH_UPDATE` | 是否启用自动保存凭证更新。默认为启用状态,将在每次登录/切换账号成功时以及每 24 小时自动更新 auth 文件。设为 `false` 禁用。 | `true` |
| `ENABLE_USAGE_STATS` | 是否启用请求统计。默认为启用;设为 `false` 后,不读取本地统计、不写入统计,`/api/usage-stats` 返回空数据。 | `true` |
| `MAX_RETRIES` | 请求失败后的最大重试次数(仅对假流式和非流式生效)。 | `3` |
| `RETRY_DELAY` | 两次重试之间的间隔(毫秒)。 | `2000` |
| `SWITCH_ON_USES` | 自动切换帐户前允许的请求次数(设为 `0` 禁用)。 | `40` |
Expand Down
7 changes: 7 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ A tool that wraps Google AI Studio web interface to provide OpenAI API, Gemini A
The API server will be available at `http://localhost:7860`

After the service starts, you can access `http://localhost:7860` in your browser to open the web console homepage, where you can view account status and service status.
Request usage statistics are persisted locally at `/data/usage-stats.jsonl`.
Comment thread
bbbugg marked this conversation as resolved.

Comment thread
bbbugg marked this conversation as resolved.
5. Update to the latest version (for existing local deployments):

Expand All @@ -73,6 +74,7 @@ docker run -d \
--name aistudio-to-api \
-p 7860:7860 \
-v /path/to/auth:/app/configs/auth \
-v /path/to/data:/app/data \
Comment thread
bbbugg marked this conversation as resolved.
-e API_KEYS=your-api-key-1,your-api-key-2 \
-e TZ=America/New_York \
--restart unless-stopped \
Expand All @@ -85,6 +87,7 @@ Parameters:

- `-p 7860:7860`: API server port (if using a reverse proxy, strongly consider `127.0.0.1:7860`)
- `-v /path/to/auth:/app/configs/auth`: Mount directory containing auth files
- `-v /path/to/data:/app/data`: Mount persistent data directory for usage statistics (`/app/data/usage-stats.jsonl`)
Comment thread
bbbugg marked this conversation as resolved.
- `-e API_KEYS`: Comma-separated list of API keys for authentication
- `-e TZ=America/New_York`: Timezone for logs (optional, defaults to system timezone)

Expand All @@ -106,6 +109,8 @@ services:
volumes:
# Mount directory containing auth files
- ./auth:/app/configs/auth
# Mount persistent data directory for usage statistics
- ./data:/app/data
environment:
# Comma-separated list of API keys for authentication
API_KEYS: your-api-key-1,your-api-key-2
Expand All @@ -130,6 +135,7 @@ If you prefer to build the Docker image yourself, you can use the following comm
--name aistudio-to-api \
-p 7860:7860 \
-v /path/to/auth:/app/configs/auth \
-v /path/to/data:/app/data \
-e API_KEYS=your-api-key-1,your-api-key-2 \
-e TZ=America/New_York \
--restart unless-stopped \
Expand Down Expand Up @@ -233,6 +239,7 @@ This endpoint forwards requests to the official Gemini API format endpoint.
| :------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------- |
| `INITIAL_AUTH_INDEX` | Initial authentication index to use on startup. | `0` |
| `ENABLE_AUTH_UPDATE` | Whether to enable automatic auth credential updates. Defaults to enabled. The auth file will be automatically updated upon successful login/account switch and every 24 hours. Set to `false` to disable. | `true` |
| `ENABLE_USAGE_STATS` | Whether to enable request usage statistics. Defaults to enabled. Set to `false` to skip loading local stats, skip writing stats, and make `/api/usage-stats` return an empty payload. | `true` |
| `MAX_RETRIES` | Maximum number of retries for failed requests (only effective for fake streaming and non-streaming). | `3` |
| `RETRY_DELAY` | Delay between retries in milliseconds. | `2000` |
| `SWITCH_ON_USES` | Number of requests before automatically switching accounts (`0` to disable). | `40` |
Expand Down
8 changes: 6 additions & 2 deletions docs/en/claw-cloud-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ This guide will help you deploy the `aistudio-to-api` service on [Claw Cloud Run
- **Public Access**: Toggle **On** (Leave the URL usage as is).

**Local Storage**:
- **Capacity**:1
- **Mount Path**:/app/configs/auth
- **Storage 1**
- **Capacity**:1
- **Mount Path**:/app/configs/auth
- **Storage 2**
- **Capacity**:1
- **Mount Path**:/app/data

**Environment Variables**:

Expand Down
8 changes: 6 additions & 2 deletions docs/zh/claw-cloud-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
- **Public Access**:开启(Toggle **On**,后面的网址选项不用动)。

**Local Storage**:
- **Capacity**:1
- **Mount Path**:/app/configs/auth
- **存储卷 1**
- **Capacity**:1
- **Mount Path**:/app/configs/auth
- **存储卷 2**
- **Capacity**:1
- **Mount Path**:/app/data

**环境变量(Environment Variables)**:

Expand Down
10 changes: 9 additions & 1 deletion src/core/ProxyServerSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ const http = require("http");
const https = require("https");
const fs = require("fs");
const net = require("net");
const path = require("path");
const { URL } = require("url");
Comment thread
bbbugg marked this conversation as resolved.

const LoggingService = require("../utils/LoggingService");
const AuthSource = require("../auth/AuthSource");
const BrowserManager = require("./BrowserManager");
const ConnectionRegistry = require("./ConnectionRegistry");
const RequestHandler = require("./RequestHandler");
const UsageStatsService = require("./UsageStatsService");
const ConfigLoader = require("../utils/ConfigLoader");
const WebRoutes = require("../routes/WebRoutes");

Expand All @@ -40,6 +42,12 @@ class ProxyServerSystem extends EventEmitter {

this.authSource = new AuthSource(this.logger);
this.browserManager = new BrowserManager(this.logger, this.config, this.authSource);
this.usageStatsService = new UsageStatsService(
this.authSource,
this.logger,
path.join(process.cwd(), "data"),
this.config.enableUsageStats
);

// Create ConnectionRegistry with lightweight reconnect callback
// When WebSocket connection is lost but browser is still running,
Expand Down Expand Up @@ -351,6 +359,7 @@ class ProxyServerSystem extends EventEmitter {
app.use((req, res, next) => {
if (
req.path !== "/api/status" &&
req.path !== "/api/usage-stats" &&
req.path !== "/" &&
req.path !== "/favicon.ico" &&
req.path !== "/login" &&
Expand Down Expand Up @@ -440,7 +449,6 @@ class ProxyServerSystem extends EventEmitter {
});

// Serve static files from ui/dist (Vite build output)
const path = require("path");
app.use(express.static(path.join(__dirname, "..", "..", "ui", "dist")));

// Serve additional public assets under ui/public
Expand Down
Loading
Loading