Files
sub2api/backend/internal/service/image_billing_count.go
T
wx-11 aa1a1b11c8 fix(billing): gate per-image billing by endpoint and pricing mode
- Require per-request/image mode for group image pricing so token-mode
  group cards no longer settle images at $0.
- Force per-image billing for channel token pricing when the group switch
  is enabled, matching the OpenAI pipeline.
- Add an ImageEndpoint marker so the switch only applies to dedicated
  image endpoints; mixed Responses/Chat/WS requests keep token billing.
- Only fall back to one image when the switch is enabled, preserving the
  previous count semantics when it is off.
- Validate image_count_billing in GroupService and gate the admin
  checkbox on allow_image_generation.
- Bump the API key auth snapshot version for the new group field.
2026-10-24 18:56:31 +08:00

21 lines
653 B
Go

package service
// resolveBillableImageCount 决定一次图片请求按几张计费。
//
// 官方多图响应没有 n 字段,只以响应体 data/output 中实际返回的图片为准。
// 解析不到张数时:
// - 分组开启按张计费:按 1 张兜底,避免已成功出图的请求完全漏计;
// - 未开启:保持原口径(流式 0 张、非流式回退请求 n),不能因为开关之外的原因多扣。
func resolveBillableImageCount(reported, requested int, fallbackToOne bool) int {
if reported > 0 {
return reported
}
if fallbackToOne {
return 1
}
if requested > 0 {
return requested
}
return 0
}