erio
8917afab2a
fix(antigravity): reduce 429 fallback cooldown from 5min to 30s
...
The default fallback cooldown when rate limit reset time cannot be
parsed was 5 minutes, which is too aggressive and causes accounts
to be unnecessarily locked out. Reduce to 30 seconds for faster
recovery. Config override still works (unit remains minutes).
2026-02-07 11:54:00 +08:00
shaw
39a5b17d31
fix: 账号测试根据类型使用不同的 beta header
...
- OAuth 账号:使用完整的 DefaultBetaHeader 和 Claude Code 客户端 headers
- API Key 账号:使用 APIKeyBetaHeader(不含 oauth beta)
2026-02-07 11:33:06 +08:00
shaw
5299f3dcf6
fix: ix: antigravity 添加 aude-opus-4-6-thinking 模型支持
2026-02-07 10:38:10 +08:00
shaw
7b1564898b
fix: make error passthrough effective for non-failover upstream errors
2026-02-07 10:25:56 +08:00
shaw
9f4c1ef9f9
fix(ops): 添加 token 相关字段白名单避免误脱敏
...
在敏感字段检测中添加白名单,排除 API 参数和用量统计字段:
- max_tokens, max_completion_tokens, max_output_tokens
- completion_tokens, prompt_tokens, total_tokens
- input_tokens, output_tokens
- cache_creation_input_tokens, cache_read_input_tokens
这些字段名虽然包含 "token" 但只是数值参数,不应被脱敏处理。
2026-02-06 19:47:14 +08:00
Wesley Liddick
a381910e86
Merge pull request #489 from LLLLLLiulei/feat/import-export-bundle
...
feat: implement account & proxy import/export with migration-ready JSON bundles
2026-02-06 16:29:52 +08:00
shaw
d182ef0391
fix(gateway): 移除 PR #316 引入的工具名转换逻辑
...
移除响应阶段的工具名/schema/description 转换逻辑,修复第三方工具调用时
工具名被错误转换的问题(如 Task → task)。
移除内容:
- 工具名相关正则变量(toolPrefixRe, toolNameBoundaryRe 等)
- openCodeToolOverrides 和 claudeToolNameOverrides 映射表
- 工具名转换函数(normalizeToolNameForClaude, normalizeToolNameForOpenCode 等)
- 响应体工具名替换函数(replaceToolNamesInText, replaceToolNamesInResponseBody 等)
- 参数名转换函数(normalizeParamNameForOpenCode, rewriteParamKeysInValue)
- 工具描述清理函数(sanitizeToolDescription)
- 输入 schema 转换函数(normalizeToolInputSchema)
- 模型 ID 正则替换函数(replaceModelIDInText)
保留内容:
- 系统提示词清理(sanitizeSystemText)
- Claude Code 指纹 headers 处理
- 模型 ID 映射(通过 JSON 对象操作)
2026-02-06 16:09:58 +08:00
LLLLLLiulei
7319122e92
merge upstream/main
2026-02-06 11:33:45 +08:00
yangjianbo
ee01f80dc1
test(backend): 修复 usage 类型断言未检查
2026-02-06 09:54:29 +08:00
yangjianbo
98671a73f4
Merge branch 'main' of https://github.com/mt21625457/aicodex2api
...
# Conflicts:
# backend/internal/service/gateway_cached_tokens_test.go
2026-02-06 09:35:46 +08:00
yangjianbo
f33a950103
fix(兼容): 将 Kimi cached_tokens 映射到 Claude 标准 cache_read_input_tokens
...
Kimi 等 Claude 兼容 API 返回缓存信息使用 OpenAI 风格的 cached_tokens 字段,
而非 Claude 标准的 cache_read_input_tokens,导致客户端收不到缓存命中信息且
内部计费缓存折扣为 0。
新增 reconcileCachedTokens 辅助函数,在 cache_read_input_tokens == 0 且
cached_tokens > 0 时自动填充,覆盖流式(message_start/message_delta)和
非流式两种响应路径。对 Claude 原生上游无影响。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-06 09:27:42 +08:00
程序猿MT
132bf34b69
Merge branch 'Wei-Shaw:main' into main
2026-02-06 08:53:52 +08:00
shaw
01b08e1e43
chore: 前端增加opus4.6模型映射
2026-02-06 08:50:45 +08:00
yangjianbo
c6a456c7c7
fix(兼容): 将 Kimi cached_tokens 映射到 Claude 标准 cache_read_input_tokens
...
Kimi 等 Claude 兼容 API 返回缓存信息使用 OpenAI 风格的 cached_tokens 字段,
而非 Claude 标准的 cache_read_input_tokens,导致客户端收不到缓存命中信息且
内部计费缓存折扣为 0。
新增 reconcileCachedTokens 辅助函数,在 cache_read_input_tokens == 0 且
cached_tokens > 0 时自动填充,覆盖流式(message_start/message_delta)和
非流式两种响应路径。对 Claude 原生上游无影响。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-06 08:42:55 +08:00
yangjianbo
a38bd413ab
fix(计费): gpt-5.3-codex 定价回退到 gpt-5.2-codex
2026-02-06 07:40:38 +08:00
yangjianbo
9e1535e203
feat(模型): 添加 gpt-5.3 Codex 映射与价格配置
2026-02-06 07:14:46 +08:00
Wesley Liddick
571d1479a4
Merge pull request #490 from IanShaw027/fix/gemini-oauth-registered-user
...
fix(gemini): 修复已注册用户 OAuth 授权问题并增强错误提示
2026-02-05 22:37:20 +08:00
shaw
39e05a2dad
feat: 新增全局错误透传规则功能
...
支持管理员配置上游错误如何返回给客户端:
- 新增 ErrorPassthroughRule 数据模型和 Ent Schema
- 实现规则的 CRUD API(/admin/error-passthrough-rules)
- 支持按错误码、关键词匹配,支持 any/all 匹配模式
- 支持按平台过滤(anthropic/openai/gemini/antigravity)
- 支持透传或自定义响应状态码和错误消息
- 实现两级缓存(Redis + 本地内存)和多实例同步
- 集成到 gateway_handler 的错误处理流程
- 新增前端管理界面组件
- 新增单元测试覆盖核心匹配逻辑
优化:
- 移除 refreshLocalCache 中的冗余排序(数据库已排序)
- 后端 Validate() 增加匹配条件非空校验
2026-02-05 21:52:54 +08:00
LLLLLLiulei
0b45d48e85
perf: batch fetch proxies for account export
2026-02-05 18:40:49 +08:00
LLLLLLiulei
b4bd46d067
feat: add data import/export bundle
2026-02-05 17:46:08 +08:00
shaw
2b192f7dca
feat: 支持用户专属分组倍率配置
2026-02-05 16:05:42 +08:00
IanShaw027
979114db45
fix(gemini): 修复已注册用户 OAuth 授权时错误调用 onboardUser 的问题
...
问题:Google One Ultra 等已注册用户在 OAuth 授权时,如果 LoadCodeAssist
返回了 currentTier/paidTier 但没有返回 cloudaicompanionProject,之前的
逻辑会继续调用 onboardUser,导致 INVALID_ARGUMENT 错误。
修复:对齐 Gemini CLI 的处理逻辑:
- 当检测到用户已注册(有 currentTier/paidTier)时,不再调用 onboardUser
- 先尝试从 Cloud Resource Manager 获取可用项目
- 如果仍无法获取,返回友好的错误提示,引导用户手动填写 Project ID
这个修复解决了 Google One 订阅用户无法正常授权的问题。
2026-02-05 13:57:02 +08:00
Wesley Liddick
dabed96af4
Merge pull request #486 from s-Joshua-s/feat/usage-filter-by-apikey
...
feat(gateway): filter /v1/usage stats by API Key instead of UserID
2026-02-05 13:37:31 +08:00
shaw
49a3c43741
feat(auth): 实现 Refresh Token 机制
...
- 新增 Access Token + Refresh Token 双令牌认证
- 支持 Token 自动刷新和轮转
- 添加登出和撤销所有会话接口
- 前端实现无感刷新和主动刷新定时器
2026-02-05 12:42:54 +08:00
JIA-ss
fa3ea5ee4d
feat(gateway): filter /v1/usage stats by API Key instead of UserID
...
Previously the /v1/usage endpoint aggregated usage stats (today/total
tokens, cost, RPM/TPM) across all API Keys belonging to the user.
This made it impossible to distinguish usage from different API Keys
(e.g. balance vs subscription keys).
Now the usage stats are filtered by the current request's API Key ID,
so each key only sees its own usage data. The balance/remaining fields
are unaffected and still reflect the user-level wallet balance.
Changes:
- Add GetAPIKeyDashboardStats to repository interface and implementation
- Add getPerformanceStatsByAPIKey helper (also fixes TPM to include
cache_creation_tokens and cache_read_tokens)
- Add GetAPIKeyDashboardStats to UsageService
- Update Usage handler to call GetAPIKeyDashboardStats(apiKey.ID)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-02-05 11:45:54 +08:00
shaw
05af95dade
fix(gateway): 修复工具名转换破坏 Anthropic 特殊工具的问题
...
未知工具名不再进行 PascalCase/snake_case 转换,保持原样透传。
修复 text_editor_20250728 等 Anthropic 特殊工具被错误转换的问题。
2026-02-05 09:53:20 +08:00
Wesley Liddick
ae680d79ed
Merge pull request #481 from beyondkmp/fix/remove-unsupported-openai-fields
...
fix: remove unsupported safety_identifier and previous_response_id fields from upstream requests
2026-02-05 08:35:12 +08:00
shaw
8f39754812
fix(gateway): 修复模型前缀映射逻辑错误
...
问题:normalizeClaudeModelForAnthropic 函数错误地将长模型ID截断为短ID,
导致 APIKey 账号的模型名被错误修改。
修复:
- 删除错误的 normalizeClaudeModelForAnthropic 函数和 anthropicPrefixMappings 变量
- 直接使用 claude.NormalizeModelID(正确的短ID->长ID扩展)
- APIKey 账号无显式映射时透传原始模型名
2026-02-04 17:50:05 +08:00
Payne Fu
fecfaae8dc
fix: remove unsupported safety_identifier and previous_response_id fields from upstream requests
...
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-02-04 15:56:01 +08:00
Wesley Liddick
804b6f2282
Merge pull request #468 from s-Joshua-s/fix/thinking-block-modification-error
...
fix(api): 修复 thinking 块被意外修改导致的 400 错误
2026-02-03 22:21:06 +08:00
Wesley Liddick
cb58daf38d
Merge pull request #476 from touwaeriol/fix/gemini-thoughtsignature-v2
...
fix(gemini): 导出 DummyThoughtSignature 常量并修复跨账号签名验证
2026-02-03 21:56:34 +08:00
Wesley Liddick
a9398d210b
Merge pull request #475 from touwaeriol/fix/openai-oauth-instructions-v2
...
fix(openai): 统一 OAuth instructions 处理逻辑,修复 Codex CLI 400 错误
2026-02-03 21:56:13 +08:00
Wesley Liddick
4cce21b125
Merge branch 'main' into main
2026-02-03 21:43:41 +08:00
liuxiongfeng
6baf810885
fix(gemini): 导出 DummyThoughtSignature 常量并修复跨账号签名验证
...
- 将 dummyThoughtSignature 改为导出的 DummyThoughtSignature 常量,供跨包使用
- 修改 gemini_native_signature_cleaner.go 将删除签名改为替换为 dummy 签名
这样可以跳过 Gemini 3 的签名验证,解决粘性会话切换账号时的验证失败问题
- 更新相关测试文件
Fixes: 粘性会话切换账号时 thoughtSignature 验证失败导致 400 错误
2026-02-03 21:34:55 +08:00
liuxiongfeng
9a48b2e942
fix(openai): 统一 OAuth instructions 处理逻辑,修复 Codex CLI 400 错误
...
- 修改 applyCodexOAuthTransform 函数签名,增加 isCodexCLI 参数
- 移除 && !isCodexCLI 条件,对所有 OAuth 请求统一处理
- 新增 applyInstructions/applyCodexCLIInstructions/applyOpenCodeInstructions 辅助函数
- 新增 isInstructionsEmpty 函数检查 instructions 字段是否为空
- 添加 Codex CLI 和非 Codex CLI 场景的测试用例
逻辑说明:
- Codex CLI + 有 instructions: 保持不变
- Codex CLI + 无 instructions: 补充 opencode 指令
- 非 Codex CLI: 使用 opencode 指令覆盖
2026-02-03 21:22:33 +08:00
Wesley Liddick
c0c9c984d1
Merge pull request #471 from bayma888/feature/api-key-quota-expiration
...
feat(api-key): 添加API密钥独立配额和过期时间功能
2026-02-03 21:11:17 +08:00
bayma888
3fed478e4d
fix(lint): format gateway_service.go with gofmt
2026-02-03 20:55:17 +08:00
bayma888
be7bc658fc
fix(test): add IncrementQuotaUsed to all APIKeyRepository test stubs
...
- Add missing IncrementQuotaUsed method to stubApiKeyRepo in api_contract_test.go
- Fix gofmt formatting issues in api_key_service.go, dto/types.go, api_key_handler.go
2026-02-03 20:49:58 +08:00
Wesley Liddick
c89bbf5130
Merge pull request #458 from bayma888/feature/admin-user-balance-history
...
feat(admin): 管理员可查看每个用户充值和并发变动记录、点击余额可直接查看、优化弹框UI
2026-02-03 20:37:30 +08:00
bayma888
e59e3a9f00
fix(test): add IncrementQuotaUsed to all APIKeyRepository test stubs
...
Add the missing IncrementQuotaUsed method to:
- fakeAPIKeyRepo (api_key_auth_google_test.go)
- stubApiKeyRepo (api_key_auth_test.go)
- apiKeyRepoStub (api_key_service_delete_test.go)
- authRepoStub (api_key_service_cache_test.go)
2026-02-03 20:00:43 +08:00
bayma888
6146be1474
feat(api-key): add independent quota and expiration support
...
This feature allows API Keys to have their own quota limits and expiration
times, independent of the user's balance.
Backend:
- Add quota, quota_used, expires_at fields to api_key schema
- Implement IsExpired() and IsQuotaExhausted() checks in middleware
- Add ResetQuota and ClearExpiration API endpoints
- Integrate quota billing in gateway handlers (OpenAI, Anthropic, Gemini)
- Include quota/expiration fields in auth cache for performance
- Expiration check returns 403, quota exhausted returns 429
Frontend:
- Add quota and expiration inputs to key create/edit dialog
- Add quick-select buttons for expiration (+7, +30, +90 days)
- Add reset quota confirmation dialog
- Add expires_at column to keys list
- Add i18n translations for new features (en/zh)
Migration:
- Add 045_add_api_key_quota.sql for new columns
2026-02-03 19:49:31 +08:00
bayma888
d008941cb3
fix(test): add missing stub methods for RedeemCodeRepository and AdminService
...
Add ListByUserPaginated and SumPositiveBalanceByUser to redeemRepoStub
Add GetUserBalanceHistory to stubAdminService
Fixes CI test compilation errors
2026-02-03 19:29:39 +08:00
song
0707f3d963
chore: gofmt
2026-02-03 17:03:54 +08:00
song
f1aafbc06f
chore: gofmt
2026-02-03 16:55:13 +08:00
song
7cb5444dbb
fix: update tests for group fallback
2026-02-03 16:48:52 +08:00
song
3bede6e65f
merge upstream main
2026-02-03 16:21:58 +08:00
JIA-ss
ad90bb4645
fix(api): 修复 thinking 块被意外修改导致的 400 错误
...
问题描述:
使用扩展思考功能时,偶现以下错误:
"thinking or redacted_thinking blocks in the latest assistant message cannot be modified"
根因分析:
当代理服务修改请求体中的某些字段时(如 metadata.user_id、model),
使用 map[string]any 解析整个 JSON 后重新序列化,导致:
1. 字段顺序改变(Go map 序列化按字母排序)
2. 数字格式变化(如 1.0 → 1)
3. Unicode 转义变化
Claude API 对 thinking 块进行字节级验证,任何变化都会触发错误。
修复内容:
1. identity_service.go - RewriteUserID/RewriteUserIDWithMasking
使用 json.RawMessage 保留其他字段的原始字节
2. gateway_service.go - replaceModelInBody
使用 json.RawMessage 保留其他字段的原始字节
3. gateway_service.go - normalizeClaudeOAuthRequestBody
保留 messages 的原始字节,跳过包含 thinking 块的消息修改
4. gateway_service.go - isThinkingBlockSignatureError
添加 "cannot be modified" 错误检测,触发自动重试
5. antigravity_gateway_service.go - isSignatureRelatedError
添加 "cannot be modified" 错误检测
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-02-03 16:15:37 +08:00
song
2220fd18ca
merge upstream main
2026-02-03 15:36:17 +08:00
Wesley Liddick
bb3df5785a
Merge pull request #322 from xlx0852/main
...
fix: 混合渠道警告确认框和过滤 prompt_cache_retention 参数
2026-02-03 15:13:10 +08:00
Wesley Liddick
6e54eda41f
Merge pull request #464 from touwaeriol/pr/antigravity-scope-ratelimit
...
feat(antigravity): 支持按配额域(scope)级别限流
2026-02-03 15:02:15 +08:00