Wesley Liddick
afbe8bf001
Merge pull request #809 from alfadb/feature/openai-messages
...
feat(openai): 添加 /v1/messages 端点和 API 兼容层
2026-03-06 20:16:06 +08:00
Wesley Liddick
005d0c5f53
Merge pull request #815 from mt21625457/pr/openai-user-group-rate-upstream
...
fix(openai): 统一专属倍率计费链路并补齐回归测试
2026-03-06 17:33:09 +08:00
yangjianbo
a18bbb5f2f
fix(openai): 统一专属倍率计费链路并补齐回归测试
...
抽取共享的用户分组专属倍率解析器,统一缓存、singleflight 与回退逻辑。\n\n让 OpenAI 独立计费链路复用专属倍率解析,修复 usage 记录与实际扣费未命中用户专属倍率的问题。\n\n补齐 OpenAI 计费与解析器单元测试,并修复全量回归中暴露的 lint 阻塞项。\n\nCo-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-06 16:47:51 +08:00
alfadb
ff1f114989
feat(openai): add /v1/messages endpoint and API compatibility layer
...
Add Anthropic Messages API support for OpenAI platform groups, enabling
clients using Claude-style /v1/messages format to access OpenAI accounts
through automatic protocol conversion.
- Add apicompat package with type definitions and bidirectional converters
(Anthropic ↔ Chat, Chat ↔ Responses, Anthropic ↔ Responses)
- Implement /v1/messages endpoint for OpenAI gateway with streaming support
- Add model mapping UI for OpenAI OAuth accounts (whitelist + mapping modes)
- Support prompt caching fields and codex OAuth transforms
- Fix tool call ID conversion for Responses API (fc_ prefix)
- Ensure function_call_output has non-empty output field
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-06 14:29:22 +08:00
erio
79ae15d5e8
fix: OpenAI passthrough accounts bypass model mapping check
...
透传模式账号仅替换认证,应允许所有模型通过。之前调度阶段的
isModelSupportedByAccount 不感知透传模式,导致 model_mapping
中未配置的新模型(如 gpt-5.4)被拒绝返回 503。
2026-03-06 14:01:47 +08:00
Wesley Liddick
63a8c76946
Merge pull request #798 from touwaeriol/feature/account-load-factor
...
feat: add account load_factor for scheduling load calculation
2026-03-06 09:42:10 +08:00
erio
0d6c1c7790
feat: add independent load_factor field for scheduling load calculation
2026-03-06 05:07:10 +08:00
erio
02dea7b09b
refactor: unify post-usage billing logic and fix account quota calculation
...
- Extract postUsageBilling() to consolidate billing logic across
GatewayService.RecordUsage, RecordUsageWithLongContext, and
OpenAIGatewayService.RecordUsage, eliminating ~120 lines of
duplicated code
- Fix account quota to use TotalCost × accountRateMultiplier
(was using raw TotalCost, inconsistent with account cost stats)
- Fix RecordUsageWithLongContext API Key quota only updating in
balance mode (now updates regardless of billing type)
- Fix WebSocket client disconnect detection on Windows by adding
"an established connection was aborted" to known disconnect errors
2026-03-06 00:54:17 +08:00
erio
05527b13db
feat: add quota limit for API key accounts
...
- Add configurable spending limit (quota_limit) for apikey-type accounts
- Atomic quota accumulation via PostgreSQL JSONB operations on TotalCost
- Scheduler filters out over-quota accounts with outbox-triggered snapshot refresh
- Display quota usage ($used / $limit) in account capacity column
- Add "Reset Quota" action in account menu to reset usage to zero
- Editing account settings preserves quota_used (no accidental reset)
- Covers all 3 billing paths: Anthropic, Gemini, OpenAI RecordUsage
chore: bump version to 0.1.90.4
2026-03-06 00:35:09 +08:00
shaw
9d70c38504
fix: 修复claude apikey账号请求时未携带beta=true 查询参数的bug
2026-03-05 15:01:04 +08:00
shaw
aeb464f3ca
feat: 模型映射应用 /v1/messages/count_tokens端点
2026-03-05 14:49:28 +08:00
Wesley Liddick
43c203333e
Merge pull request #733 from DaydreamCoding/fix/group-isolation
...
fix(gateway): 分组隔离 — 禁止未分组账号被跨组调度
2026-03-03 15:10:30 +08:00
shaw
a80ec5d8bb
feat: apikey支持5h/1d/7d速率控制
2026-03-03 15:01:10 +08:00
QTom
530a16291c
fix(gateway): 分组隔离 — 禁止未分组账号被跨组调度
...
当 API Key 无分组时,调度仅从未分组账号池中选取。
修复 isAccountInGroup 在 groupID==nil 时的逻辑,
同时补全 scheduler_snapshot_service 和 gemini_compat_service
中的 SimpleMode 保护,确保分组隔离在所有调度路径生效。
新增 ListSchedulableUngroupedByPlatform/s 方法,
使用 Ent 的 Not(HasAccountGroups()) 谓词实现未分组账号隔离。
新增 17 个单元和端到端隔离测试,覆盖所有分支和边界条件。
2026-03-03 13:20:58 +08:00
QTom
a9285b8a94
feat(gateway): 双模式用户消息队列 — 串行队列 + 软性限速
...
新增 UMQ (User Message Queue) 双模式支持:
- serialize: 账号级分布式串行锁 + RPM 自适应延迟(严格限流)
- throttle: 仅 RPM 自适应前置延迟,不阻塞并发(软性限速)
后端:
- config: 新增 Mode 字段,保留 Enabled 向后兼容
- service: 新增 UserMessageQueueService(Lua 锁/延迟算法/清理 worker)
- repository: 新增 UserMsgQueueCache(Redis Lua acquire/release/force-release)
- handler: 新增 UserMsgQueueHelper(SSE ping + 等待循环 + throttle)
- gateway: 按 mode 分支集成 serialize/throttle 逻辑
- lint: 修复 gofmt rewrite rules、errcheck 类型断言、staticcheck QF1012
前端:
- 三态选择器 UI(关闭/软性限速/串行队列)替代 toggle 开关
- BulkEdit 支持 null 语义(不修改)
- i18n 中英文文案
通过 6 轮专家评审(42 次 review)、golangci-lint、单元测试、集成测试。
2026-03-03 01:05:11 +08:00
QTom
2491e9b5ad
fix: round-3 review fixes for RPM limiting
...
- Add sanitizeExtraBaseRPM to BulkUpdate handler (was missing)
- Add WindowCost scheduling checks to legacy non-sticky selection
paths (4 sites), matching existing sticky + load-aware coverage
- Export ParseExtraInt from service package, remove duplicate
parseExtraIntForValidation from admin handler
2026-02-28 20:38:06 +08:00
QTom
e63c83955a
fix: address deep code review issues for RPM limiting
...
- Move IncrementRPM after Forward success to prevent phantom RPM
consumption during account switch retries
- Add base_rpm input sanitization (clamp to 0-10000) in Create/Update
- Add WindowCost scheduling checks to legacy path sticky sessions
(4 check sites + 4 prefetch sites), fixing pre-existing gap
- Clean up rpm_strategy/rpm_sticky_buffer when disabling RPM in
BulkEditModal (JSONB merge cannot delete keys, use empty values)
- Add json.Number test cases to TestGetBaseRPM/TestGetRPMStickyBuffer
- Document TOCTOU race as accepted soft-limit design trade-off
2026-02-28 20:38:06 +08:00
QTom
ff9683b0fc
fix: move RPM prefetch before routing segment in legacy/mixed paths
...
Ensures isAccountSchedulableForRPM calls within the routing segment
hit the prefetch cache instead of querying Redis individually.
2026-02-28 20:37:37 +08:00
QTom
607237571f
fix: address code review issues for RPM limiting feature
...
- Use TxPipeline (MULTI/EXEC) instead of Pipeline for atomic INCR+EXPIRE
- Filter negative values in GetBaseRPM(), update test expectation
- Add RPM batch query (GetRPMBatch) to account List API
- Add warn logs for RPM increment failures in gateway handler
- Reset enableRpmLimit on BulkEditAccountModal close
- Use union type 'tiered' | 'sticky_exempt' for rpmStrategy refs
- Add design decision comments for rdb.Time() RTT trade-off
2026-02-28 20:37:37 +08:00
QTom
f648b8e026
feat: increment RPM counter before request forwarding
2026-02-28 20:37:10 +08:00
QTom
678c3ae132
feat: integrate RPM scheduling checks into account selection flow
2026-02-28 20:37:10 +08:00
QTom
c1c31ed9b2
feat: wire RPMCache into GatewayService and AccountHandler
2026-02-28 20:35:38 +08:00
yangjianbo
bb664d9bbf
feat(sync): full code sync from release
2026-02-28 15:01:20 +08:00
erio
a6f9f9f968
feat: replace gemini-3-pro-image with gemini-3.1-flash-image
...
- Add migration 060 to update model_mapping for all antigravity accounts
- Remove gemini-3-pro-image and gemini-3-pro-image-preview mappings
- Add gemini-3.1-flash-image and gemini-3.1-flash-image-preview mappings
- Update frontend usage window to show GImage for new model
- Update isImageGenerationModel to support new model
2026-02-27 09:52:50 +08:00
alfadb
e6969acb50
fix: address review - fix log wording and add response body assertion in test
2026-02-26 23:49:30 +08:00
alfadb
9489531431
fix(gateway): return 404 instead of fake 200 for unsupported count_tokens endpoint
...
PR #635 returned HTTP 200 with {"input_tokens": 0} when upstream doesn't
support count_tokens (404). This caused Claude Code CLI to trust the zero
value, believing context uses 0 tokens, so auto-compression never triggers.
Fix: return 404 with proper error body so CLI falls back to its local
tokenizer for accurate estimation. Return nil (not error) to avoid
polluting ops error metrics with expected 404s.
Affected paths:
- Passthrough APIKey accounts: upstream 404 now passed through as 404
- Antigravity accounts: same fix (was also returning fake 200)
2026-02-26 23:34:53 +08:00
shaw
4ac57b4edf
fix: 临时移除fast-mode-2026-02-01避免429问题
2026-02-26 15:44:28 +08:00
alfadb
03bcd94ae5
fix: count_tokens 端点不支持时降级返回空值 (404 only)
...
第三方 Anthropic 中转站通常不支持 /v1/messages/count_tokens 端点,
上游返回 404 时降级返回 {input_tokens: 0},客户端 fallback 到本地估算。
- 仅匹配 404 状态码,语义明确:端点不存在
- 其他错误 (400/429/500) 保留原始处理链和 ops 遥测
- 无需解析错误消息内容,不依赖字符串匹配
- 新增 table-driven 测试覆盖 fallback 和 non-fallback 路径
2026-02-26 09:28:45 +08:00
erio
644058174e
fix(gemini): enable model_mapping filtering for Gemini API Key accounts
...
Remove the special case that bypassed model-supported checks for Gemini
API Key accounts, allowing model_mapping to filter requests properly.
Add tests for multiplatform model filtering behavior.
2026-02-24 18:54:59 +08:00
yangjianbo
2ee6c26676
fix(gateway): 修复粘性会话预取分组错配并优化并发等待热路径
2026-02-22 16:43:33 +08:00
yangjianbo
a89477ddf5
perf(gateway): 优化热点路径并补齐高覆盖测试
2026-02-22 13:31:30 +08:00
yangjianbo
1985be26b2
fix(gateway): 恢复 Anthropic 透传流数据间隔超时保护并补充回归测试
2026-02-21 16:54:44 +08:00
yangjianbo
bde9dbc57a
feat(anthropic): 支持 API Key 自动透传并优化透传链路性能
...
- 新增 Anthropic API Key 自动透传开关与后端透传分支(仅替换认证)
- 账号编辑页新增自动透传开关,默认关闭
- 优化透传性能:SSE usage 解析 gjson 快路径、减少请求体重复拷贝、优化流式写回与非流式 usage 解析
- 补充单元测试与 benchmark,确保 Claude OAuth 路径不受影响
2026-02-21 14:16:18 +08:00
yangjianbo
46d9aee6dd
feat(proxy,sora): 增强代理质量检测与Sora稳定性并修复审查问题
2026-02-19 21:18:35 +08:00
yangjianbo
440b87094a
fix(sora): 增强 Cloudflare 挑战识别并收敛 Sora 请求链路
...
- 在 failover 场景透传上游响应头并识别 Cloudflare challenge/cf-ray
- 统一 Sora 任务请求的 UA 与代理使用,sentinel 与业务请求保持一致
- 修复流式错误事件 JSON 转义问题并补充相关单元测试
2026-02-19 15:09:58 +08:00
yangjianbo
5d9667d27a
Merge branch 'main' into test
...
# Conflicts:
# backend/cmd/server/VERSION
# backend/ent/migrate/schema.go
# backend/ent/mutation.go
# backend/ent/runtime/runtime.go
# backend/ent/usagelog.go
# backend/ent/usagelog/usagelog.go
# backend/ent/usagelog/where.go
# backend/ent/usagelog_create.go
# backend/ent/usagelog_update.go
# backend/internal/repository/usage_log_repo.go
# backend/internal/server/api_contract_test.go
# backend/internal/server/middleware/cors.go
# backend/internal/service/gateway_service.go
2026-02-18 20:16:31 +08:00
yangjianbo
fad04ca995
Merge branch 'main' of https://github.com/mt21625457/aicodex2api
2026-02-18 20:10:32 +08:00
shaw
074bd0dfda
fix: 临时移除context-1m-2025-08-07以确保避免sonnet1m触发429
2026-02-18 18:41:30 +08:00
John Doe
3d1f03c286
feat: add Cache TTL Override per account + bump VERSION to 0.1.83
...
- Account-level cache TTL override: rewrite Anthropic cache_creation
token classification (5m↔1h) in streaming/non-streaming responses
- New DB field cache_ttl_overridden in usage_log for billing tracking
- Migration 055_add_cache_ttl_overridden
- Frontend: CacheTTL override toggle in account create/edit modals
- Ent schema regenerated for new usage_log fields
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-17 14:19:24 +03:00
yangjianbo
6577f2ef03
fix(gateway): 避免SSE delta将缓存创建明细重置为0
...
- 仅在 delta 中 5m/1h 值大于0时覆盖 usage 明细
- 新增回归测试覆盖 delta 默认 0 不应覆盖 message_start 非零值
- 迁移 054 在删除 legacy 字段前追加一次回填,避免升级实例丢失历史写入
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-16 13:23:12 +08:00
yangjianbo
41d0383fb7
merge(test): 合并 main 并解决前端筛选器冲突
2026-02-15 22:04:06 +08:00
程序猿MT
1cf51b14f7
Merge branch 'Wei-Shaw:main' into main
2026-02-15 20:49:14 +08:00
shaw
a817cafe3d
feat: 区分 Anthropic 5m/1h 缓存创建 token 的差异化计费
...
Anthropic API 的 cache_creation 对象区分了 ephemeral_5m 和 ephemeral_1h
两种缓存创建 token,1h 单价远高于 5m(如 claude-3-5-haiku: 5m=$1/MTok,
1h=$6/MTok)。此前系统统一按 5m 单价计费,导致计费偏低。
后端:
- pricing_service: 加载 LiteLLM 的 cache_creation_input_token_cost_above_1hr
- billing_service: GetModelPricing 启用分类计费(安全守卫 1h>5m),
CalculateCost 按 5m/1h 分别计费,无明细时回退到 5m 单价
- gateway_service: parseSSEUsage/handleNonStreamingResponse 用 gjson
提取嵌套 cache_creation 对象的 ephemeral_5m/1h_input_tokens
- antigravity_gateway_service: extractSSEUsage/extractClaudeUsage 同步提取
- usage_log: 修复 GORM column tag 确保写入正确的数据库列
- 新增迁移 054: 删除 GORM 自动生成的重复列
前端:
- 使用记录 tooltip 展示 5m/1h 缓存创建明细(带彩色 badge 区分)
- 表格单元格缓存写入数值旁显示 1h 标识
2026-02-14 18:15:35 +08:00
yangjianbo
d04b47b3ca
feat(backend): 提交后端审计修复与配套测试改动
2026-02-14 11:23:10 +08:00
yangjianbo
abf5de69fb
Merge branch 'main' into test
2026-02-12 23:43:47 +08:00
程序猿MT
174d7c774d
Merge branch 'Wei-Shaw:main' into main
2026-02-12 23:12:41 +08:00
yangjianbo
584cfc3db2
chore(logging): 完成后端日志审计与结构化迁移
...
- 将高密度服务与处理器日志迁移到新日志系统(LegacyPrintf/结构化日志)
- 增加 stdlog bridge 与兼容测试,保留旧日志捕获能力
- 将 OpenAI 断流告警改为结构化 Warn 并改造对应测试为 sink 捕获
- 补齐后端相关文件 logger 引用并通过全量 go test
2026-02-12 19:01:09 +08:00
程序猿MT
8da5fac69e
Merge branch 'Wei-Shaw:main' into main
2026-02-11 18:39:52 +08:00
SilentFlower
19cca11e00
[UPDATE] 增强 Claude Thinking 模式支持与 Opus 4.6 动态预算适配
...
✨ feat(antigravity): 支持 thinking adaptive 类型并适配 Opus 4.6 动态预算
🧪 test(gateway): 增加 thinking 模式解析与签名块过滤的边界用例测试
2026-02-11 10:31:16 +08:00
Edric Li
378e476e48
fix: 修复 CI 检查失败
...
- gofmt: 修复 error_passthrough_service.go 格式问题
- errcheck: 修复 error_passthrough_runtime_test.go 类型断言未检查
- staticcheck: if-else 改为 switch (gateway_service.go)
- test: 修复两个测试用例错误使用 MODEL_CAPACITY_EXHAUSTED 导致走错路径
2026-02-10 22:08:49 +08:00