Skip to content

refactor: optimize billing flow for OpenAI-to-Anthropic convert - #3400

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/openai-usage
Mar 23, 2026
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/openai-usage

Conversation

@seefs001

@seefs001 seefs001 commented Mar 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • Refactor

    • Consolidated quota consumption logic for text-based requests into a unified service function, improving consistency across audio, image, embedding, and chat handlers.
    • Enhanced usage metadata tracking with semantic attribution (identifying request sources) and improved cached token accounting with support for detailed cache-creation token breakdowns.
  • Tests

    • Added comprehensive unit tests validating text quota calculation, cache token handling, and usage semantic attribution.

@coderabbitai

coderabbitai Bot commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request consolidates quota consumption and billing logic across multiple API handlers by introducing a centralized PostTextConsumeQuota service function, replacing scattered local implementations. It adds semantic metadata to track usage origins (e.g., "anthropic" vs "openai"), implements Claude-to-OpenAI usage transformation for compatibility, and removes the Claude-specific PostClaudeConsumeQuota function. The changes unify quota calculation across text, embedding, image, audio, and gemini handlers while preserving model-specific token accounting.

Changes

Cohort / File(s) Summary
DTO Enhancements
dto/openai_response.go
Added UsageSemantic and UsageSource optional string fields to Usage struct; modified CachedCreationTokens JSON serialization from excluded to included when non-empty.
Handler Quota Consolidation
relay/audio_handler.go, relay/embedding_handler.go, relay/gemini_handler.go, relay/image_handler.go, relay/rerank_handler.go, relay/responses_handler.go
Replaced local postConsumeQuota calls with service.PostTextConsumeQuota, passing an additional nil argument and routing quota handling through centralized service logic.
Claude Handler Update
relay/claude_handler.go
Changed quota-consumption call from PostClaudeConsumeQuota to PostTextConsumeQuota in both execution paths, adding explicit nil parameter.
Compatible Handler Refactor
relay/compatible_handler.go
Removed 291-line local postConsumeQuota implementation and its dependencies; replaced all call sites with service.PostTextConsumeQuota.
Claude Relay Usage Transformation
relay/channel/claude/relay-claude.go
Added helpers cacheCreationTokensForOpenAIUsage and buildOpenAIStyleUsageFromClaudeUsage to compute unified cache-creation counts and transform Claude usage into OpenAI-style format with semantic metadata; set UsageSemantic="anthropic" throughout Claude response handling; updated OpenAI-formatted outputs to use transformed usage.
Claude Relay Tests
relay/channel/claude/relay_claude_test.go
Added two unit tests validating buildOpenAIStyleUsageFromClaudeUsage behavior, including cache-creation token aggregation and fallback logic.
Service Quota Core Logic
service/text_quota.go
New 427-line module implementing centralized text quota calculation via calculateTextQuotaSummary and public PostTextConsumeQuota function; handles token-based quota with decimal arithmetic, cache/cache-creation token tracking, multi-model pricing ratios, special token types (search, tools, audio, image), semantic classification, and billing settlement.
Service Quota Tests
service/text_quota_test.go
Added 206 lines of unit tests validating calculateTextQuotaSummary across scenarios: Claude cache-creation ratios, split 5m/1h token handling, usage semantic sourcing, cache write totals, and legacy Claude-derived OpenAI usage.
Service Quota Removal
service/quota.go
Removed 102-line PostClaudeConsumeQuota function and its control flow for quota computation, billing settlement, and consume-log recording.
Service Conversion Helpers
service/convert.go
Added buildClaudeUsageFromOpenAIUsage helper to convert OpenAI usage into Claude usage format; replaced inline dto.ClaudeUsage constructions in StreamResponseOpenAI2Claude with calls to this helper.
Service Logging Enhancement
service/log_info_generate.go
Added appendFinalRequestFormat helper to detect and record when final upstream request format is Claude, setting other["claude"]=true for frontend log rendering.

