Skip to content

Commit 49f9abf

Browse files
committed
feat(server): 开发者白名单生产透传与配额端点无限展示(DEV_USER_IDS)
1 parent b73a088 commit 49f9abf

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎server/.env.example‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ ALIYUN_ACCESS_KEY_SECRET=
6161
SUPABASE_JWT_SECRET=
6262
# JWT 验证算法:HS256(Supabase 默认)/ ES256(仅开启自定义 JWT 时选用)
6363
SUPABASE_JWT_ALGORITHM=HS256
64+
65+
# --- 开发者白名单(可选) ---
66+
# 邮箱或 Supabase user_id(sub claim),逗号分隔,大小写不敏感。
67+
# 命中的账户完全豁免 AI 配额/费用限制(rate_limit/budget 跳过)并赋予 lifetime 最高身份。
68+
# 生产部署需同时在 docker-compose.prod.yml 的 ai-gateway.environment 透传(DEV_USER_IDS: ${DEV_USER_IDS:-})
69+
#DEV_USER_IDS=dev@example.com
6470
# 项目 URL:从 Supabase Dashboard > Settings > API 获取
6571
SUPABASE_URL=https://your-project-id.supabase.co
6672
# JWKS URL:通常为 <SUPABASE_URL>/auth/v1/.well-known/jwks.json

‎server/ai-gateway/routers/license.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ async def get_quota(
214214
tier = get_effective_tier(beta_tier, paid_tier)
215215
limits = get_tier_limits(beta_tier, paid_tier)
216216

217+
# 开发者白名单(DEV_USER_IDS):实际完全豁免限流/费用,
218+
# 展示层用 -1 表示无限配额(客户端渲染为 ∞,避免误导性显示 120 次/天)
219+
if getattr(request.state, "is_dev", False):
220+
return QuotaResponse(
221+
used_calls=used_calls,
222+
total_calls=-1,
223+
used_cost=round(usage.get("yuan", 0.0), 4),
224+
cost_limit=-1,
225+
tier="lifetime",
226+
expires_at=None,
227+
)
228+
217229
# 服务端权威到期时间(用户全部绑定记录中的最高值)
218230
expires_at = None
219231
rows = await supabase_adapter.list_licenses_by_user(user_id)

‎server/docker-compose.prod.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ services:
119119
SUPABASE_JWT_SECRET: ${SUPABASE_JWT_SECRET:-}
120120
SUPABASE_URL: ${SUPABASE_URL:-}
121121
SUPABASE_SERVICE_KEY: ${SUPABASE_SERVICE_KEY:-}
122+
# 开发者白名单(邮箱或 user_id,逗号分隔):完全豁免配额/费用限制并赋予 lifetime 身份
123+
DEV_USER_IDS: ${DEV_USER_IDS:-}
122124
# 预算控制(每日 token/费用上限,0=不限制)
123125
BUDGET_DAILY_TOKEN_LIMIT: ${BUDGET_DAILY_TOKEN_LIMIT:-0}
124126
BUDGET_DAILY_COST_LIMIT: ${BUDGET_DAILY_COST_LIMIT:-0}

0 commit comments

Comments
 (0)