From e7f02f31bca42920545881f3b03163e385bb6b45 Mon Sep 17 00:00:00 2001 From: sharath <29162020+tnfssc@users.noreply.github.com> Date: Thu, 26 Jun 2025 17:33:52 +0000 Subject: [PATCH] feat(billing): introduce token price multiplier and update cost calculations; enhance billing UI with new pricing buttons --- backend/services/billing.py | 15 +- .../app/(dashboard)/model-pricing/page.tsx | 367 ++++++++---------- .../billing/account-billing-status.tsx | 11 +- .../src/components/billing/billing-modal.tsx | 4 +- .../src/components/billing/usage-logs.tsx | 2 +- .../home/sections/pricing-section.tsx | 6 +- frontend/src/lib/home.tsx | 16 +- 7 files changed, 194 insertions(+), 227 deletions(-) diff --git a/backend/services/billing.py b/backend/services/billing.py index dcbfa923..4593bb30 100644 --- a/backend/services/billing.py +++ b/backend/services/billing.py @@ -20,6 +20,9 @@ import time # Initialize Stripe stripe.api_key = config.STRIPE_SECRET_KEY +# Token price multiplier +TOKEN_PRICE_MULTIPLIER = 2 + # Initialize router router = APIRouter(prefix="/billing", tags=["billing"]) @@ -278,8 +281,8 @@ async def calculate_monthly_usage(client, user_id: str) -> float: total_cost += message_cost - # Return total cost * 2 (as per original logic) - total_cost = total_cost * 2 + # Return total cost * TOKEN_PRICE_MULTIPLIER (as per original logic) + total_cost = total_cost * TOKEN_PRICE_MULTIPLIER logger.info(f"Total cost for user {user_id}: {total_cost}") return total_cost @@ -1038,8 +1041,8 @@ async def get_available_models( if hardcoded_pricing: input_cost_per_million, output_cost_per_million = hardcoded_pricing pricing_info = { - "input_cost_per_million_tokens": input_cost_per_million, - "output_cost_per_million_tokens": output_cost_per_million, + "input_cost_per_million_tokens": input_cost_per_million * TOKEN_PRICE_MULTIPLIER, + "output_cost_per_million_tokens": output_cost_per_million * TOKEN_PRICE_MULTIPLIER, "max_tokens": None } else: @@ -1090,8 +1093,8 @@ async def get_available_models( if input_cost_per_token is not None and output_cost_per_token is not None: pricing_info = { - "input_cost_per_million_tokens": round(input_cost_per_token * 2, 2), - "output_cost_per_million_tokens": round(output_cost_per_token * 2, 2), + "input_cost_per_million_tokens": input_cost_per_token * TOKEN_PRICE_MULTIPLIER, + "output_cost_per_million_tokens": output_cost_per_token * TOKEN_PRICE_MULTIPLIER, "max_tokens": None # cost_per_token doesn't provide max_tokens info } else: diff --git a/frontend/src/app/(dashboard)/model-pricing/page.tsx b/frontend/src/app/(dashboard)/model-pricing/page.tsx index fc7161ac..4df75abe 100644 --- a/frontend/src/app/(dashboard)/model-pricing/page.tsx +++ b/frontend/src/app/(dashboard)/model-pricing/page.tsx @@ -1,226 +1,183 @@ 'use client'; -import { useEffect, useState } from 'react'; import { SectionHeader } from '@/components/home/section-header'; -import { getAvailableModels, Model } from '@/lib/api'; -import { Loader2, AlertCircle } from 'lucide-react'; +import { AlertCircle } from 'lucide-react'; import { Button } from '@/components/ui/button'; +import { useAvailableModels } from '@/hooks/react-query/subscriptions/use-billing'; +import type { Model } from '@/lib/api'; +import { Loader2 } from 'lucide-react'; import Link from 'next/link'; -interface PricingTableRowProps { +interface ModelCardProps { model: Model; index: number; } -function PricingTableRow({ model, index }: PricingTableRowProps) { +function ModelCard({ model, index }: ModelCardProps) { return ( -
- Compare pricing across our supported AI models. All prices are shown - per million tokens. -
-Loading model pricing...
-{error}
- -- Model - | -- Input Cost - | -- Output Cost - | -
---|
+ Loading compute pricing +
++ Fetching the latest pricing data... +
++ {error instanceof Error + ? error.message + : 'Failed to fetch model pricing'} +
+