Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(ui): read Usage Total Requests tile from gateway request counts (#39963)

devin-ai-integration[bot]9a5564f00e15
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(<UsagePage {...defaultProps} />);
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(<UsagePage {...defaultProps} />);
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<UsagePageProps> = ({ teams, organizations }) => {
<CardContent>
<h3 className="text-lg font-medium text-foreground">Total Requests</h3>
<p className="text-2xl font-bold mt-2">
- {userSpendData.metadata?.total_api_requests?.toLocaleString() || 0}
+ {(gatewayActivity
+ ? gatewayActivity.total_successful_requests + gatewayActivity.total_failed_requests
+ : userSpendData.metadata?.total_api_requests
+ )?.toLocaleString() || 0}
</p>
</CardContent>
</ShadcnCard>