From 4bee1ab6355c7c7796fa191bf5542edef18f778d Mon Sep 17 00:00:00 2001 From: sharath <29162020+tnfssc@users.noreply.github.com> Date: Thu, 26 Jun 2025 19:49:47 +0000 Subject: [PATCH] feat(billing): implement fixed cutoff date for monthly usage calculations to ignore token counts before June 27, 2025 --- backend/services/billing.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/services/billing.py b/backend/services/billing.py index 4593bb30..1fd10908 100644 --- a/backend/services/billing.py +++ b/backend/services/billing.py @@ -229,6 +229,13 @@ async def calculate_monthly_usage(client, user_id: str) -> float: now = datetime.now(timezone.utc) start_of_month = datetime(now.year, now.month, 1, tzinfo=timezone.utc) + # Use fixed cutoff date: June 27, 2025 midnight UTC + # Ignore all token counts before this date + cutoff_date = datetime(2025, 6, 27, 0, 0, 0, tzinfo=timezone.utc) + + # Use the later of the two dates (start of month or cutoff date) + start_of_month = max(start_of_month, cutoff_date) + # First get all threads for this user threads_result = await client.table('threads') \ .select('thread_id') \ @@ -254,7 +261,7 @@ async def calculate_monthly_usage(client, user_id: str) -> float: if not token_messages.data: return 0.0 - + # Calculate total cost per message (to handle different models correctly) total_cost = 0.0