Litellm dev 12 20 2024 p3 (#7339)

* fix(proxy_track_cost_callback.py): log to db if only end user param given

* fix: allows for jwt-auth based end user id spend tracking to work

* fix(utils.py): fix 'get_end_user_id_for_cost_tracking' to use 'user_api_key_end_user_id'

more stable - works with jwt-auth based end user tracking as well

* test(test_jwt.py): add e2e unit test to confirm end user cost tracking works for spend logs

* test: update test to use end_user api key hash param

* fix(langfuse.py): support end user cost tracking via jwt auth + langfuse

logs end user to langfuse if decoded from jwt token

* fix: fix linting errors

* test: fix test

* test: fix test

* fix: fix end user id extraction

* fix: run test earlier
This commit is contained in:
Krish Dholakia 2024-12-20 21:13:32 -08:00 committed by GitHub
parent 6107f9f3f3
commit 522da384b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 149 additions and 36 deletions

View file

@ -72,8 +72,12 @@ def safe_add_api_version_from_query_params(data: dict, request: Request):
query_params = dict(request.query_params)
if "api-version" in query_params:
data["api_version"] = query_params["api-version"]
except KeyError:
pass
except Exception as e:
verbose_logger.error("error checking api version in query params: %s", str(e))
verbose_logger.exception(
"error checking api version in query params: %s", str(e)
)
def convert_key_logging_metadata_to_callback(
@ -266,6 +270,7 @@ class LiteLLMProxyRequestSetup:
user_api_key_user_id=user_api_key_dict.user_id,
user_api_key_org_id=user_api_key_dict.org_id,
user_api_key_team_alias=user_api_key_dict.team_alias,
user_api_key_end_user_id=user_api_key_dict.end_user_id,
)
return user_api_key_logged_metadata