Skip to content

fix:sora异步API调用时扣费逻辑有误 - #2172

Closed
Andras5014 wants to merge 2 commits into
QuantumNous:mainfrom
Andras5014:fix/#2169
Closed

fix:sora异步API调用时扣费逻辑有误#2172
Andras5014 wants to merge 2 commits into
QuantumNous:mainfrom
Andras5014:fix/#2169

Conversation

@Andras5014

@Andras5014 Andras5014 commented Nov 5, 2025

Copy link
Copy Markdown

演练场chat聊天直接用的modelprice的按次 api调用算了otherratios的seconds

Summary by CodeRabbit

  • Changes
    • Refined pricing calculation to exclude non-billed time entries from ratio multipliers, improving billing accuracy.
    • Improved quota consumption logging to omit non-billed time from logged calculation details for clearer reports.
    • Enhanced consistency between billing computations and quota logs to reduce discrepancies and improve observability.

@coderabbitai

coderabbitai Bot commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Exclude 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

Cohort / File(s) Summary
Billing multiplier and logging
relay/relay_task.go
In RelayTaskSubmit, skip the "seconds" key when computing the final price ratio (exclude it from multiplicative factors) and omit "seconds" from the assembled quota-consumption log parameters; added clarifying inline comments.

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

  • Focus review on the ratio computation loop and the logging assembly in relay/relay_task.go to ensure "seconds" is correctly excluded in all paths and comments match behavior.

Possibly related issues

Possibly related PRs

  • task_relay_info #1656 — Related edits to relay/relay_task.go and RelayTaskSubmit; may overlap at call-site or data propagation.

Suggested reviewers

  • creamlike1024

Poem

🐰 I nibbled code under moonlit beams,
Skipped "seconds" from the billing streams,
Multiplier trimmed, logs made neat,
Tiny hops make charges meet —
A rabbit's fix, all tidy and sweet. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title is in Chinese and refers to fixing billing logic for Sora asynchronous API calls. The changes in relay_task.go specifically exclude 'seconds' from billing multiplier calculations, which directly addresses the stated billing issue.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29e70ac and 293da66.

📒 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)

Comment thread relay/relay_task.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 293da66 and 955c7f3.

📒 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 OtherRatios already include the "seconds" filter (lines 79-82 and 170-173). Direct access patterns found in relay_utils.go and ali/adaptor.go are 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 OtherRatios map in a future refactor to improve clarity. For this PR, the fix is functionally correct and complete.

@Calcium-Ion

Copy link
Copy Markdown
Member

扣费逻辑没有问题
想按次数计费看这个https://github.com/QuantumNous/new-api/releases/tag/v0.9.9-patch.3

@Calcium-Ion Calcium-Ion closed this Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants