YanzheL
c5aac1251d
fix(gateway): add content-based session hash fallback for non-Codex clients
...
When no explicit session signals (session_id, conversation_id, prompt_cache_key)
are provided, derive a stable session seed from the request body content
(model + tools + system prompt + first user message) to enable sticky routing
and prompt caching for non-Codex clients using the Chat Completions API.
This mirrors the content-based fallback already present in GatewayService.
GenerateSessionHash, adapted for the OpenAI gateway's request formats (both
Chat Completions messages and Responses API input).
JSON fragments are canonicalized via normalizeCompatSeedJSON to ensure
semantically identical requests produce the same seed regardless of
whitespace or key ordering.
Closes #1421
2026-04-02 00:11:06 +08:00
wucm667
f5764d8dc6
fix(billing): 计费始终使用用户请求的原始模型,而非映射后的上游模型
...
当账号配置了模型映射(如 claude-sonnet-4-6 → glm-5.0)时,系统错误地
使用映射后的上游模型名计算费用。由于上游模型(如 glm-5.0)在定价系统中
没有价格配置,导致计费失败后被静默置为 0,用户不被扣费。
修改 forwardResultBillingModel 优先返回请求模型名,并移除 OpenAI 路径
中 BillingModel 字段对计费模型的覆盖逻辑。
2026-03-28 16:22:06 +08:00
Wesley Liddick
4b1ffc23f5
Merge pull request #1240 from Zqysl/qingyu/fix-openai-passthrough-429-rate-limits
...
fix(openai): persist passthrough 429 rate limits
2026-03-24 19:02:40 +08:00
qingyuzhang
ce8520c9e6
fix(openai): persist passthrough 429 rate limits
2026-03-24 01:48:25 +08:00
Wang Lvyuan
fef9259aaa
fix(openai): recheck runtime state from db before final account selection
2026-03-23 03:50:03 +08:00
Ethan0x0000
4edcfe1f7c
fix(usage): preserve requested model in gateway billing paths
...
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent )
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai >
2026-03-21 01:23:54 +08:00
Ethan0x0000
2e4ac88ad9
feat(service): record upstream model across all gateway paths
...
Propagate UpstreamModel through ForwardResult and OpenAIForwardResult in Anthropic direct, API-key passthrough, Bedrock, and OpenAI gateway flows. Extract optionalNonEqualStringPtr and optionalTrimmedStringPtr into usage_log_helpers.go. Store upstream_model only when it differs from the requested model.
Also introduces anthropicPassthroughForwardInput struct to reduce parameter count.
2026-03-17 19:25:35 +08:00
QTom
ab4e8b2cf0
fix(gateway): 防止 OpenAI Codex 跨用户串流
...
根因:多个用户共享同一 OAuth 账号时,conversation_id/session_id 头
未做用户隔离,导致上游 chatgpt.com 将不同用户的请求关联到同一会话。
HTTP SSE 修复:
- 新增 isolateOpenAISessionID(apiKeyID, raw),将 API Key ID 混入
session 标识符(xxhash),确保不同 Key 的用户产生不同上游会话
- buildUpstreamRequest: OAuth 分支先 Del 客户端透传的 session 头,
再用隔离值覆盖
- buildUpstreamRequestOpenAIPassthrough: 透传路径同样隔离
- ForwardAsAnthropic: Anthropic Messages 兼容路径同步修复
- buildOpenAIWSHeaders: WS 路径的 OAuth session 头同步隔离
2026-03-16 10:28:51 +08:00
erio
cfe72159d0
feat(ops): add ignore insufficient balance errors toggle and extract error constants
...
- Add 5th error filter switch IgnoreInsufficientBalanceErrors to suppress
upstream insufficient balance / insufficient_quota errors from ops log
- Extract hardcoded error strings into package-level constants for
shouldSkipOpsErrorLog, normalizeOpsErrorType, classifyOpsPhase, and
classifyOpsIsBusinessLimited
- Define ErrNoAvailableAccounts sentinel error and replace all
errors.New("no available accounts") call sites
- Update tests to use require.ErrorIs with the sentinel error
2026-03-15 17:26:18 +08:00
Ethan0x0000
eefab15958
feat: 完善使用记录端点可观测性与分布统计
...
将入站、上游与路径三类端点分布统一到使用记录页的一致化卡片交互中,并补齐端点元数据与统计链路,提升排障与流量分析效率。
2026-03-15 11:26:42 +08:00
InCerry
e4a4dfd038
Merge remote-tracking branch 'origin/main' into fix/enc_coot
...
# Conflicts:
# backend/internal/service/openai_gateway_service.go
2026-03-14 13:04:24 +08:00
InCerry
2666422b99
fix: handle invalid encrypted content error and retry logic.
2026-03-14 11:42:42 +08:00
ius
b764d3b8f6
Merge remote-tracking branch 'origin/main' into feat/billing-ledger-decouple-usage-log-20260312
2026-03-12 16:53:28 +08:00
ius
611fd884bd
feat: decouple billing correctness from usage log batching
2026-03-12 16:53:18 +08:00
Wesley Liddick
c0110cb5af
Merge pull request #941 from CoolCoolTomato/main
...
fix: 修复gpt-5.2以上模型映射到gpt-5.2以下时verbosity参数引发的报错
2026-03-12 09:35:09 +08:00
Wesley Liddick
78193ceec1
Merge pull request #931 from xvhuan/fix/db-write-amplification-20260311
...
降低 quota 与 Codex 快照热路径的数据库写放大
2026-03-12 09:27:34 +08:00
CoolCoolTomato
eb0b77bf4d
fix: 修复流水线golangci-lint 的 errcheck
2026-03-11 22:56:20 +08:00
shaw
9d81467937
refactor: 重构 Chat Completions 端点,采用类型安全的 Responses API 转换
...
将 /v1/chat/completions 端点从 ResponseWriter 劫持模式重构为独立的
类型安全转换路径,与 Anthropic Messages 端点架构对齐:
- 在 apicompat 包新增 Chat Completions 完整类型定义和双向转换器
- 新增 ForwardAsChatCompletions service 方法,走 Responses API 上游
- Handler 改为独立的账号选择/failover 循环,不再劫持 Responses handler
- 提取 handleCompatErrorResponse 为 Chat Completions 和 Messages 共用
- 删除旧的 forwardChatCompletions 直传路径及相关死代码
2026-03-11 22:15:32 +08:00
CoolCoolTomato
fd8ccaf01a
fix: 修复gpt-5.2以上模型映射到gpt-5.2以下时verbosity参数引发的报错
2026-03-11 21:12:07 +08:00
ius
2fc6aaf936
Fix Codex exhausted snapshot propagation
2026-03-11 15:47:39 +08:00
ius
2694149489
Reduce DB write amplification on quota and account extra updates
2026-03-11 13:53:19 +08:00
7976723
656a77d585
feat: 添加 OpenAI Chat Completions 兼容端点
...
基于 @yulate 在 PR #648 (commit 0bb6a392) 的工作,解决了与最新
main 分支的合并冲突。
原始功能(@yulate):
- 添加 /v1/chat/completions 和 /chat/completions 兼容端点
- 将 Chat Completions 请求转换为 Responses API 格式并转换回来
- 添加 API Key 直连转发支持
- 包含单元测试
Co-authored-by: yulate <yulate@users.noreply.github.com >
2026-03-11 13:47:37 +08:00
kyx236
5fa22fdf82
fix: OpenAI临时性400错误支持池模式同账号重试 & HelpTooltip层级修复
...
1. 识别OpenAI "An error occurred while processing your request" 临时性400错误
并触发failover,同时在池模式下标记RetryableOnSameAccount,允许同账号重试
2. ForwardAsAnthropic路径同步支持临时性400错误的识别和同账号重试
3. HelpTooltip组件使用Teleport渲染到body,修复在dialog内被裁切的问题
2026-03-10 03:00:58 +08:00
shaw
a461538d58
fix: 修复gpt->claude转换无法命中codex缓存问题
2026-03-09 15:08:37 +08:00
Wesley Liddick
391e79f8ee
Merge pull request #875 from mt21625457/fix/openai-fast-billing-clean
...
fix(billing): 修复 OpenAI fast 档位计费并补齐展示
2026-03-09 10:32:18 +08:00
yangjianbo
87f4ed591e
fix(billing): 修复 OpenAI fast 档位计费并补齐展示
...
- 打通 service_tier 在 OpenAI HTTP、WS、passthrough 与 usage 记录中的传递
- 修正 priority/flex 计费逻辑,并将 fast 归一化为 priority
- 在用户端和管理端补齐服务档位与计费明细展示
- 补齐前后端测试,并修复 WS 限流信号重复持久化导致的全量回归失败
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-09 09:51:26 +08:00
Wesley Liddick
97aaa24733
Merge pull request #858 from james-6-23/fix/pool-mode-03bf3485
...
支持 API Key 上游池模式的同账号重试次数配置与自定义错误策略
2026-03-09 08:48:53 +08:00
kyx236
e643fc382c
feat: 支持 API Key 上游池模式同账号重试次数配置与自定义错误策略
2026-03-08 14:12:17 +08:00
神乐
1307d604e7
fix: 补齐旧账号的 OpenAI 限流补偿
2026-03-08 00:14:15 +08:00
神乐
45d57018eb
fix: 修复 OpenAI WS 限流状态与调度同步
2026-03-07 23:59:39 +08:00
神乐
101ef0cf62
fix: 限流账号自动退出调度并优化提示文案
2026-03-07 21:05:37 +08:00
Wesley Liddick
c2b14693b4
Merge pull request #835 from biubiutata/codex/fix-openai-originator-detection
...
fix(openai): 统一官方 Codex 客户端识别逻辑
2026-03-07 17:03:52 +08:00
admin
da89583ccc
fix(openai): detect official codex client by headers
2026-03-07 14:12:38 +08:00
shaw
ebd5253e22
fix: /response端点移除强制注入大量instructions内容
2026-03-07 13:39:47 +08:00
Wesley Liddick
f6709fb5d6
Merge pull request #824 from pkssssss/fix/ws-usage-window-pr
...
fix(openai): 修复 WS 模式下用量窗口不显示
2026-03-06 22:45:36 +08:00
shaw
921599948b
feat: /v1/messages端点适配codex账号池
2026-03-06 22:44:07 +08:00
神乐
dd25281305
chore(test): resolve merge conflict for ws usage window pr
2026-03-06 21:16:21 +08:00
神乐
838ada8864
fix(openai): restore ws usage window display
2026-03-06 20:49:47 +08:00
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
神乐
3403909354
fix(openai): support remote compact task
2026-03-06 18:51:05 +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
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
yangjianbo
1d0872e7ca
feat(openai-ws): 合并 WS v2 透传模式与前端 ws mode
...
新增 OpenAI WebSocket v2 passthrough relay 数据面与服务适配层,
支持按账号 ws mode 在 ctx_pool 与 passthrough 间路由。
同步调整前端 OpenAI ws mode 选项为 off/ctx_pool/passthrough,
并补充 i18n 文案与对应单测。
新增 Caddyfile.dmit 与 docker-compose-aicodex.yml 部署配置,
用于宿主机场景下的反向代理与服务编排。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-05 11:50:58 +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