diff --git a/routstr/core/admin.py b/routstr/core/admin.py index 8f038a8e..c3539191 100644 --- a/routstr/core/admin.py +++ b/routstr/core/admin.py @@ -2893,7 +2893,7 @@ def _aggregate_metrics_by_time( CRITICAL: This function parses specific log messages for usage tracking. The following log messages must not be modified without updating this function: - "received proxy request" -> counts total_requests - - "token adjustment completed" -> counts successful_chat_completions, extracts revenue_msats from cost_data.actual_cost + - "token adjustment completed" -> counts successful_chat_completions, extracts revenue_msats from cost_data.total_msats - "upstream request failed" OR "revert payment" -> counts failed_requests - "payment processed successfully" -> counts payment_processed - "revert payment" -> extracts refunds_msats from max_cost_for_model @@ -2965,7 +2965,7 @@ def _aggregate_metrics_by_time( if "token adjustment completed" in message: cost_data = entry.get("cost_data") if isinstance(cost_data, dict): - actual_cost = cost_data.get("actual_cost", 0) + actual_cost = cost_data.get("total_msats", 0) if isinstance(actual_cost, (int, float)) and actual_cost > 0: time_buckets[bucket_key]["revenue_msats"] += actual_cost @@ -3080,7 +3080,7 @@ def _get_summary_stats(entries: list[dict], hours_back: int = 24) -> dict: if "token adjustment completed" in message: cost_data = entry.get("cost_data") if isinstance(cost_data, dict): - actual_cost = cost_data.get("actual_cost", 0) + actual_cost = cost_data.get("total_msats", 0) if isinstance(actual_cost, (int, float)) and actual_cost > 0: assert isinstance(stats["revenue_msats"], (int, float)) stats["revenue_msats"] = float(stats["revenue_msats"]) + float(actual_cost) @@ -3407,7 +3407,7 @@ async def get_revenue_by_model( model_stats[model]["successful"] += 1 cost_data = entry.get("cost_data") if isinstance(cost_data, dict): - actual_cost = cost_data.get("actual_cost", 0) + actual_cost = cost_data.get("total_msats", 0) if isinstance(actual_cost, (int, float)) and actual_cost > 0: model_stats[model]["revenue_msats"] += actual_cost diff --git a/routstr/core/logging.py b/routstr/core/logging.py index 4905748e..6dbd2cfc 100644 --- a/routstr/core/logging.py +++ b/routstr/core/logging.py @@ -13,7 +13,7 @@ DO NOT modify or remove these messages without updating the usage tracking logic 2. "Token adjustment completed for streaming" (INFO) - routstr/upstream/base.py "Token adjustment completed for non-streaming" (INFO) - routstr/upstream/base.py - Used to track successful completions and revenue - - The 'cost_data.actual_cost' field is extracted for revenue calculation + - The 'cost_data.total_msats' field is extracted for revenue calculation - Must include 'cost_data' in extra dict 3. "Payment processed successfully" (INFO) - routstr/auth.py diff --git a/routstr/upstream/base.py b/routstr/upstream/base.py index bccf3601..f1ce6b24 100644 --- a/routstr/upstream/base.py +++ b/routstr/upstream/base.py @@ -454,7 +454,7 @@ class BaseUpstreamProvider: usage_finalized = True # IMPORTANT: Do not modify this log message - used for usage statistics tracking # This log is parsed to track revenue from successful requests - # The 'cost_data.actual_cost' field is used to calculate total revenue + # The 'cost_data.total_msats' field is used to calculate total revenue logger.info( "Token adjustment completed for streaming", extra={ @@ -560,7 +560,7 @@ class BaseUpstreamProvider: # IMPORTANT: Do not modify this log message - used for usage statistics tracking # This log is parsed to track revenue from successful requests - # The 'cost_data.actual_cost' field is used to calculate total revenue + # The 'cost_data.total_msats' field is used to calculate total revenue logger.info( "Token adjustment completed for non-streaming", extra={