Sequence Diagram(s)

sequenceDiagram
    participant Handler as Request Handler
    participant Service as service.PostTextConsumeQuota
    participant Calc as calculateTextQuotaSummary
    participant Billing as SettleBilling
    participant Log as RecordConsumeLog

    Handler->>Service: PostTextConsumeQuota(ctx, relayInfo, usage, extraContent)
    Service->>Calc: calculateTextQuotaSummary(relayInfo, usage, duration)
    Note over Calc: Extract tokens, apply pricing ratios,<br/>compute cache/cache-creation,<br/>handle special token types
    Calc-->>Service: textQuotaSummary (with computed Quota)
    
    alt TotalTokens == 0
        Service-->>Handler: Error (no tokens to consume)
    else Quota valid
        Service->>Service: Update user/channel quota
        Service->>Billing: SettleBilling(...)
        Service->>Log: RecordConsumeLog(other metadata)
        Service-->>Handler: Success
    end
Loading
sequenceDiagram
    participant ClaudeRelay as Claude Relay Handler
    participant Transform as buildOpenAIStyleUsageFromClaudeUsage
    participant TextQuota as PostTextConsumeQuota
    participant Output as OpenAI Response Builder

    ClaudeRelay->>ClaudeRelay: Receive Claude response<br/>(set UsageSemantic="anthropic")
    ClaudeRelay->>Transform: Transform Claude usage to OpenAI format
    Note over Transform: Compute cache creation tokens,<br/>combine input + cache tokens,<br/>set UsageSemantic="openai",<br/>UsageSource="anthropic"
    Transform-->>ClaudeRelay: OpenAI-style Usage
    ClaudeRelay->>TextQuota: PostTextConsumeQuota with transformed usage
    Note over TextQuota: Calculate quota with<br/>semantic metadata
    TextQuota-->>ClaudeRelay: Quota settled
    ClaudeRelay->>Output: Build response with transformed usage
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • creamlike1024

Poem

🐰 Through tokens and cache, a rabbit hops free,
Consolidating quotas for all to see,
Claude becomes OpenAI with semantic grace,
One billing path forward, a unified place! 🎉
Where 5m and 1h cache dance in sync,
And consumption logs capture each blink.

🚥 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 'refactor: optimize billing flow for OpenAI-to-Anthropic convert' accurately summarizes the main change—a significant refactoring of billing/quota handling across multiple relay handlers to use a unified service function and conversion logic.

✏️ 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.

