fix:sora异步API调用时扣费逻辑有误 - #2172
Conversation
WalkthroughExclude the "seconds" entry from multiplicative pricing factors and from quota-consumption log assembly in RelayTaskSubmit; added inline comments clarifying "seconds" is not part of billing multiplier. No public signatures changed. Changes
Sequence Diagram(s)(omitted — changes are local to a calculation and logging path, not control-flow or new interactions) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
relay/relay_task.go(5 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: 9Ninety
Repo: QuantumNous/new-api PR: 1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.
📚 Learning: 2025-06-21T03:37:41.726Z
Learnt from: 9Ninety
Repo: QuantumNous/new-api PR: 1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.
Applied to files:
relay/relay_task.go
📚 Learning: 2025-08-26T09:59:00.337Z
Learnt from: Sh1n3zZ
Repo: QuantumNous/new-api PR: 1659
File: relay/relay_task.go:285-305
Timestamp: 2025-08-26T09:59:00.337Z
Learning: In controller/task_video.go, the redactVideoResponseBody function sanitizes video task responses by removing bytesBase64Encoded fields and truncating base64 strings to 256 characters to prevent large binary data from being stored in task.Data.
Applied to files:
relay/relay_task.go
📚 Learning: 2025-08-26T09:59:00.337Z
Learnt from: Sh1n3zZ
Repo: QuantumNous/new-api PR: 1659
File: relay/relay_task.go:285-305
Timestamp: 2025-08-26T09:59:00.337Z
Learning: In controller/task_video.go, data: URLs (containing base64 encoded video data) are prevented from being stored in task.FailReason by checking if the URL starts with "data:" before assignment. This same pattern should be applied consistently across the codebase.
Applied to files:
relay/relay_task.go
🧬 Code graph analysis (1)
relay/relay_task.go (2)
types/price_data.go (1)
PriceData(11-27)constant/channel.go (1)
ChannelTypeVertexAi(41-41)
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
relay/relay_task.go (1)
171-174: Consider extracting the filtering logic to avoid duplication.The same "skip seconds" filtering logic appears in two places (lines 79-82 and here). This duplication creates a maintenance burden and risks inconsistency if the filtering rule changes.
Consider extracting a helper function:
// getMultiplierRatios returns OtherRatios excluding non-multiplier entries like "seconds" func getMultiplierRatios(otherRatios map[string]float64) map[string]float64 { result := make(map[string]float64) for key, value := range otherRatios { if key == "seconds" { continue } result[key] = value } return result }Then use it in both locations to ensure consistency.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
relay/relay_task.go(2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-06-21T03:37:41.726Z
Learnt from: 9Ninety
Repo: QuantumNous/new-api PR: 1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.
Applied to files:
relay/relay_task.go
📚 Learning: 2025-08-26T09:59:00.337Z
Learnt from: Sh1n3zZ
Repo: QuantumNous/new-api PR: 1659
File: relay/relay_task.go:285-305
Timestamp: 2025-08-26T09:59:00.337Z
Learning: In controller/task_video.go, data: URLs (containing base64 encoded video data) are prevented from being stored in task.FailReason by checking if the URL starts with "data:" before assignment. This same pattern should be applied consistently across the codebase.
Applied to files:
relay/relay_task.go
📚 Learning: 2025-08-26T09:59:00.337Z
Learnt from: Sh1n3zZ
Repo: QuantumNous/new-api PR: 1659
File: relay/relay_task.go:285-305
Timestamp: 2025-08-26T09:59:00.337Z
Learning: In controller/task_video.go, the redactVideoResponseBody function sanitizes video task responses by removing bytesBase64Encoded fields and truncating base64 strings to 256 characters to prevent large binary data from being stored in task.Data.
Applied to files:
relay/relay_task.go
🧬 Code graph analysis (1)
relay/relay_task.go (1)
types/price_data.go (1)
PriceData(11-27)
🔇 Additional comments (1)
relay/relay_task.go (1)
77-88: Verification complete: defensive filtering applied in all iteration paths.The patch correctly addresses the billing issue. All code paths that iterate over
OtherRatiosalready include the "seconds" filter (lines 79-82 and 170-173). Direct access patterns found inrelay_utils.goandali/adaptor.goare writes to the map, not reads that would bypass the filter.The architectural concern remains valid but optional: consider separating non-multiplier metadata (like "seconds") from the
OtherRatiosmap in a future refactor to improve clarity. For this PR, the fix is functionally correct and complete.
演练场chat聊天直接用的modelprice的按次 api调用算了otherratios的seconds
Summary by CodeRabbit