From 59ec4b53b2909d21ec8089c0103bfb88dfb2fc9d Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Mon, 5 Jan 2026 17:45:20 +0530 Subject: [PATCH] v0 cost estimator --- .../cost_tracking_settings.tsx | 264 ++++++++++-------- 1 file changed, 152 insertions(+), 112 deletions(-) diff --git a/ui/litellm-dashboard/src/components/CostTrackingSettings/cost_tracking_settings.tsx b/ui/litellm-dashboard/src/components/CostTrackingSettings/cost_tracking_settings.tsx index 32ffd55efa0..7b68c7cd29b 100644 --- a/ui/litellm-dashboard/src/components/CostTrackingSettings/cost_tracking_settings.tsx +++ b/ui/litellm-dashboard/src/components/CostTrackingSettings/cost_tracking_settings.tsx @@ -6,11 +6,13 @@ import ProviderDiscountTable from "./provider_discount_table"; import AddProviderForm from "./add_provider_form"; import ProviderMarginTable from "./provider_margin_table"; import AddMarginForm from "./add_margin_form"; +import PricingCalculator from "./pricing_calculator/index"; import { ExclamationCircleOutlined } from "@ant-design/icons"; import { DocsMenu } from "../HelpLink"; import HowItWorks from "./how_it_works"; import { useDiscountConfig } from "./use_discount_config"; import { useMarginConfig } from "./use_margin_config"; +import { fetchAvailableModels, ModelGroup } from "../playground/llm_calls/fetch_models"; const DOCS_LINKS = [ { label: "Custom pricing for models", href: "https://docs.litellm.ai/docs/proxy/custom_pricing" }, @@ -31,9 +33,12 @@ const CostTrackingSettings: React.FC = ({ const [marginType, setMarginType] = useState<"percentage" | "fixed">("percentage"); const [percentageValue, setPercentageValue] = useState(""); const [fixedAmountValue, setFixedAmountValue] = useState(""); + const [models, setModels] = useState([]); const [form] = Form.useForm(); const [marginForm] = Form.useForm(); const [modal, contextHolder] = Modal.useModal(); + + const isProxyAdmin = userRole === "proxy_admin"; // Use custom hooks for discount and margin config const { @@ -57,6 +62,17 @@ const CostTrackingSettings: React.FC = ({ Promise.all([fetchDiscountConfig(), fetchMarginConfig()]).finally(() => { setIsFetching(false); }); + + // Fetch models for pricing calculator (available to all roles) + const loadModels = async () => { + try { + const modelGroups = await fetchAvailableModels(accessToken); + setModels(modelGroups.map((m: ModelGroup) => m.model_group)); + } catch (error) { + console.error("Error fetching models:", error); + } + }; + loadModels(); } }, [accessToken, fetchDiscountConfig, fetchMarginConfig]); @@ -152,129 +168,153 @@ const CostTrackingSettings: React.FC = ({ {/* Main Content Card with Accordions */}
- {/* Accordion 1: Provider Discounts */} - - -
- Provider Discounts - - Apply percentage-based discounts to reduce costs for specific providers - -
-
- - - - Discounts - Test It - - - -
-
- -
- {isFetching ? ( -
- Loading configuration... -
- ) : Object.keys(discountConfig).length > 0 ? ( - - ) : ( -
- + +
+ Provider Discounts + + Apply percentage-based discounts to reduce costs for specific providers + +
+ + + + + Discounts + Test It + + + +
+
+
- )} -
-
- -
- -
-
-
-
-
- + {isFetching ? ( +
+ Loading configuration... +
+ ) : Object.keys(discountConfig).length > 0 ? ( + + ) : ( +
+ + + + + No provider discounts configured + + + Click "Add Provider Discount" to get started + +
+ )} +
+ + +
+ +
+
+ + + + + )} - {/* Accordion 2: Fee/Price Margin */} - + {/* Accordion 2: Fee/Price Margin - Only for proxy admins */} + {isProxyAdmin && ( + + +
+ Fee/Price Margin + + Add fees or margins to LLM costs for internal billing and cost recovery + +
+
+ +
+
+ +
+ {isFetching ? ( +
+ Loading configuration... +
+ ) : Object.keys(marginConfig).length > 0 ? ( + + ) : ( +
+ + + + + No provider margins configured + + + Click "Add Provider Margin" to get started + +
+ )} +
+
+
+ )} + + {/* Accordion 3: Pricing Calculator - Available to all roles */} +
- Fee/Price Margin + Pricing Calculator - Add fees or margins to LLM costs for internal billing and cost recovery + Estimate LLM costs based on expected token usage and request volume
-
- -
- {isFetching ? ( -
- Loading configuration... -
- ) : Object.keys(marginConfig).length > 0 ? ( - - ) : ( -
- - - - - No provider margins configured - - - Click "Add Provider Margin" to get started - -
- )} +