mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
fix(gemini): keep forced cache billing on sticky-session failover
Keep the stable content session hash from this PR, but restore ForceCacheBilling on the native v1beta entry. Dropping it changed billing policy: a sticky session that failed over would be charged full input price instead of cache-read price. That also hit Antigravity accounts served by this handler, and made it inconsistent with /v1/messages, which still forces cache billing. Billing on this entry is now identical to main.
This commit is contained in:
1 parent
e391d5fa38
commit
8d57f461ca
1 file changed
+3
-1
@@ -816,11 +816,12 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
|
||||
requestPayloadHash := service.HashUsageRequestPayload(body)
|
||||
inboundEndpoint := GetInboundEndpoint(c)
|
||||
upstreamEndpoint := GetUpstreamEndpoint(c, account.Platform)
|
||||
// ForceCacheBilling 提前拍成标量,避免 worker 闭包保活 failover 状态里的响应体。
|
||||
forceCacheBilling := fs.ForceCacheBilling
|
||||
quotaPlatform := service.QuotaPlatform(c.Request.Context(), apiKey)
|
||||
sessionID := service.ExtractClientSessionID(c)
|
||||
// 长上下文阶梯由目录数据驱动,统一在计费路径内生效,入口无需声明。
|
||||
channelUsageFields := clientRequestedUsageFields(c, channelMapping, reqModel, result.UpstreamModel)
|
||||
// 按上游实际返回的用量计费:粘性会话换号不做强制缓存计费,缓存读取只来自上游的 cachedContentTokenCount。
|
||||
h.submitUsageRecordTask(c.Request.Context(), func(ctx context.Context) {
|
||||
if err := h.gatewayService.RecordUsage(ctx, &service.RecordUsageInput{
|
||||
Result: result,
|
||||
@@ -835,6 +836,7 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
|
||||
UserAgent: userAgent,
|
||||
IPAddress: clientIP,
|
||||
RequestPayloadHash: requestPayloadHash,
|
||||
ForceCacheBilling: forceCacheBilling,
|
||||
APIKeyService: h.apiKeyService,
|
||||
SessionID: sessionID,
|
||||
ChannelUsageFields: channelUsageFields,
|
||||
|
||||
Reference in new issue
Block a user