From ddf2b249019916feb690d1b38dbde21cbbc9052a Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Tue, 13 Jan 2026 15:50:34 -0800 Subject: [PATCH] Top virtual keys show N select --- .../components/EntityUsage/TopKeyView.tsx | 25 ++++++++++++++----- .../UsagePage/components/UsagePageView.tsx | 20 +++++++++------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ui/litellm-dashboard/src/components/UsagePage/components/EntityUsage/TopKeyView.tsx b/ui/litellm-dashboard/src/components/UsagePage/components/EntityUsage/TopKeyView.tsx index db26828600..5d982133fa 100644 --- a/ui/litellm-dashboard/src/components/UsagePage/components/EntityUsage/TopKeyView.tsx +++ b/ui/litellm-dashboard/src/components/UsagePage/components/EntityUsage/TopKeyView.tsx @@ -4,7 +4,7 @@ import KeyInfoView from "../../../templates/key_info_view"; import { keyInfoV1Call } from "../../../networking"; import { transformKeyInfo } from "../../../key_team_helpers/transform_key_info"; import { DataTable } from "../../../view_logs/table"; -import { Tooltip } from "antd"; +import { Segmented, Tooltip } from "antd"; import { Button } from "@tremor/react"; import { formatNumberWithCommas } from "../../../../utils/dataUtils"; import { TagUsage } from "../../types"; @@ -15,9 +15,11 @@ interface TopKeyViewProps { topKeys: any[]; teams: any[] | null; showTags?: boolean; + topKeysLimit: number; + setTopKeysLimit: (limit: number) => void; } -const TopKeyView: React.FC = ({ topKeys, teams, showTags = false }) => { +const TopKeyView: React.FC = ({ topKeys, teams, showTags = false, topKeysLimit, setTopKeysLimit }) => { const { accessToken, userRole, userId: userID, premiumUser } = useAuthorized(); const [isModalOpen, setIsModalOpen] = useState(false); const [selectedKey, setSelectedKey] = useState(null); @@ -178,7 +180,17 @@ const TopKeyView: React.FC = ({ topKeys, teams, showTags = fals return ( <> -
+
+ setTopKeysLimit(value as number)} + />
{viewMode === "chart" ? ( -
+
= ({ topKeys, teams, showTags = fals />
) : ( -
+
= ({ teams, organizations }) => { const [showCustomerBanner, setShowCustomerBanner] = useState(true); const [usageView, setUsageView] = useState("global"); const [showAgentBanner, setShowAgentBanner] = useState(true); + const [topKeysLimit, setTopKeysLimit] = useState(5); const getAllTags = async () => { if (!accessToken) { return; @@ -116,7 +117,7 @@ const UsagePage: React.FC = ({ teams, organizations }) => { const totalSpend = userSpendData.metadata?.total_spend || 0; // Calculate top models from the breakdown data - const getTopModels = () => { + const getTopModels = (limit: number = 5) => { const modelSpend: { [key: string]: MetricWithMetadata } = {}; userSpendData.results.forEach((day) => { Object.entries(day.breakdown.models || {}).forEach(([model, metrics]) => { @@ -159,10 +160,10 @@ const UsagePage: React.FC = ({ teams, organizations }) => { tokens: metrics.metrics.total_tokens, })) .sort((a, b) => b.spend - a.spend) - .slice(0, 5); + .slice(0, limit); }; - const getTopModelGroups = () => { + const getTopModelGroups = (limit: number = 5) => { const modelGroupSpend: { [key: string]: MetricWithMetadata } = {}; userSpendData.results.forEach((day) => { Object.entries(day.breakdown.model_groups || {}).forEach(([modelGroup, metrics]) => { @@ -206,7 +207,7 @@ const UsagePage: React.FC = ({ teams, organizations }) => { tokens: metrics.metrics.total_tokens, })) .sort((a, b) => b.spend - a.spend) - .slice(0, 5); + .slice(0, limit); }; // Calculate provider spend from the breakdown data @@ -254,7 +255,7 @@ const UsagePage: React.FC = ({ teams, organizations }) => { }; // Calculate top API keys from the breakdown data - const getTopKeys = () => { + const getTopKeys = (limit: number = 5) => { const keySpend: { [key: string]: KeyMetricWithMetadata } = {}; userSpendData.results.forEach((day) => { Object.entries(day.breakdown.api_keys || {}).forEach(([key, metrics]) => { @@ -300,7 +301,7 @@ const UsagePage: React.FC = ({ teams, organizations }) => { spend: metrics.metrics.spend, })) .sort((a, b) => b.spend - a.spend) - .slice(0, 5); + .slice(0, limit); }; const fetchUserSpendData = useCallback(async () => { @@ -576,7 +577,12 @@ const UsagePage: React.FC = ({ teams, organizations }) => { Top Virtual Keys - +