From 9a5564f00e1522bbaba246221e1b1dc26bb92752 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sat, 5 Sep 2026 16:20:56 -0700 Subject: [PATCH] fix(ui): read Usage Total Requests tile from gateway request counts (#39963) --- .../components/UsagePageView.test.tsx | 24 +++++++++---------- .../_components/components/UsagePageView.tsx | 5 +++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.test.tsx index 26d595f4d74..7702488f5bf 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.test.tsx @@ -424,17 +424,14 @@ describe("UsagePage", () => { // Check that key metrics are displayed const totalRequestElements = screen.getAllByText("Total Requests"); expect(totalRequestElements.length).toBeGreaterThan(0); - expect(screen.getByText("1,500")).toBeInTheDocument(); const successfulRequestLabelElements = screen.getAllByText("Successful Requests"); expect(successfulRequestLabelElements.length).toBeGreaterThan(0); - // Successful and Failed Requests both read the gateway counter, not the - // spend-derived 1,450 / 50 that the same payload carries for the per-key and - // per-model breakdowns. They must share a source, or the tiles contradict the - // endpoint breakdown chart below them. await waitFor(() => { expect(screen.getAllByText("424,242").length).toBeGreaterThan(0); }); expect(screen.getAllByText("909").length).toBeGreaterThan(0); + expect(screen.getByText("425,151")).toBeInTheDocument(); + expect(screen.queryByText("1,500")).not.toBeInTheDocument(); expect(screen.queryByText("1,450")).not.toBeInTheDocument(); }); @@ -454,7 +451,7 @@ describe("UsagePage", () => { renderWithProviders(); await waitFor(() => { - expect(screen.getAllByText("1,500").length).toBeGreaterThan(0); + expect(screen.getAllByText("75,000").length).toBeGreaterThan(0); }); await act(async () => { @@ -464,13 +461,13 @@ describe("UsagePage", () => { await waitFor(() => { expect(mockUserDailyActivityAggregatedCall).toHaveBeenCalledTimes(2); }); - expect(screen.queryByText("1,500")).not.toBeInTheDocument(); + expect(screen.queryByText("75,000")).not.toBeInTheDocument(); await act(async () => { releaseSecondFetch(); }); await waitFor(() => { - expect(screen.getAllByText("1,500").length).toBeGreaterThan(0); + expect(screen.getAllByText("75,000").length).toBeGreaterThan(0); }); }); @@ -485,8 +482,10 @@ describe("UsagePage", () => { await waitFor(() => { expect(screen.getAllByText("1,450").length).toBeGreaterThan(0); }); + expect(screen.getByText("1,500")).toBeInTheDocument(); expect(screen.queryByText("424,242")).not.toBeInTheDocument(); expect(screen.queryByText("909")).not.toBeInTheDocument(); + expect(screen.queryByText("425,151")).not.toBeInTheDocument(); expect(screen.queryByTestId("gateway-requests-by-endpoint")).not.toBeInTheDocument(); }); @@ -499,6 +498,7 @@ describe("UsagePage", () => { expect(mockUserDailyActivityAggregatedCall).toHaveBeenCalled(); }); expect(mockGatewayDailyActivityCall).not.toHaveBeenCalled(); + expect(screen.getByText("1,500")).toBeInTheDocument(); expect(screen.queryByText("424,242")).not.toBeInTheDocument(); expect(screen.queryByTestId("gateway-requests-by-endpoint")).not.toBeInTheDocument(); }); @@ -1045,7 +1045,7 @@ describe("UsagePage", () => { }); // Should still render the data from the paginated fallback, which lands a render after the call - expect(await screen.findByText("1,500")).toBeInTheDocument(); + expect(await screen.findByText("75,000")).toBeInTheDocument(); }); it("should stop showing the previous range's paginated pages while a new range is in flight", async () => { @@ -1069,7 +1069,7 @@ describe("UsagePage", () => { renderWithProviders(); await waitFor(() => { - expect(screen.getAllByText("1,500").length).toBeGreaterThan(0); + expect(screen.getAllByText("75,000").length).toBeGreaterThan(0); }); await act(async () => { @@ -1079,13 +1079,13 @@ describe("UsagePage", () => { await waitFor(() => { expect(mockUserDailyActivityAggregatedCall).toHaveBeenCalledTimes(2); }); - expect(screen.queryByText("1,500")).not.toBeInTheDocument(); + expect(screen.queryByText("75,000")).not.toBeInTheDocument(); await act(async () => { releaseSecondAggregated(); }); await waitFor(() => { - expect(screen.getAllByText("1,500").length).toBeGreaterThan(0); + expect(screen.getAllByText("75,000").length).toBeGreaterThan(0); }); }); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsx b/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsx index 29a81e1ae3f..a92d1209567 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsx @@ -573,7 +573,10 @@ const UsagePage: React.FC = ({ teams, organizations }) => {

Total Requests

- {userSpendData.metadata?.total_api_requests?.toLocaleString() || 0} + {(gatewayActivity + ? gatewayActivity.total_successful_requests + gatewayActivity.total_failed_requests + : userSpendData.metadata?.total_api_requests + )?.toLocaleString() || 0}