mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-27 08:05:33 +00:00
fix(billing): bill composite alias requests by the concrete forwarded model
Composite public aliases (e.g. all/claude) reach the Anthropic/Gemini billing core via OriginalModel/ChannelMappedModel source overrides. Unknown aliases resolved to no pricing and silently recorded $0 cost, while family-word aliases were mispriced by the fallback family match (Opus traffic billed at the Sonnet fallback rate). The OpenAI path already guards this via usageBillingModelCandidates; the shared recordUsageCore had neither the guard nor a fallback. - composite groups: unless the admin explicitly configured channel pricing for the alias (OpenRouter-style custom pricing), bill by the concrete forwarded model - general safety net: when the selected billing model has no resolvable pricing at all, fall back to the concrete forwarded model instead of silently recording $0 - grok media usage records now attribute OriginalModel to the client requested public alias, consistent with every other endpoint (billing unaffected: empty BillingModelSource never triggers source overrides) Priced traffic and non-composite groups are unaffected.
This commit is contained in:
@@ -472,8 +472,11 @@ func recordGrokMediaUsage(
|
||||
inboundEndpoint := GetInboundEndpoint(c)
|
||||
upstreamEndpoint := GetUpstreamEndpoint(c, account.Platform)
|
||||
quotaPlatform := service.QuotaPlatform(c.Request.Context(), apiKey)
|
||||
// OriginalModel 记录客户端请求的模型:composite 分组下 body 已被改写为具体模型,
|
||||
// 公开别名需从 context 取回,与其他端点的用量归因口径一致(计费不受影响:
|
||||
// BillingModelSource 为空不会触发来源覆盖)。
|
||||
channelUsageFields := service.ChannelUsageFields{
|
||||
OriginalModel: requestModel,
|
||||
OriginalModel: clientRequestedModel(c, requestModel),
|
||||
ChannelMappedModel: requestModel,
|
||||
}
|
||||
h.submitOpenAIUsageRecordTask(c.Request.Context(), result, func(ctx context.Context) {
|
||||
|
||||
Reference in New Issue
Block a user