Skip to content

fix: restore pre-3400 OpenRouter billing semantics - #3438

Merged
Calcium-Ion merged 3 commits into
QuantumNous:mainfrom
seefs001:fix/openrouter-usage
Mar 25, 2026
Merged

fix: restore pre-3400 OpenRouter billing semantics#3438
Calcium-Ion merged 3 commits into
QuantumNous:mainfrom
seefs001:fix/openrouter-usage

Conversation

@seefs001

@seefs001 seefs001 commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

fix #3433

Summary by CodeRabbit

  • Tests

    • Added tests covering OpenRouter/Claude token billing, cached token handling, and quota calculations.
  • Bug Fixes

    • Corrected OpenRouter Claude billing so cached read/creation tokens and discount ratios are applied correctly to quotas.
  • Refactor

    • Response conversion now uses a shared helper to ensure usage and cache-related token counts are populated consistently.

@coderabbitai

coderabbitai Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 336b283a-0256-4bfe-9196-77d31a3293f4

📥 Commits

Reviewing files that changed from the base of the PR and between d4a470a and 926e178.

📒 Files selected for processing (1)
  • service/convert.go

Walkthrough

Introduced an explicit boolean (isOpenRouterClaudeBilling) to gate OpenRouter+Claude-specific billing adjustments in token quota calculation; updated conversion of OpenAI usage to Claude usage via a helper; added tests covering OpenRouter/Claude token billing semantics.

Changes

Cohort / File(s) Summary
Token Quota Billing Logic
service/text_quota.go
Added isOpenRouterClaudeBilling to combine the OpenRouter channel check with Claude semantic usage; guarded prompt token adjustments, cached-token subtraction, and possible recomputation of CacheCreationTokens with this condition.
Token Quota Tests
service/text_quota_test.go
Added OpenRouter-specific test cases validating prompt token/quota splits, cached read tokens, cached creation tokens, and Claude semantic behavior across relay formats.
Usage Conversion Helper
service/convert.go
Changed ResponseOpenAI2Claude to build Claude usage via buildClaudeUsageFromOpenAIUsage(&openAIResponse.Usage) to centralize population of usage fields (including cache-related tokens).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I nibble tokens, soft and bright,

OpenRouter and Claude in sight,
Cache and prompt now sort their dues,
Tests hop in to check the clues,
Hooray—billing bunnies dance tonight! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'fix: restore pre-3400 OpenRouter billing semantics' directly relates to the main change, which restores OpenRouter billing behavior by introducing a condition that combines OpenRouter channel detection with Claude usage semantics.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

上游为openrouter模型gpt5.4计费异常

2 participants