From e69d9fde8a3a0509419980db6e2827d8e31abb76 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Tue, 16 Sep 2025 16:47:25 -0700 Subject: [PATCH] fix(key_management_endpoints.py): include created by keys in `/key/list` Allow user to see service account keys they've created Fixes https://github.com/BerriAI/litellm/issues/14183 --- .../management_endpoints/key_management_endpoints.py | 9 +++++++++ ui/litellm-dashboard/src/components/networking.tsx | 1 + 2 files changed, 10 insertions(+) diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index 8dac7685f1..026ae9e405 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -2462,6 +2462,9 @@ async def list_keys( include_team_keys: bool = Query( False, description="Include all keys for teams that user is an admin of." ), + include_created_by_keys: bool = Query( + False, description="Include keys created by the user" + ), sort_by: Optional[str] = Query( default=None, description="Column to sort by (e.g. 'user_id', 'created_at', 'spend')", @@ -2524,6 +2527,7 @@ async def list_keys( return_full_object=return_full_object, organization_id=organization_id, admin_team_ids=admin_team_ids, + include_created_by_keys=include_created_by_keys, sort_by=sort_by, sort_order=sort_order, ) @@ -2601,6 +2605,7 @@ async def _list_key_helper( admin_team_ids: Optional[ List[str] ] = None, # New parameter for teams where user is admin + include_created_by_keys: bool = False, sort_by: Optional[str] = None, sort_order: str = "desc", ) -> KeyListResponseObject: @@ -2650,6 +2655,10 @@ async def _list_key_helper( if user_condition: or_conditions.append(user_condition) + # Add condition for created by keys if provided + if include_created_by_keys and user_id: + or_conditions.append({"created_by": user_id}) + # Add condition for admin team keys if provided if admin_team_ids: or_conditions.append({"team_id": {"in": admin_team_ids}}) diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx index 8855b1b843..7a5ca76b6a 100644 --- a/ui/litellm-dashboard/src/components/networking.tsx +++ b/ui/litellm-dashboard/src/components/networking.tsx @@ -3270,6 +3270,7 @@ export const keyListCall = async ( } queryParams.append("return_full_object", "true"); queryParams.append("include_team_keys", "true"); + queryParams.append("include_created_by_keys", "true"); const queryString = queryParams.toString(); if (queryString) {