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(key_management_endpoints.py): include created by keys in `/key/list`

Krrish Dholakiae69d9fde8a3a
diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py
index 8dac7685f16..026ae9e4056 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 8855b1b8435..7a5ca76b6a5 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) {