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

+8
View File
@@ -940,6 +940,14 @@ func (s *Service) EnrichAPICallLog(log *model.ApiCallLog, responseBody []byte) {
log.UsageAvailable = true
log.InputTokens = firstInt64(usage, "input_tokens", "prompt_tokens")
log.OutputTokens = firstInt64(usage, "output_tokens", "completion_tokens")
// 火山方舟视频的输入 Token 恒为 0;查询任务以 completion_tokens 为实际用量,
// 兼容只返回 total_tokens 的同协议中转实现。
if log.Capability == "video" && strings.Contains(log.Path, "/contents/generations/tasks") && log.OutputTokens == 0 {
log.OutputTokens = firstInt64(usage, "total_tokens")
}
if log.Capability == "video" && strings.Contains(log.Path, "/contents/generations/tasks") && log.OutputTokens <= 0 {
log.UsageAvailable = false
}
if details, ok := usage["input_tokens_details"].(map[string]any); ok {
log.CachedTokens = firstInt64(details, "cached_tokens")
}