(Patch/bug fix) - UI, filter out litellm ui session tokens on Virtual Keys Page (#8568)

* fix key list endpoint

* _get_condition_to_filter_out_ui_session_tokens

* duration_in_seconds

* test_list_key_helper_team_filtering
This commit is contained in:
Ishaan Jaff 2025-02-15 16:25:57 -08:00 committed by GitHub
parent c8d31a209b
commit 1b4d3db170
2 changed files with 133 additions and 1 deletions

View file

@ -24,6 +24,7 @@ from fastapi import APIRouter, Depends, Header, HTTPException, Query, Request, s
import litellm
from litellm._logging import verbose_proxy_logger
from litellm.caching import DualCache
from litellm.constants import UI_SESSION_TOKEN_TEAM_ID
from litellm.litellm_core_utils.duration_parser import duration_in_seconds
from litellm.proxy._types import *
from litellm.proxy.auth.auth_checks import (
@ -1885,7 +1886,9 @@ async def _list_key_helper(
"""
# Prepare filter conditions
where: Dict[str, Union[str, Dict[str, str]]] = {}
where: Dict[str, Union[str, Dict[str, Any]]] = {}
where.update(_get_condition_to_filter_out_ui_session_tokens())
if user_id and isinstance(user_id, str):
where["user_id"] = user_id
if team_id and isinstance(team_id, str):
@ -1938,6 +1941,20 @@ async def _list_key_helper(
)
def _get_condition_to_filter_out_ui_session_tokens() -> Dict[str, Any]:
"""
Condition to filter out UI session tokens
"""
return {
"OR": [
{"team_id": None}, # Include records where team_id is null
{
"team_id": {"not": UI_SESSION_TOKEN_TEAM_ID}
}, # Include records where team_id != UI_SESSION_TOKEN_TEAM_ID
]
}
@router.post(
"/key/block", tags=["key management"], dependencies=[Depends(user_api_key_auth)]
)