From eeebf1c6e9e03dcd77e0d8eada4106d05cebd5a0 Mon Sep 17 00:00:00 2001 From: Praveen Thirumurugan Date: Sat, 27 Dec 2025 20:26:40 +0000 Subject: [PATCH] fix(cost): use optional chaining for cost match and Number.parseFloat for fixed total Co-authored-by: Genie --- cost.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cost.ts b/cost.ts index 4a509ba..912ffe5 100644 --- a/cost.ts +++ b/cost.ts @@ -166,7 +166,7 @@ export function getCostConfig(model: string): CostConfig { * Check Helicone costs with operator matching */ const exactMatch = heliconeCosts.get(normalizedModel); - if (exactMatch && exactMatch.operator === "equals") { + if (exactMatch?.operator === "equals") { return exactMatch.config; } @@ -229,5 +229,5 @@ export function calculateCost( (completion_tokens / 1_000_000) * cost.output; const total = inputCost + cachedCost + outputCost; - return total > 0 ? Number(total.toFixed(6)) : null; + return total > 0 ? Number.parseFloat(total.toFixed(6)) : null; }