feat(billing): 火山方舟视频计费 - 支持真实 Token 预授权与结算

Refs #228

Co-authored-by: MasterChiefCN <49179444+MasterChiefCN@users.noreply.github.com>
This commit is contained in:
ddCatandMasterChiefCN committed 2026-08-15 12:58:05 +08:00
1 parent 476348a322
commit b2a7eef35d
11 files changed
+362 -36

No files matched your search

+9 -2
View File
@@ -152,8 +152,8 @@ func (s *Service) SaveAdminChannelModel(actor *model.User, channelID string, id
if billingMode == "per_second" && capability != "video" {
return nil, BadAuthRequest("只有视频模型可以按秒计费")
}
if billingMode == "token" && capability != "text" {
return nil, BadAuthRequest("只有文本模型可以按 Token 计费")
if billingMode == "token" && !supportsTokenBilling(capability, protocol) {
return nil, BadAuthRequest("Token 计费仅支持文本模型和火山方舟视频协议")
}
if req.UnitPriceMicrocredits < 0 || req.InputTokenPriceMicrocredits < 0 || req.OutputTokenPriceMicrocredits < 0 || req.CachedTokenPriceMicrocredits < 0 {
return nil, BadAuthRequest("模型积分价格不能小于 0")
@@ -161,6 +161,9 @@ func (s *Service) SaveAdminChannelModel(actor *model.User, channelID string, id
if billingMode == "token" && req.InputTokenPriceMicrocredits == 0 && req.OutputTokenPriceMicrocredits == 0 && req.CachedTokenPriceMicrocredits == 0 {
return nil, BadAuthRequest("Token 计费至少需要配置一项价格")
}
if billingMode == "token" && capability == "video" && req.OutputTokenPriceMicrocredits == 0 {
return nil, BadAuthRequest("火山方舟视频 Token 计费需要配置每百万视频 Token 价格")
}
const maxTokenPriceMicrocredits = int64(1_000_000) * CreditScale
if req.InputTokenPriceMicrocredits > maxTokenPriceMicrocredits || req.OutputTokenPriceMicrocredits > maxTokenPriceMicrocredits || req.CachedTokenPriceMicrocredits > maxTokenPriceMicrocredits {
return nil, BadAuthRequest("Token 每百万用量价格不能超过 1,000,000 积分")
@@ -222,6 +225,10 @@ func (s *Service) SaveAdminChannelModel(actor *model.User, channelID string, id
return item, nil
}
func supportsTokenBilling(capability string, protocol model.ChannelInterfaceType) bool {
return capability == "text" || (capability == "video" && protocol == model.ChannelInterfaceVolcengineArkVideo)
}
func (s *Service) TestAdminChannelModel(ctx context.Context, actor *model.User, channelID string, req ChannelModelRequest) (*AdminChannelModelTestResult, error) {
if err := s.RequireAdmin(actor); err != nil {
return nil, err