feat: expose video task billing usage (token via header, seconds in body) - #5831
feat: expose video task billing usage (token via header, seconds in body)#5831feitianbubu wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe OpenAI video response path now adds upstream usage data to a response header and includes billing-derived seconds in the converted video payload when available. ChangesVideo response enrichment
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
移植上游 PR QuantumNous#6173(异步视频输出 Token 计费)与 QuantumNous#5831(计量外露)。 QuantumNous#6173:RecalculateTaskQuotaByTokens 此前把 totalTokens 整体按模型倍率 计价,输出 token 未乘补全倍率。现新增 completionTokens 入参,按 input + completion×completionRatio 计价;倍率优先取任务提交时的 BillingContext 快照而非当前配置,避免中途改价影响在途任务。 TaskBillingContext 新增 CompletionRatio(指针,兼容未保存该字段的历史 任务);未配置补全倍率的模型默认取 1,与旧行为等价。 QuantumNous#5831:任务计量经 X-New-Api-Usage 响应头透传给下游(中转套娃场景), body 保持纯 OpenAI 结构;ToOpenAIVideo 带出按秒计费的时长。 一处加固:OtherRatios["seconds"] 读自数据库,历史记录可能写于尚无时长 上界校验的版本,转 int 前先钳到 MaxTaskDurationSeconds——超出 int 范围的 float64 转换结果是未定义的。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
51fdfc5 to
2b6f1df
Compare
📝 变更描述 / Description
向视频任务查询接口的输出补充计费计量信息,方便下游(含中转/网关场景)据此计费。分两类:
1. 按量(token)计费 → 响应头
X-New-Api-Usage在
GET /v1/videos/{task_id}响应上新增响应头,携带任务 token 用量:ParseTaskResult能解析出total_tokens > 0时设置。2. 按秒计费 → 响应体标准字段
secondsToOpenAIVideo统一将计费所用时长(BillingContext.OtherRatios["seconds"],即实际计费依据)写入标准的seconds字段:{ "model": "...", "status": "completed", "seconds": "5", ... }seconds是 OpenAI 视频对象的标准字段,不污染结构。seconds倍率)不受影响。两处均为纯增量,不改变任何现有计费/响应逻辑;普通客户端忽略即可。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
go build ./...通过。📸 运行证明 / Proof of Work
X-New-Api-Usage: {"completion_tokens":1234,"total_tokens":1234}。"seconds": "5",与实际计费时长一致。Summary by CodeRabbit