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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge upstream/litellm_internal_staging into litellm_searchable_usage_report_user_filter
Daniel Meismer2fabfd7eef4f
diff --cc ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/EntityUsage/EntityUsage.tsxindex 6f63b56c372,2d6dbb823cc..6a124aa24d3--- a/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/EntityUsage/EntityUsage.tsx+++ b/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/EntityUsage/EntityUsage.tsx@@@ -596,6 -621,6 +623,9 @@@ const EntityUsage: React.FC<EntityUsage{ key: "endpoints", label: "Endpoint Activity", content: <EndpointUsage userSpendData={spendData} /> },];++ const hasEntityFilterOptions = entityList !== null && entityList.length > 0;++ const showEntityFilters = entityType !== "team" && (filterSelectProps !== undefined || hasEntityFilterOptions);++return (<div style={{ width: "100%" }} className="relative">{isFetchingMore && (@@@ -680,31 -685,29 +690,30 @@@dateValue={dateValue}entityType={entityType}spendData={spendData}- showFilters={- entityType !== "team" &&- (filterSelectProps?.showSearch === true || (entityList !== null && entityList.length > 0))- }- showFilters={entityType !== "team" && entityList !== null && entityList.length > 0}++ showFilters={showEntityFilters}filterLabel={getFilterLabel(entityType)}filterPlaceholder={getFilterPlaceholder(entityType)}selectedFilters={selectedTags}onFiltersChange={setSelectedTags}filterOptions={getAllTags() || undefined}filterMode={entityType === "user" ? "single" : "multiple"}+ filterSelectProps={filterSelectProps}teams={teams || []}/>- <TabGroup>- <TabList variant="solid" className="mt-1">+ <Tabs defaultValue={tabs[0].key}>+ <TabsList className="mt-1">{tabs.map(({ key, label }) => (- <Tab key={key}>{label}</Tab>- ))}- </TabList>- <TabPanels>- {tabs.map(({ key, content }) => (- <TabPanel key={key}>{content}</TabPanel>+ <TabsTrigger key={key} value={key} className="flex-none px-3">+ {label}+ </TabsTrigger>))}- </TabPanels>- </TabGroup>+ </TabsList>+ {tabs.map(({ key, content }) => (+ <TabsContent key={key} value={key} keepMounted>+ {content}+ </TabsContent>+ ))}+ </Tabs></div>);};diff --cc ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.test.tsxindex 0c6874d0786,9cd1e53c9b4..016d96cfa5c--- 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@@@ -46,18 -47,7 +47,18 @@@ vi.mock("@/components/UsagePage/compone}));vi.mock("./EntityUsage/EntityUsage", () => ({- default: () => <div>Entity Usage</div>,+ default: ({+ entityType,+ filterSelectProps,+ }: {+ entityType?: string;- filterSelectProps?: { showSearch?: boolean };++ filterSelectProps?: { onSearchChange?: (query: string) => void };+ }) => (+ <div>+ Entity Usage- {entityType === "user" && filterSelectProps?.showSearch && <span>Searchable user filter</span>}++ {entityType === "user" && filterSelectProps !== undefined && <span>Searchable user filter</span>}+ </div>+ ),EntityList: [],}));diff --cc ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsxindex 9cd499dd7d2,a716d59bdc4..c37dd4b8bdc--- a/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsx+++ b/ui/litellm-dashboard/src/app/(dashboard)/usage/_components/components/UsagePageView.tsx@@@ -148,39 -135,6 +135,14 @@@ const UsagePage: React.FC<UsagePagePropreturn result;}, [usersInfiniteData]);- const handleUserSearchChange = (value: string) => {- setUserSearchInput(value);- setDebouncedUserSearch(value);- };-- const handleUserPopupScroll = (e: UIEvent<HTMLDivElement>) => {- const target = e.currentTarget;- const scrollRatio = (target.scrollTop + target.clientHeight) / target.scrollHeight;- if (scrollRatio >= 0.8 && hasNextUsersPage && !isFetchingNextUsersPage) {- fetchNextUsersPage();- }- };-+ const userFilterSelectProps: UsageFilterSelectProps = {- showSearch: true,- filterOption: false,- onSearch: handleUserSearchChange,- searchValue: userSearchInput,- onPopupScroll: handleUserPopupScroll,- loading: isLoadingUsers,- notFoundContent: isLoadingUsers ? <LoadingOutlined spin /> : "No users found",- popupRender: (menu) => (- <>- {menu}- {isFetchingNextUsersPage && (- <div style={{ textAlign: "center", padding: 8 }}>- <LoadingOutlined spin />- </div>- )}- </>- ),++ onSearchChange: setSettledUserSearch,++ onLoadMore: () => void fetchNextUsersPage(),++ hasNextPage: hasNextUsersPage,++ isLoading: isLoadingUsers,++ isFetchingNextPage: isFetchingNextUsersPage,++ emptyText: "No users found",+ };-// For admins: null means global view (all users), a string means filter by that user// For non-admins: always set to their own user IDconst [selectedUserId, setSelectedUserId] = useState<string | null>(isAdmin ? null : userID || null);diff --cc ui/litellm-dashboard/src/components/EntityUsageExport/UsageExportHeader.test.tsxindex 2a1a5f66ece,729d6fd3406..bfc667f60ba--- a/ui/litellm-dashboard/src/components/EntityUsageExport/UsageExportHeader.test.tsx+++ b/ui/litellm-dashboard/src/components/EntityUsageExport/UsageExportHeader.test.tsx@@@ -1,4 -1,4 +1,4 @@@--import { renderWithProviders, screen } from "../../../tests/test-utils";++import { renderWithProviders, screen, waitFor } from "../../../tests/test-utils";import userEvent from "@testing-library/user-event";import { vi } from "vitest";import UsageExportHeader from "./UsageExportHeader";@@@ -70,29 -70,4 +70,29 @@@ describe("UsageExportHeader", () =>);expect(screen.getByText("Team")).toBeInTheDocument();});++ it("should keep a searchable single filter usable when no options match", async () => {+ const user = userEvent.setup();- const onSearch = vi.fn();++ const onSearchChange = vi.fn();++ renderWithProviders(+ <UsageExportHeader+ {...defaultProps}+ entityType="user"+ showFilters+ filterMode="single"+ filterLabel="User"+ filterPlaceholder="Select user to filter..."+ filterOptions={[]}- filterSelectProps={{ showSearch: true, filterOption: false, onSearch }}++ filterSelectProps={{ onSearchChange, onLoadMore: vi.fn() }}+ onFiltersChange={vi.fn()}+ />,+ );++ const userFilter = screen.getByRole("combobox");+ await user.click(userFilter);+ await user.type(userFilter, "alice");+- expect(onSearch).toHaveBeenLastCalledWith("alice");++ await waitFor(() => expect(onSearchChange).toHaveBeenLastCalledWith("alice"));+ });});diff --cc ui/litellm-dashboard/src/components/EntityUsageExport/UsageExportHeader.tsxindex f7bd7747e37,78781df5948..ae5166e8d68--- a/ui/litellm-dashboard/src/components/EntityUsageExport/UsageExportHeader.tsx+++ b/ui/litellm-dashboard/src/components/EntityUsageExport/UsageExportHeader.tsx@@@ -1,23 -1,24 +1,35 @@@import type { DateRangePickerValue } from "@tremor/react";- import { Button, Text } from "@tremor/react";- import { Select, type SelectProps } from "antd";+ import { Download } from "lucide-react";import React, { useState } from "react";++import { PaginatedSearchSelect } from "@/components/shared/PaginatedSearchSelect";+ import { Button } from "@/components/ui/button";+ import {+ Combobox,+ ComboboxChip,+ ComboboxChips,+ ComboboxChipsInput,+ ComboboxClear,+ ComboboxContent,+ ComboboxEmpty,+ ComboboxInput,+ ComboboxItem,+ ComboboxList,+ ComboboxValue,+ } from "@/components/ui/combobox";import EntityUsageExportModal from "./EntityUsageExportModal";import type { EntitySpendData, EntityType } from "./types";import type { Team } from "@/components/key_team_helpers/key_list";- export type UsageFilterSelectProps = Pick<- SelectProps<string>,- | "filterOption"- | "loading"- | "notFoundContent"- | "onPopupScroll"- | "onSearch"- | "popupRender"- | "searchValue"- | "showSearch"- >;++export interface UsageFilterSelectProps {++ onSearchChange: (query: string) => void;++ onLoadMore: () => void;++ hasNextPage?: boolean;++ isLoading?: boolean;++ isFetchingNextPage?: boolean;++ emptyText?: string;++ loadingText?: string;++}+interface UsageExportHeaderProps {dateValue: DateRangePickerValue;entityType: EntityType;@@@ -53,14 -52,24 +65,81 @@@ const UsageExportHeader: React.FC<Usageteams = [],}) => {const [isExportModalOpen, setIsExportModalOpen] = useState(false);- const hasFilters = showFilters && (filterOptions.length > 0 || filterSelectProps?.showSearch === true);-- const hasFilters = showFilters && filterOptions.length > 0;++ const hasFilters = showFilters && (filterOptions.length > 0 || filterSelectProps !== undefined);+ const optionValues = filterOptions.map((option) => option.value);+ const labelOf = (value: string) => filterOptions.find((option) => option.value === value)?.label ?? value;++ const filterList = (+ <ComboboxContent>+ <ComboboxEmpty>No options found</ComboboxEmpty>+ <ComboboxList>+ {(value: string) => (+ <ComboboxItem key={value} value={value}>+ {labelOf(value)}+ </ComboboxItem>+ )}+ </ComboboxList>+ </ComboboxContent>+ );- // Determine grid layout based on what's visible- const getGridCols = () => {- if (hasFilters) return "grid-cols-[1fr_auto]";- return "grid-cols-[auto]";- };++ let filterControl: React.ReactNode;++ if (filterMode === "single" && filterSelectProps !== undefined) {++ filterControl = (++ <PaginatedSearchSelect++ options={filterOptions}++ value={selectedFilters[0]}++ onValueChange={(next) => onFiltersChange?.(next ? [next] : [])}++ placeholder={filterPlaceholder}++ {...filterSelectProps}++ />++ );++ } else if (filterMode === "single") {++ filterControl = (++ <Combobox++ items={optionValues}++ value={selectedFilters[0] ?? null}++ onValueChange={(next: string | null) => onFiltersChange?.(next ? [next] : [])}++ itemToStringLabel={labelOf}++ >++ <ComboboxInput++ className="w-full"++ placeholder={filterPlaceholder}++ aria-label={filterPlaceholder}++ showClear={selectedFilters.length > 0}++ />++ {filterList}++ </Combobox>++ );++ } else {++ filterControl = (++ <Combobox++ multiple++ items={optionValues}++ value={selectedFilters}++ onValueChange={(next: string[]) => onFiltersChange?.(next)}++ >++ <ComboboxChips className="w-full">++ <ComboboxValue>++ {(selected: string[]) =>++ selected.map((value) => (++ <ComboboxChip key={value} aria-label={labelOf(value)}>++ {labelOf(value)}++ </ComboboxChip>++ ))++ }++ </ComboboxValue>++ <ComboboxChipsInput++ className="border-0 bg-transparent"++ placeholder={filterPlaceholder}++ aria-label={filterPlaceholder}++ />++ {selectedFilters.length > 0 && <ComboboxClear aria-label={`Clear ${filterLabel ?? "filters"}`} />}++ </ComboboxChips>++ {filterList}++ </Combobox>++ );++ }+return (<><div className="mb-4">@@@ -69,26 -78,52 +148,11 @@@* align to the same baseline regardless of label heights. This removes* vertical drift when the right column has a label above the input.*/}- <div className={`grid ${getGridCols()} items-end gap-4`}>+ <div className={`grid ${hasFilters ? "grid-cols-[1fr_auto]" : "grid-cols-[auto]"} items-end gap-4`}>{hasFilters && (<div>- {filterLabel && <Text className="mb-2">{filterLabel}</Text>}- <Select- {...filterSelectProps}- mode={filterMode === "single" ? undefined : "multiple"}- style={{ width: "100%" }}- placeholder={filterPlaceholder}- value={filterMode === "single" ? selectedFilters[0] ?? undefined : selectedFilters}- onChange={(value: any) => {- if (filterMode === "single") {- onFiltersChange?.(value ? [value] : []);- } else {- onFiltersChange?.(value);- }- }}- options={filterOptions}- allowClear- />+ {filterLabel && <label className="text-sm font-medium text-gray-700 block mb-2">{filterLabel}</label>}- {filterMode === "single" ? (- <Combobox- items={optionValues}- value={selectedFilters[0] ?? null}- onValueChange={(next: string | null) => onFiltersChange?.(next ? [next] : [])}- itemToStringLabel={labelOf}- >- <ComboboxInput- className="w-full"- placeholder={filterPlaceholder}- aria-label={filterPlaceholder}- showClear={selectedFilters.length > 0}- />- {filterList}- </Combobox>- ) : (- <Combobox- multiple- items={optionValues}- value={selectedFilters}- onValueChange={(next: string[]) => onFiltersChange?.(next)}- >- <ComboboxChips className="w-full">- <ComboboxValue>- {(selected: string[]) =>- selected.map((value) => (- <ComboboxChip key={value} aria-label={labelOf(value)}>- {labelOf(value)}- </ComboboxChip>- ))- }- </ComboboxValue>- <ComboboxChipsInput- className="border-0 bg-transparent"- placeholder={filterPlaceholder}- aria-label={filterPlaceholder}- />- {selectedFilters.length > 0 && <ComboboxClear aria-label={`Clear ${filterLabel ?? "filters"}`} />}- </ComboboxChips>- {filterList}- </Combobox>- )}++ {filterControl}</div>)}