diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 3e50ba3ee55..f54bbd95a78 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -1055,9 +1055,21 @@ class PrismaClient: }, ) else: - response = await self.db.litellm_usertable.find_many( # type: ignore - order={"spend": "desc"}, take=limit, skip=offset - ) + # return all users in the table, get their key aliases ordered by spend + sql_query = """ + SELECT + u.*, + json_agg(v.key_alias) AS key_aliases + FROM + "LiteLLM_UserTable" u + LEFT JOIN "LiteLLM_VerificationToken" v ON u.user_id = v.user_id + GROUP BY + u.user_id + ORDER BY u.spend DESC + LIMIT $1 + OFFSET $2 + """ + response = await self.db.query_raw(sql_query, limit, offset) return response elif table_name == "spend": verbose_proxy_logger.debug( diff --git a/ui/litellm-dashboard/src/components/view_users.tsx b/ui/litellm-dashboard/src/components/view_users.tsx index 13446ae4311..815de35070e 100644 --- a/ui/litellm-dashboard/src/components/view_users.tsx +++ b/ui/litellm-dashboard/src/components/view_users.tsx @@ -158,6 +158,7 @@ const ViewUserDashboard: React.FC = ({ User ID + User Email User Role User Models User Spend ($ USD) @@ -168,8 +169,9 @@ const ViewUserDashboard: React.FC = ({ {userData.map((user: any) => ( {user.user_id} + {user.user_email} - {user.user_role ? user.user_role : "app_owner"} + {user.user_role ? user.user_role : ""} {user.models && user.models.length > 0