Skip to content

为Moonshot添加缓存tokens读取逻辑 - #2493

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
shikaiwei1:patch-1
Dec 24, 2025
Merged

为Moonshot添加缓存tokens读取逻辑#2493
seefs001 merged 1 commit into
QuantumNous:mainfrom
shikaiwei1:patch-1

Conversation

@shikaiwei1

@shikaiwei1 shikaiwei1 commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

为Moonshot添加缓存tokens读取逻辑。其与智普V4的逻辑相同,所以共用逻辑

Summary by CodeRabbit

  • Bug Fixes
    • Improved token usage reporting for specific API provider integrations with enhanced cached token metrics processing and robust fallback mechanisms that retrieve token data from multiple sources, ensuring precise usage tracking, accurate billing calculations, and better visibility into API resource consumption and associated costs.

✏️ Tip: You can customize this high-level summary in your review settings.

为Moonshot添加缓存tokens读取逻辑。其与智普V4的逻辑相同,所以共用逻辑
@coderabbitai

coderabbitai Bot commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The PR expands switch case handling in applyUsagePostProcessing to group ChannelTypeMoonshot with ChannelTypeZhipu_v4, implementing fallback logic to extract cached tokens from multiple sources when usage.PromptTokensDetails.CachedTokens is zero.

Changes

Cohort / File(s) Change Summary
Cached tokens handling expansion
relay/channel/openai/relay-openai.go
Grouped ChannelTypeMoonshot with ChannelTypeZhipu_v4 in switch case; added fallback chain to extract cached tokens from InputTokensDetails.CachedTokens, response body, or PromptCacheHitTokens when primary source is zero

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Attention points:
    • Verify the fallback precedence for cached token extraction is correct across all three sources
    • Confirm that grouping ChannelTypeMoonshot with ChannelTypeZhipu_v4 is appropriate and they share identical cached token handling requirements

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰 A moonshot aims for Zhipu's sky so bright,
With cached tokens stacked in fallback light,
When zeros appear, we seek deep and far,
Through fields and pools—a cached-token memoir! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding cached tokens reading logic for Moonshot channel type.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between afd9c29 and dbaba87.

📒 Files selected for processing (1)
  • relay/channel/openai/relay-openai.go
🧰 Additional context used
🧠 Learnings (1)
📚 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/channel/openai/relay-openai.go
🧬 Code graph analysis (1)
relay/channel/openai/relay-openai.go (1)
constant/channel.go (2)
  • ChannelTypeZhipu_v4 (30-30)
  • ChannelTypeMoonshot (29-29)
🔇 Additional comments (1)
relay/channel/openai/relay-openai.go (1)

599-608: Consolidate Moonshot cached token extraction with Zhipu V4 logic.

The change appropriately groups ChannelTypeMoonshot with ChannelTypeZhipu_v4 for cached token handling. Both APIs are OpenAI-compatible and the multi-source fallback strategy (InputTokensDetails → response body → PromptCacheHitTokens) robustly handles their response formats.


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.

@seefs001
seefs001 merged commit a0c3d37 into QuantumNous:main Dec 24, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
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