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
This commit is contained in:
Claude
2026-01-31 15:19:09 +00:00
parent 53aca05a65
commit fa3f872457

View File

@@ -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;
}
}
}