feat(proxy_server.py): support cost tracking on user id via JWT-Auth

allows admin to track cost for LiteLLM_UserTable via JWT
This commit is contained in:
Krrish Dholakia 2024-04-11 18:47:46 -07:00
parent a9285710d1
commit 4b2d13322e
4 changed files with 59 additions and 24 deletions

View file

@ -74,6 +74,16 @@ class JWTHandler:
team_id = default_value
return team_id
def get_user_id(self, token: dict, default_value: Optional[str]) -> Optional[str]:
try:
if self.litellm_jwtauth.user_id_jwt_field is not None:
user_id = token[self.litellm_jwtauth.user_id_jwt_field]
else:
user_id = None
except KeyError:
user_id = default_value
return user_id
def get_scopes(self, token: dict) -> list:
try:
if isinstance(token["scope"], str):