mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-11 07:56:50 +02:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user