From 22f7d198a66ea5b8e305c7b74cb2d650a214df8c Mon Sep 17 00:00:00 2001 From: 9qeklajc Date: Sat, 3 Jan 2026 21:23:32 +0100 Subject: [PATCH] #274 do not change user for empty response by upstream --- routstr/payment/cost_calculation.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/routstr/payment/cost_calculation.py b/routstr/payment/cost_calculation.py index 2a3f9e8a..efbd3987 100644 --- a/routstr/payment/cost_calculation.py +++ b/routstr/payment/cost_calculation.py @@ -48,13 +48,6 @@ async def calculate_cost( # todo: can be sync }, ) - cost_data = MaxCostData( - base_msats=max_cost, - input_msats=0, - output_msats=0, - total_msats=max_cost, - ) - if "usage" not in response_data or response_data["usage"] is None: logger.warning( "No usage data in response, using base cost only", @@ -63,7 +56,12 @@ async def calculate_cost( # todo: can be sync "model": response_data.get("model", "unknown"), }, ) - return cost_data + return MaxCostData( + base_msats=0, + input_msats=0, + output_msats=0, + total_msats=0, + ) usage_data = response_data["usage"] @@ -178,7 +176,12 @@ async def calculate_cost( # todo: can be sync "model": response_data.get("model", "unknown"), }, ) - return cost_data + return MaxCostData( + base_msats=max_cost, + input_msats=0, + output_msats=0, + total_msats=max_cost, + ) input_tokens = usage_data.get("prompt_tokens", 0) output_tokens = usage_data.get("completion_tokens", 0)