mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-06 16:04:24 +00:00
- 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.
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package service
|
|
|
|
// imageCountBillingEnabled 表示该分组强制按实际出图张数计费,即使渠道是 token 计费。
|
|
func imageCountBillingEnabled(apiKey *APIKey) bool {
|
|
return apiKey != nil && apiKey.Group != nil && apiKey.Group.ImageCountBilling
|
|
}
|
|
|
|
// imageCountBillingApplies 判断分组按张计费开关是否作用于本次请求。
|
|
// 开关只影响专用图片端点;混合的 Responses/Chat/WS 请求即使带图片工具,
|
|
// 也必须保留 token 计费,避免整条请求被按图片单价结算而丢失文本 token 费用。
|
|
func imageCountBillingApplies(apiKey *APIKey, imageEndpoint bool) bool {
|
|
return imageEndpoint && imageCountBillingEnabled(apiKey)
|
|
}
|
|
|
|
func imagePriceConfigFromAPIKey(apiKey *APIKey) *ImagePriceConfig {
|
|
if apiKey == nil || apiKey.Group == nil {
|
|
return nil
|
|
}
|
|
return &ImagePriceConfig{
|
|
Price1K: apiKey.Group.ImagePrice1K,
|
|
Price2K: apiKey.Group.ImagePrice2K,
|
|
Price4K: apiKey.Group.ImagePrice4K,
|
|
}
|
|
}
|
|
|
|
func apiKeyHasConfiguredImagePrice(apiKey *APIKey, imageSize string) bool {
|
|
return apiKey != nil && apiKey.Group != nil && apiKey.Group.GetImagePrice(imageSize) != nil
|
|
}
|
|
|
|
func videoPriceConfigFromAPIKey(apiKey *APIKey) *VideoPriceConfig {
|
|
if apiKey == nil || apiKey.Group == nil {
|
|
return nil
|
|
}
|
|
return &VideoPriceConfig{
|
|
Price480P: apiKey.Group.VideoPrice480P,
|
|
Price720P: apiKey.Group.VideoPrice720P,
|
|
Price1080P: apiKey.Group.VideoPrice1080P,
|
|
ModelPrices: apiKey.Group.VideoModelPrices,
|
|
}
|
|
}
|
|
|
|
func apiKeyHasConfiguredVideoPrice(apiKey *APIKey, model, resolution string) bool {
|
|
return apiKey != nil && apiKey.Group != nil && apiKey.Group.GetVideoPriceForModel(model, resolution) != nil
|
|
}
|
|
|
|
func webSearchPricePerCallFromAPIKey(apiKey *APIKey) *float64 {
|
|
if apiKey == nil || apiKey.Group == nil {
|
|
return nil
|
|
}
|
|
return apiKey.Group.WebSearchPricePerCall
|
|
}
|
|
|
|
func groupSearchPricePer1kFromAPIKey(apiKey *APIKey) *float64 {
|
|
if apiKey == nil || apiKey.Group == nil {
|
|
return nil
|
|
}
|
|
return apiKey.Group.GetSearchPricePer1k()
|
|
}
|
|
|
|
func groupAudioPriceConfigFromAPIKey(apiKey *APIKey) *audioPriceConfig {
|
|
if apiKey == nil || apiKey.Group == nil {
|
|
return nil
|
|
}
|
|
g := apiKey.Group
|
|
return &audioPriceConfig{
|
|
RealtimePerMin: g.AudioRealtimePricePerMin,
|
|
TTSPerMChars: g.AudioTTSPricePerMillionChars,
|
|
STTPerHour: g.AudioSTTPricePerHour,
|
|
}
|
|
}
|