fix(cost): use optional chaining for cost match and Number.parseFloat for fixed total

Co-authored-by: Genie <genie@cosine.sh>
This commit is contained in:
Praveen Thirumurugan
2025-12-27 20:26:40 +00:00
committed by Genie
parent 308a251056
commit eeebf1c6e9

View File

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