@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: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@relay/audio_handler.go`:
- Around line 70-73: The audio billing branch should only call
service.PostAudioConsumeQuota when the model actually has audio-specific ratios
configured; update the existing conditional that checks
usage.(*dto.Usage).CompletionTokenDetails.AudioTokens and
PromptTokens.AudioTokens to also require the same "model has audio ratios" guard
used in relay/compatible_handler.go (i.e., the check that inspects the
model/info for audio ratio configuration) so that
service.PostAudioConsumeQuota(c, info, usage.(*dto.Usage), "") is only invoked
when audio ratios are configured; otherwise call service.PostTextConsumeQuota as
before.

In `@relay/channel/claude/relay-claude.go`:
- Around line 856-860: The code in the RelayFormatOpenAI branch uses
encoding/json.Marshal directly; replace that call with the project JSON wrapper
common.Marshal to comply with JSON marshaling guidelines. Locate the block where
openaiResponse is created (ResponseClaude2OpenAI,
buildOpenAIStyleUsageFromClaudeUsage, claudeResponse/claudeInfo) and change
json.Marshal(openaiResponse) to common.Marshal(openaiResponse), handling the
returned bytes and error the same way.

In `@service/text_quota.go`:
- Around line 98-108: The current code fabricates a dto.Usage when usage == nil
using relayInfo.GetEstimatePromptTokens(), which causes summary.TotalTokens to
be non-zero and allows quota deduction; instead, do not synthesize billable
usage—only populate summary.PromptTokens, summary.CompletionTokens and
summary.TotalTokens from usage when usage != nil (i.e., gate on
usage.TotalTokens), and when usage is nil set summary fields to zero (or leave
nil) so upstream "no usage" remains non-billable; update the logic around usage,
dto.Usage, relayInfo.GetEstimatePromptTokens(), and summary.TotalTokens so the
zero-charge branch (lines referenced around 319-325) remains reachable.
- Around line 117-127: The OpenRouter branch is subtracting cache hit/write
tokens from summary.PromptTokens but those same tokens are subtracted again
later, causing underbilling; modify the OpenRouter block in
service/text_quota.go to avoid double-deduction by adding a guard (e.g., a
boolean on the summary like CacheNormalizationDone or CacheAdjusted) and only
apply the two subtractions (summary.PromptTokens -= summary.CacheTokens and
summary.PromptTokens -= summary.CacheCreationTokens) when that guard is false,
setting it true after adjusting; reference the existing symbols
relayInfo.ChannelMeta, relayInfo.ChannelType, constant.ChannelTypeOpenRouter,
summary.PromptTokens, summary.CacheTokens, summary.CacheCreationTokens,
CalcOpenRouterCacheCreateTokens and hasCustomModelRatio to locate and update the
logic so the generic OpenAI path (lines ~198-218) can perform the single
canonical subtraction.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4b67d267-1533-400c-9e0a-8dfca8f713d7

📥 Commits

Reviewing files that changed from the base of the PR and between deff59a and 9ecad90.

📒 Files selected for processing (16)
  • dto/openai_response.go
  • relay/audio_handler.go
  • relay/channel/claude/relay-claude.go
  • relay/channel/claude/relay_claude_test.go
  • relay/claude_handler.go
  • relay/compatible_handler.go
  • relay/embedding_handler.go
  • relay/gemini_handler.go
  • relay/image_handler.go
  • relay/rerank_handler.go
  • relay/responses_handler.go
  • service/convert.go
  • service/log_info_generate.go
  • service/quota.go
  • service/text_quota.go
  • service/text_quota_test.go
💤 Files with no reviewable changes (1)
  • service/quota.go

Comment thread relay/audio_handler.go
Comment on lines 70 to +73
if usage.(*dto.Usage).CompletionTokenDetails.AudioTokens > 0 || usage.(*dto.Usage).PromptTokensDetails.AudioTokens > 0 {
service.PostAudioConsumeQuota(c, info, usage.(*dto.Usage), "")
} else {
postConsumeQuota(c, info, usage.(*dto.Usage))
service.PostTextConsumeQuota(c, info, usage.(*dto.Usage), nil)

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.

⚠️ Potential issue | 🟠 Major

Gate audio billing on configured audio ratios here too.

This still diverges from relay/compatible_handler.go:80-92, which only routes to PostAudioConsumeQuota when the model actually has audio ratios configured. Without the same guard, the dedicated audio path can classify the same usage differently and misprice models that emit AudioTokens but have no audio-specific ratio entry.

💡 Proposed fix
 import (
 	"errors"
 	"fmt"
 	"net/http"
 
 	"github.com/QuantumNous/new-api/common"
 	"github.com/QuantumNous/new-api/dto"
 	relaycommon "github.com/QuantumNous/new-api/relay/common"
 	"github.com/QuantumNous/new-api/relay/helper"
 	"github.com/QuantumNous/new-api/service"
+	"github.com/QuantumNous/new-api/setting/ratio_setting"
 	"github.com/QuantumNous/new-api/types"
 
 	"github.com/gin-gonic/gin"
 )
@@
-	if usage.(*dto.Usage).CompletionTokenDetails.AudioTokens > 0 || usage.(*dto.Usage).PromptTokensDetails.AudioTokens > 0 {
-		service.PostAudioConsumeQuota(c, info, usage.(*dto.Usage), "")
+	usageDto := usage.(*dto.Usage)
+	containAudioTokens := usageDto.CompletionTokenDetails.AudioTokens > 0 || usageDto.PromptTokensDetails.AudioTokens > 0
+	containsAudioRatios := ratio_setting.ContainsAudioRatio(info.OriginModelName) || ratio_setting.ContainsAudioCompletionRatio(info.OriginModelName)
+	if containAudioTokens && containsAudioRatios {
+		service.PostAudioConsumeQuota(c, info, usageDto, "")
 	} else {
-		service.PostTextConsumeQuota(c, info, usage.(*dto.Usage), nil)
+		service.PostTextConsumeQuota(c, info, usageDto, nil)
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@relay/audio_handler.go` around lines 70 - 73, The audio billing branch should
only call service.PostAudioConsumeQuota when the model actually has
audio-specific ratios configured; update the existing conditional that checks
usage.(*dto.Usage).CompletionTokenDetails.AudioTokens and
PromptTokens.AudioTokens to also require the same "model has audio ratios" guard
used in relay/compatible_handler.go (i.e., the check that inspects the
model/info for audio ratio configuration) so that
service.PostAudioConsumeQuota(c, info, usage.(*dto.Usage), "") is only invoked
when audio ratios are configured; otherwise call service.PostTextConsumeQuota as
before.

