From fa3f8724577d89bac995457456116705fd7c37ef Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Jan 2026 15:19:09 +0000 Subject: [PATCH] fix: prefer upstream_inference_cost over cost for BYOK For BYOK (Bring Your Own Key) scenarios, OpenRouter returns: - cost: 0 (no charge to OpenRouter account) - cost_details.upstream_inference_cost: actual API cost Now checks upstream_inference_cost first, which contains the actual cost regardless of billing mode. https://claude.ai/code/session_01HqtD9R33oqfB14Gu1V5wHC --- src/services/llm/provider-manager.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/services/llm/provider-manager.ts b/src/services/llm/provider-manager.ts index 1d13485..55a6872 100644 --- a/src/services/llm/provider-manager.ts +++ b/src/services/llm/provider-manager.ts @@ -439,14 +439,13 @@ class AIProviderManager { }; // Extract cost from API response (OpenRouter/PPQ provide this) + // Prefer upstream_inference_cost (actual cost for BYOK) over cost (which is 0 for BYOK) // eslint-disable-next-line @typescript-eslint/no-explicit-any const usageAny = chunk.usage as any; - if (typeof usageAny.cost === "number") { - cost = usageAny.cost; - } else if ( - usageAny.cost_details?.upstream_inference_cost !== undefined - ) { + if (usageAny.cost_details?.upstream_inference_cost !== undefined) { cost = usageAny.cost_details.upstream_inference_cost; + } else if (typeof usageAny.cost === "number" && usageAny.cost > 0) { + cost = usageAny.cost; } } }