Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions model/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"database/sql/driver"
"encoding/json"
"strconv"
"time"

"github.com/QuantumNous/new-api/common"
Expand Down Expand Up @@ -531,5 +532,11 @@ func (t *Task) ToOpenAIVideo() *dto.OpenAIVideo {
openAIVideo.CreatedAt = t.CreatedAt
openAIVideo.CompletedAt = t.UpdatedAt
openAIVideo.SetMetadata("url", t.GetResultURL())
// 按秒计费的时长(OtherRatios["seconds"])统一带出,供下游按秒计费
if bc := t.PrivateData.BillingContext; bc != nil {
if s, ok := bc.OtherRatios["seconds"]; ok && s > 0 {
openAIVideo.Seconds = strconv.Itoa(int(s))
}
}
return openAIVideo
}
9 changes: 9 additions & 0 deletions relay/relay_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ func videoFetchByIDRespBodyBuilder(c *gin.Context) (respBody []byte, taskResp *d
taskResp = service.TaskErrorWrapper(err, "convert_to_openai_video_failed", http.StatusInternalServerError)
return
}
// 计量经 header 透传给下游(中转套娃),保持 body 为纯 OpenAI 标准结构
if ti, perr := adaptor.ParseTaskResult(originTask.Data); perr == nil && ti != nil && ti.TotalTokens > 0 {
if usageJSON, merr := common.Marshal(map[string]int{
"completion_tokens": ti.CompletionTokens,
"total_tokens": ti.TotalTokens,
}); merr == nil {
c.Header("X-New-Api-Usage", string(usageJSON))
}
}
respBody = openAIVideoData
return
}
Expand Down