Comment on lines 856 to 860
case types.RelayFormatOpenAI:
openaiResponse := ResponseClaude2OpenAI(&claudeResponse)
openaiResponse.Usage = *claudeInfo.Usage
openaiResponse.Usage = buildOpenAIStyleUsageFromClaudeUsage(claudeInfo.Usage)
responseData, err = json.Marshal(openaiResponse)
if err != nil {

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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, check the file exists and see the target lines
wc -l relay/channel/claude/relay-claude.go

Repository: QuantumNous/new-api

Length of output: 103


🏁 Script executed:

# Read lines 856-870 to see the exact code
sed -n '856,870p' relay/channel/claude/relay-claude.go

Repository: QuantumNous/new-api

Length of output: 659


🏁 Script executed:

# Check the imports at the top of the file to see what's currently imported
head -50 relay/channel/claude/relay-claude.go | grep -E "^import|encoding/json|common"

Repository: QuantumNous/new-api

Length of output: 282


🏁 Script executed:

# Search for all json.Marshal usages in this file
rg 'json\.Marshal|json\.Unmarshal|json\.NewDecoder|json\.NewEncoder' relay/channel/claude/relay-claude.go -n

Repository: QuantumNous/new-api

Length of output: 366


🏁 Script executed:

# Check if common.Marshal is imported or available
rg 'common\.' relay/channel/claude/relay-claude.go | head -20

Repository: QuantumNous/new-api

Length of output: 1336


🏁 Script executed:

# Verify common.Marshal exists in common/json.go
fd common/json.go --exec grep -l 'func Marshal' {} \;

Repository: QuantumNous/new-api

Length of output: 45


🏁 Script executed:

# Confirm common.Marshal is exported and available
rg 'func Marshal' common/json.go -A 2

Repository: QuantumNous/new-api

Length of output: 126


Replace json.Marshal with common.Marshal.

The touched code at line 859 directly calls encoding/json.Marshal() instead of using the common.Marshal() wrapper required by the JSON marshaling guidelines.

Suggested fix
-		responseData, err = json.Marshal(openaiResponse)
+		responseData, err = common.Marshal(openaiResponse)

All JSON marshal/unmarshal operations in business code must use wrapper functions from common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType). Do not directly call encoding/json.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case types.RelayFormatOpenAI:
openaiResponse := ResponseClaude2OpenAI(&claudeResponse)
openaiResponse.Usage = *claudeInfo.Usage
openaiResponse.Usage = buildOpenAIStyleUsageFromClaudeUsage(claudeInfo.Usage)
responseData, err = json.Marshal(openaiResponse)
if err != nil {
case types.RelayFormatOpenAI:
openaiResponse := ResponseClaude2OpenAI(&claudeResponse)
openaiResponse.Usage = buildOpenAIStyleUsageFromClaudeUsage(claudeInfo.Usage)
responseData, err = common.Marshal(openaiResponse)
if err != nil {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@relay/channel/claude/relay-claude.go` around lines 856 - 860, The code in the
RelayFormatOpenAI branch uses encoding/json.Marshal directly; replace that call
with the project JSON wrapper common.Marshal to comply with JSON marshaling
guidelines. Locate the block where openaiResponse is created
(ResponseClaude2OpenAI, buildOpenAIStyleUsageFromClaudeUsage,
claudeResponse/claudeInfo) and change json.Marshal(openaiResponse) to
common.Marshal(openaiResponse), handling the returned bytes and error the same
way.

Comment thread service/text_quota.go
Comment on lines +98 to +108
if usage == nil {
usage = &dto.Usage{
PromptTokens: relayInfo.GetEstimatePromptTokens(),
CompletionTokens: 0,
TotalTokens: relayInfo.GetEstimatePromptTokens(),
}
}

summary.PromptTokens = usage.PromptTokens
summary.CompletionTokens = usage.CompletionTokens
summary.TotalTokens = usage.PromptTokens + usage.CompletionTokens

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.

⚠️ Potential issue | 🟠 Major

Do not turn missing usage into billable quota.

usage == nil is converted into an estimated prompt-only payload, and summary.TotalTokens is then recomputed from PromptTokens + CompletionTokens. That makes the zero-charge branch at Lines 319-325 unreachable for the exact "上游无计费信息" path, so requests with no upstream usage can still deduct quota. Synthetic billing should stay at the caller; this helper should gate billing off upstream usage.TotalTokens.

Also applies to: 319-325

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@service/text_quota.go` around lines 98 - 108, The current code fabricates a
dto.Usage when usage == nil using relayInfo.GetEstimatePromptTokens(), which
causes summary.TotalTokens to be non-zero and allows quota deduction; instead,
do not synthesize billable usage—only populate summary.PromptTokens,
summary.CompletionTokens and summary.TotalTokens from usage when usage != nil
(i.e., gate on usage.TotalTokens), and when usage is nil set summary fields to
zero (or leave nil) so upstream "no usage" remains non-billable; update the
logic around usage, dto.Usage, relayInfo.GetEstimatePromptTokens(), and
summary.TotalTokens so the zero-charge branch (lines referenced around 319-325)
remains reachable.

Comment thread service/text_quota.go
Comment on lines +117 to +127
if relayInfo.ChannelMeta != nil && relayInfo.ChannelType == constant.ChannelTypeOpenRouter {
summary.PromptTokens -= summary.CacheTokens
isUsingCustomSettings := relayInfo.PriceData.UsePrice || hasCustomModelRatio(summary.ModelName, relayInfo.PriceData.ModelRatio)
if summary.CacheCreationTokens == 0 && relayInfo.PriceData.CacheCreationRatio != 1 && usage.Cost != 0 && !isUsingCustomSettings {
maybeCacheCreationTokens := CalcOpenRouterCacheCreateTokens(*usage, relayInfo.PriceData)
if maybeCacheCreationTokens >= 0 && summary.PromptTokens >= maybeCacheCreationTokens {
summary.CacheCreationTokens = maybeCacheCreationTokens
}
}
summary.PromptTokens -= summary.CacheCreationTokens
}

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.

⚠️ Potential issue | 🟠 Major

OpenRouter cache buckets are deducted twice.

Lines 117-127 already strip cache hit/write tokens from summary.PromptTokens. Lines 198-218 subtract summary.CacheTokens and summary.CacheCreationTokens again before applying the discounted ratios, so cached OpenRouter requests underbill. This needs an "already normalized" guard here, or summary.PromptTokens should stay raw and let the generic OpenAI path do the subtraction once.

Also applies to: 198-218

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@service/text_quota.go` around lines 117 - 127, The OpenRouter branch is
subtracting cache hit/write tokens from summary.PromptTokens but those same
tokens are subtracted again later, causing underbilling; modify the OpenRouter
block in service/text_quota.go to avoid double-deduction by adding a guard
(e.g., a boolean on the summary like CacheNormalizationDone or CacheAdjusted)
and only apply the two subtractions (summary.PromptTokens -= summary.CacheTokens
and summary.PromptTokens -= summary.CacheCreationTokens) when that guard is
false, setting it true after adjusting; reference the existing symbols
relayInfo.ChannelMeta, relayInfo.ChannelType, constant.ChannelTypeOpenRouter,
summary.PromptTokens, summary.CacheTokens, summary.CacheCreationTokens,
CalcOpenRouterCacheCreateTokens and hasCustomModelRatio to locate and update the
logic so the generic OpenAI path (lines ~198-218) can perform the single
canonical subtraction.

@Calcium-Ion
Calcium-Ion merged commit 0191a68 into QuantumNous:main Mar 23, 2026
1 check passed
RoodraNambisa added a commit to RoodraNambisa/new-api that referenced this pull request Mar 24, 2026
commit dbf900a
Author: CaIon <i@caion.me>
Date:   Wed Mar 25 00:04:01 2026 +0800

    fix: restore doubao coding plan deprecation and regex ignored models lost during conflict resolution

commit 7399e47
Author: CaIon <i@caion.me>
Date:   Tue Mar 24 23:56:10 2026 +0800

    feat: add slide-in animations and update translations for new UI elements

    # Conflicts:
    #	web/src/components/table/channels/modals/EditChannelModal.jsx

commit a5e2026
Author: CaIon <i@caion.me>
Date:   Tue Mar 24 23:53:50 2026 +0800

    security: harden Docker and release CI workflows

    - Pin all GitHub Actions to commit SHA to prevent supply chain attacks
    - Enable SLSA provenance attestation (mode=max) and SBOM generation
    - Add cosign keyless signing for Docker images via GitHub OIDC
    - Capture and output image digests to GitHub Job Summary
    - Pin Dockerfile base images to digest (bun:1, golang:1.26.1-alpine, debian:bookworm-slim)
    - Add SHA256 checksum generation for binary releases (Linux/macOS/Windows)
    - Update actions/checkout v3->v4, actions/setup-go v3->v5 in release.yml

commit 9ae9040
Merge: 0191a68 ded4a12
Author: Calcium-Ion <i@caion.me>
Date:   Mon Mar 23 15:04:06 2026 +0800

    Merge pull request QuantumNous#3401 from seefs001/fix/convert-openai-detail-field

    fix: the "detail" field is empty, an empty field was sent to upstream

commit 0191a68
Merge: 16221f8 9ecad90
Author: Calcium-Ion <i@caion.me>
Date:   Mon Mar 23 15:03:57 2026 +0800

    Merge pull request QuantumNous#3400 from seefs001/fix/openai-usage

    refactor: optimize billing flow for OpenAI-to-Anthropic convert

commit 16221f8
Merge: 763c3ff 929b506
Author: Calcium-Ion <i@caion.me>
Date:   Mon Mar 23 15:03:47 2026 +0800

    Merge pull request QuantumNous#3399 from seefs001/refactor/codex-usage

    Refactor/codex usage

commit 763c3ff
Merge: c667e47 e520977
Author: Calcium-Ion <i@caion.me>
Date:   Mon Mar 23 15:03:36 2026 +0800

    Merge pull request QuantumNous#3331 from seefs001/fix/claude-beta-query

    fix: apply forced beta query at final upstream URL stage

commit c667e47
Merge: 216b94d b09337e
Author: Calcium-Ion <i@caion.me>
Date:   Mon Mar 23 15:03:23 2026 +0800

    Merge pull request QuantumNous#3333 from seefs001/fix/channel-affinity-disable

    fix: honor channel affinity skip-retry when channel is disabled

commit 216b94d
Merge: 49eb533 e9f8f62
Author: Calcium-Ion <i@caion.me>
Date:   Mon Mar 23 15:03:01 2026 +0800

    Merge pull request QuantumNous#3335 from seefs001/chore/adjuct-default-settings

    adjuct default settings

commit 49eb533
Merge: 7693eda 45f65c2
Author: Calcium-Ion <i@caion.me>
Date:   Mon Mar 23 15:02:44 2026 +0800

    Merge pull request QuantumNous#3381 from seefs001/feature/regex-ignored-upstream-models

    feat: support regex-prefixed ignored upstream models

commit 7693eda
Merge: d6982c8 f40eb4e
Author: Calcium-Ion <i@caion.me>
Date:   Mon Mar 23 15:02:34 2026 +0800

    Merge pull request QuantumNous#3393 from seefs001/fix/oauth-bind

    fix: oauth bind callback handling

commit ded4a12
Author: Seefs <i@seefs.me>
Date:   Mon Mar 23 15:00:20 2026 +0800

    fix: the "detail" field is empty, an empty field was sent to the upstream system.

commit d6982c8
Merge: deff59a 6c074ef
Author: Calcium-Ion <i@caion.me>
Date:   Mon Mar 23 14:53:13 2026 +0800

    Merge pull request QuantumNous#3379 from seefs001/refactor/rm-coding-plan

    fix: disable doubao coding plan selection

commit 9ecad90
Author: Seefs <i@seefs.me>
Date:   Mon Mar 23 14:22:12 2026 +0800

    refactor: optimize billing flow for OpenAI-to-Anthropic convert

commit 929b506
Author: Seefs <i@seefs.me>
Date:   Mon Mar 23 13:54:54 2026 +0800

    refactor: simplify codex account modal and collapse raw json by default

commit 755ece2
Author: Seefs <i@seefs.me>
Date:   Mon Mar 23 00:58:59 2026 +0800

    refactor: simplify codex account modal and collapse raw json by default

commit f40eb4e
Author: Seefs <i@seefs.me>
Date:   Mon Mar 23 00:48:55 2026 +0800

    fix: oauth bind callback handling

commit 45f65c2
Author: Seefs <i@seefs.me>
Date:   Sun Mar 22 15:43:03 2026 +0800

    feat: support regex-prefixed ignored upstream models

commit 6c074ef
Author: Seefs <i@seefs.me>
Date:   Sun Mar 22 15:01:09 2026 +0800

    fix: disable doubao coding plan selection

commit deff59a
Author: CaIon <i@caion.me>
Date:   Sun Mar 22 13:55:03 2026 +0800

    fix: increase StreamScannerMaxBufferMB limit and add handling for gpt-5.4-nano prefix

commit 3c51608
Merge: 4d675b4 e80d867
Author: Seefs <40468931+seefs001@users.noreply.github.com>
Date:   Sun Mar 22 00:43:13 2026 +0800

    Merge pull request QuantumNous#3360 from lcq225/docs/improve-bt-installation-guide

    docs: 完善宝塔面板部署教程并修复链接错误

commit 4d675b4
Merge: 87b426f 2c3ae32
Author: Seefs <40468931+seefs001@users.noreply.github.com>
Date:   Sun Mar 22 00:39:49 2026 +0800

    Merge pull request QuantumNous#3357 from wenyifancc/cache_llama_cpp

    feat: Add support for counting cache-hit tokens in llama.cpp

commit 87b426f
Merge: 42846c6 49db514
Author: Seefs <40468931+seefs001@users.noreply.github.com>
Date:   Sun Mar 22 00:32:01 2026 +0800

    Merge pull request QuantumNous#3369 from RedwindA/feat/logsManagement

    feat: add server log file management to performance settings

commit 49db514
Author: RedwindA <austinaosid@gmail.com>
Date:   Sat Mar 21 21:48:31 2026 +0800

    fix: align log cleanup button with other controls in the row

commit 13122aa
Author: RedwindA <austinaosid@gmail.com>
Date:   Sat Mar 21 21:11:52 2026 +0800

    fix: refresh log info on partial delete failure

commit dcd0911
Author: RedwindA <austinaosid@gmail.com>
Date:   Sat Mar 21 20:40:39 2026 +0800

    fix: log management race condition, partial delete reporting, and UX issues

    - Fix data race on gin.DefaultWriter during log rotation by adding LogWriterMu
    - Report partial failure when some log files fail to delete instead of always returning success
    - Fix misleading "logging disabled" banner shown before API responds
    - Fix en.json translation for numeric validation message

commit e904579
Author: RedwindA <austinaosid@gmail.com>
Date:   Sat Mar 21 20:06:49 2026 +0800

    feat: add server log file management to performance settings

    Add API endpoints (GET/DELETE /api/performance/logs) to list and clean up
    server log files by count or by age. Track the active log file path in
    the logger to prevent deleting the currently open log. Add a management
    UI section in the performance settings page with log directory info,
    file statistics, and cleanup controls. Includes i18n translations for
    all supported languages (en, fr, ja, ru, vi, zh-CN, zh-TW).

commit e80d867
Author: mm413 <lcq225@163.com>
Date:   Fri Mar 20 20:13:30 2026 +0800

    Update docs/installation/BT.md

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

commit cf86fe5
Author: lcq225 <lcq225@163.com>
Date:   Fri Mar 20 20:06:09 2026 +0800

    docs: 完善宝塔面板部署教程并修复链接错误

    - 完善 docs/installation/BT.md,从 2 行扩展为完整教程
    - 包含前置要求、安装步骤、配置说明、常见问题
    - 修复 README.zh_CN.md 中的链接错误
    - 所有内容基于官方文档 https://docs.newapi.pro 编写

commit 2c3ae32
Author: wenyifan <yifan.wen@eisgroup.com>
Date:   Fri Mar 20 16:48:04 2026 +0800

    fix map

commit 498199b
Author: wenyifan <yifan.wen@eisgroup.com>
Date:   Fri Mar 20 16:38:48 2026 +0800

    fix code quality

commit ff29900
Author: wenyifan <yifan.wen@eisgroup.com>
Date:   Fri Mar 20 16:10:18 2026 +0800

    feat: Add support for counting cache-hit tokens in llama.cpp OpenAI-Compatible API

commit eff5185
Author: Seefs <i@seefs.me>
Date:   Fri Mar 20 16:00:36 2026 +0800

    refactor: show codex account info tag and highlight plan type in usage modal

commit e9f8f62
Author: Seefs <i@seefs.me>
Date:   Thu Mar 19 16:58:13 2026 +0800

    fix: raise default overload disk threshold to 95%

commit 5fe8e98
Author: Seefs <i@seefs.me>
Date:   Thu Mar 19 16:56:28 2026 +0800

    fix: default codex and claude channel affinity templates to skip retry on failure

commit e520977
Author: Seefs <i@seefs.me>
Date:   Thu Mar 19 15:49:50 2026 +0800

    fix: apply forced beta query at final upstream URL stage

commit b09337e
Author: Seefs <i@seefs.me>
Date:   Wed Mar 18 16:08:31 2026 +0800

    fix: honor channel affinity skip-retry when preferred channel is disabled
VeryGoodUser1 pushed a commit to xmz-ai/new-api that referenced this pull request Apr 3, 2026
refactor: optimize billing flow for OpenAI-to-Anthropic convert
@coderabbitai coderabbitai Bot mentioned this pull request Jun 21, 2026
6 of 11 tasks
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
refactor: optimize billing flow for OpenAI-to-Anthropic convert
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
refactor: optimize billing flow for OpenAI-to-Anthropic convert
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