1. 07 Apr, 2026 3 commits
    • Elysia's avatar
      fix: 非流式响应路径扩展SSE检测至所有账号类型 (#1493) · 9e515ea7
      Elysia authored
      
      
      当上游返回SSE格式响应(如sub2api链路)时,API Key账号的非流式路径
      未检测SSE,导致终态事件中空output直接透传给客户端。
      
      - 将Content-Type SSE检测从仅OAuth扩展至所有账号类型
      - 重命名handleOAuthSSEToJSON为handleSSEToJSON(无OAuth专属逻辑)
      - 为透传路径新增handlePassthroughSSEToJSON,支持SSE转JSON及空output重建
      Co-Authored-By: default avatarClaude Opus 4.6 (1M context) <noreply@anthropic.com>
      9e515ea7
    • shaw's avatar
      fix: 非流式路径在上游终态事件output为空时从delta事件重建响应内容 · b2e379cf
      shaw authored
      上游API近期更新后,response.completed终态SSE事件的output字段可能为空,
      实际内容仅通过response.output_text.delta等增量事件下发。流式路径不受影响,
      但chat_completions非流式路径和responses OAuth非流式路径只依赖终态事件的
      output,导致返回空响应。
      
      新增BufferedResponseAccumulator累积器,在SSE扫描过程中收集delta事件内容
      (文本、function_call、reasoning),当终态output为空时补充重建。
      
      同时修复handleChatBufferedStreamingResponse遗漏response.done事件类型的问题。
      b2e379cf
    • Alex's avatar
      7eecc49c
  2. 05 Apr, 2026 1 commit
    • shaw's avatar
      fix(billing): prevent channel_mapped override from reverting BillingModel when channel did not map · f585a15e
      shaw authored
      When a channel has no model mapping for the requested model, ChannelMappedModel
      equals OriginalModel (the user's arbitrary input). Combined with the default
      BillingModelSource="channel_mapped", this incorrectly overrides the BillingModel
      set by the OpenAI format conversion layer (e.g., gpt-5.4 from DefaultMappedModel)
      back to the unmapped original model (e.g., glm) which has no pricing — resulting
      in zero-cost billing.
      
      Add guard condition so the channel_mapped override only fires when the channel
      actually changed the model (ChannelMappedModel != OriginalModel).
      f585a15e
  3. 04 Apr, 2026 15 commits
    • erio's avatar
      refactor: remove resolveOpenAIUpstreamModel, use normalizeCodexModel directly · e27b0adb
      erio authored
      Eliminates unnecessary indirection layer. The wrapper function only
      called normalizeCodexModel with a special case for "gpt 5.3 codex spark"
      (space-separated variant) that is no longer needed.
      
      All call sites now use normalizeCodexModel directly.
      e27b0adb
    • erio's avatar
      feat(channel): improve cache strategy and add restriction logging · 58f758c8
      erio authored
      - Change channel cache TTL from 60s to 10min (reduce unnecessary DB queries)
      - Actively rebuild cache after CRUD instead of lazy invalidation
      - Add slog.Warn logging for channel pricing restriction blocks (4 places)
      58f758c8
    • erio's avatar
      fix: resolve 5 audit findings in channel/credits/scheduling · 71f61bbc
      erio authored
      P0-1: Credits degraded response retry + fail-open
      - Add isAntigravityDegradedResponse() to detect transient API failures
      - Retry up to 3 times with exponential backoff (500ms/1s/2s)
      - Invalidate singleflight cache between retries
      - Fail-open after exhausting retries instead of 5h circuit break
      
      P1-1: Fix channel restriction pre-check timing conflict
      - Swap checkClaudeCodeRestriction before checkChannelPricingRestriction
      - Ensures channel restriction is checked against final fallback groupID
      
      P1-2: Add interval pricing validation (frontend + backend)
      - Backend: ValidateIntervals() with boundary, price, overlap checks
      - Frontend: validateIntervals() with Chinese error messages
      - Rules: MinTokens>=0, MaxTokens>MinTokens, prices>=0, no overlap
      
      P2: Fix cross-platform same-model pricing/mapping override
      - Store cache keys using original platform instead of group platform
      - Lookup across matching platforms (antigravity→anthropic→gemini)
      - Prevents anthropic/gemini same-name models from overwriting each other
      71f61bbc
    • erio's avatar
      fix: address review findings for channel restriction refactoring · 1fca2bfa
      erio authored
      - Fix 7 stale comments still mentioning "限制检查" in handlers/services
      - Make billingModelForRestriction explicitly list channel_mapped case
      - Add slog.Warn for error swallowing in ResolveChannelMapping and
        needsUpstreamChannelRestrictionCheck
      - Document sticky session upstream check exemption
      1fca2bfa
    • erio's avatar
      refactor: replace magic strings with named constants · 0d241d52
      erio authored
      - PricingSourceChannel/LiteLLM/Fallback for resolver source
      - MediaTypeImage/Video/Prompt for result.MediaType
      - Reuse BillingModeToken/BillingModeImage for billing mode
      - Reuse BillingModelSourceChannelMapped/PlatformAnthropic in handler
      0d241d52
    • erio's avatar
      fix: address audit findings - cache sync, validation, consistency · 9b213115
      erio authored
      - clearCreditsExhausted: sync Redis scheduler cache after DB update
      - Image billing mode UI: write to per_request_price instead of image_output_price
      - OpenAI RecordUsage: use BillingModelSourceRequested constant, add s.cfg nil guard
      - Fix i18n key path: admin.channels.perRequestPriceRequired → admin.channels.form.perRequestPriceRequired
      9b213115
    • erio's avatar
      fix: golangci-lint test assertion and gofmt · c9145ad4
      erio authored
      c9145ad4
    • erio's avatar
      fix: resolve golangci-lint issues · 3851628a
      erio authored
      - Fix errcheck: defer rows.Close() with nolint
      - Fix errcheck: type assertion with ok check in channel cache
      - Fix staticcheck ST1005: lowercase error string
      - Fix staticcheck SA5011: nil check cost before use in openai gateway
      - Fix gofmt: format chatcompletions_to_responses.go
      3851628a
    • erio's avatar
      feat: image output token billing, channel-mapped billing source, credits balance precheck · d72ac926
      erio authored
      - Parse candidatesTokensDetails from Gemini API to separate image/text output tokens
      - Add image_output_tokens and image_output_cost to usage_log (migration 089)
      - Support per-image-token pricing via output_cost_per_image_token from model pricing data
      - Channel pricing ImageOutputPrice override works in token billing mode
      - Auto-fill image_output_price in channel pricing form from model defaults
      - Add "channel_mapped" billing model source as new default (migration 088)
      - Bills by model name after channel mapping, before account mapping
      - Fix channel cache error TTL sign error (115s → 5s)
      - Fix Update channel only invalidating new groups, not removed groups
      - Fix frontend model_mapping clearing sending undefined instead of {}
      - Credits balance precheck via shared AccountUsageService cache before injection
      - Skip credits injection for accounts with insufficient balance
      - Don't mark credits exhausted for "exhausted your capacity on this model" 429s
      d72ac926
    • erio's avatar
      feat(channel): 渠道管理全链路集成 — 模型映射、定价、限制、用量统计 · 2555951b
      erio authored
      - 渠道模型映射:支持精确匹配和通配符映射,按平台隔离
      - 渠道模型定价:支持 token/按次/图片三种计费模式,区间分层定价
      - 模型限制:渠道可限制仅允许定价列表中的模型
      - 计费模型来源:支持 requested/upstream 两种计费模型选择
      - 用量统计:usage_logs 新增 channel_id/model_mapping_chain/billing_tier/billing_mode 字段
      - Dashboard 支持 model_source 维度(requested/upstream/mapping)查看模型统计
      - 全部 gateway handler 统一接入 ResolveChannelMappingAndRestrict
      - 修复测试:同步 SoraGenerationRepository 接口、SQL INSERT 参数、scan 字段
      2555951b
    • erio's avatar
      fix(channel): 全平台渠道映射覆盖 + 公共函数抽取 + 死代码清理 · eb385457
      erio authored
      - 4个缺失handler入口添加渠道映射+限制检查(ChatCompletions/Responses/Gemini)
      - 模型限制错误信息优化,区分"模型不可用"和"无账号"
      - OpenAI RecordUsage RequestedModel 改用 OriginalModel
      - ResolveChannelMappingAndRestrict/ReplaceModelInBody 抽取到 ChannelService 消除跨service重复
      - validateNoDuplicateModels 按 platform:model 去重
      - 删除 Channel.ResolveMappedModel 死代码和 CalculateCostWithChannel Deprecated方法
      - 移除冗余nil检查,抽取 validatePricingBillingMode 公共校验
      eb385457
    • erio's avatar
      refactor(channel): 抽取渠道映射公共函数 + OpenAI映射到body + 空响应修复 + 清理日志 · 4ea8b4cb
      erio authored
      - 抽取 ResolveChannelMappingAndRestrict 统一入口(5处→1个方法)
      - 抽取 BuildModelMappingChain 到 ChannelMappingResult 方法(5处→1行调用)
      - OpenAI 三入口 Forward 前应用渠道映射到请求体
      - OpenAI Responses/Messages 限制检查添加错误响应
      - 清理前端 3 处 console.log 调试日志
      4ea8b4cb
    • erio's avatar
      feat(channel): 通配符定价匹配 + OpenAI BillingModelSource + 按次价格校验 + 用户端计费模式展示 · 8d03c52e
      erio authored
      - 定价查找支持通配符(suffix *),最长前缀优先匹配
      - 模型限制(restrict_models)同样支持通配符匹配
      - OpenAI 网关接入渠道映射/BillingModelSource/模型限制
      - 按次/图片计费模式创建时强制要求价格或层级(前后端)
      - 用户使用记录列表增加计费模式 badge 列
      8d03c52e
    • erio's avatar
      feat(billing): 网关计费迁移到 CalculateCostUnified + 模型限制错误统一 · 632035aa
      erio authored
      - GatewayService/OpenAIGatewayService 注入 ModelPricingResolver
      - RecordUsage 从旧路径迁移到 CalculateCostUnified(支持 per_request/image 模式)
      - 无渠道时自动回退旧路径,保持原有行为
      - 长上下文双倍计费仅在无渠道定价时生效
      - CostBreakdown 新增 BillingMode 字段,使用日志记录实际计费模式
      - 模型限制错误改为与"无可用账号"相同的 503 响应
      632035aa
    • erio's avatar
      feat(usage): 使用记录增加计费模式字段 — 记录/展示/筛选 token/按次/图片 · a51e0047
      erio authored
      - DB: usage_logs 表新增 billing_mode VARCHAR(20) 列
      - 后端: RecordUsage 写入时根据 image_count 判定计费模式
      - 前端: 使用记录表格新增计费模式 badge 列 + 筛选下拉
      a51e0047
  4. 30 Mar, 2026 1 commit
  5. 28 Mar, 2026 1 commit
    • wucm667's avatar
      fix(billing): 计费始终使用用户请求的原始模型,而非映射后的上游模型 · f5764d8d
      wucm667 authored
      当账号配置了模型映射(如 claude-sonnet-4-6 → glm-5.0)时,系统错误地
      使用映射后的上游模型名计算费用。由于上游模型(如 glm-5.0)在定价系统中
      没有价格配置,导致计费失败后被静默置为 0,用户不被扣费。
      
      修改 forwardResultBillingModel 优先返回请求模型名,并移除 OpenAI 路径
      中 BillingModel 字段对计费模型的覆盖逻辑。
      f5764d8d
  6. 24 Mar, 2026 1 commit
  7. 23 Mar, 2026 1 commit
  8. 22 Mar, 2026 1 commit
  9. 20 Mar, 2026 1 commit
  10. 17 Mar, 2026 1 commit
    • Ethan0x0000's avatar
      feat(service): record upstream model across all gateway paths · 2e4ac88a
      Ethan0x0000 authored
      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.
      2e4ac88a
  11. 16 Mar, 2026 1 commit
    • QTom's avatar
      fix(gateway): 防止 OpenAI Codex 跨用户串流 · ab4e8b2c
      QTom authored
      根因:多个用户共享同一 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 头同步隔离
      ab4e8b2c
  12. 15 Mar, 2026 2 commits
    • erio's avatar
      feat(ops): add ignore insufficient balance errors toggle and extract error constants · cfe72159
      erio authored
      - 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
      cfe72159
    • Ethan0x0000's avatar
      feat: 完善使用记录端点可观测性与分布统计 · eefab159
      Ethan0x0000 authored
      将入站、上游与路径三类端点分布统一到使用记录页的一致化卡片交互中,并补齐端点元数据与统计链路,提升排障与流量分析效率。
      eefab159
  13. 14 Mar, 2026 1 commit
  14. 12 Mar, 2026 1 commit
  15. 11 Mar, 2026 6 commits
  16. 09 Mar, 2026 3 commits