mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-11 04:23:25 +00:00
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
This commit is contained in:
@@ -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}})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user