mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
fix(spend_tracking_utils.py): revert api key pass through fix (#7977)
* fix(spend_tracking_utils.py): revert api key pass through fix * fix: fix linting error * fix(spend_tracking_utils.py): add noqa - refactor post fixing standard logging payload on pass-through endpoints * test(test_groq.py): bump groq model * fix: fix positioning of noqa
This commit is contained in:
parent
67e9dbcc98
commit
e01c9c1fc6
2 changed files with 25 additions and 4 deletions
|
@ -58,7 +58,9 @@ def _get_spend_logs_metadata(metadata: Optional[dict]) -> SpendLogsMetadata:
|
|||
return clean_metadata
|
||||
|
||||
|
||||
def get_logging_payload(kwargs, response_obj, start_time, end_time) -> SpendLogsPayload:
|
||||
def get_logging_payload( # noqa: PLR0915
|
||||
kwargs, response_obj, start_time, end_time
|
||||
) -> SpendLogsPayload:
|
||||
from litellm.proxy.proxy_server import general_settings, master_key
|
||||
|
||||
if kwargs is None:
|
||||
|
@ -84,8 +86,27 @@ def get_logging_payload(kwargs, response_obj, start_time, end_time) -> SpendLogs
|
|||
)
|
||||
|
||||
end_user_id = get_end_user_id_for_cost_tracking(litellm_params)
|
||||
if standard_logging_payload is not None:
|
||||
api_key = standard_logging_payload["metadata"].get("user_api_key_hash") or ""
|
||||
|
||||
api_key = metadata.get("user_api_key", "")
|
||||
|
||||
if api_key is not None and isinstance(api_key, str):
|
||||
if api_key.startswith("sk-"):
|
||||
# hash the api_key
|
||||
api_key = hash_token(api_key)
|
||||
if (
|
||||
_is_master_key(api_key=api_key, _master_key=master_key)
|
||||
and general_settings.get("disable_adding_master_key_hash_to_db") is True
|
||||
):
|
||||
api_key = "litellm_proxy_master_key" # use a known alias, if the user disabled storing master key in db
|
||||
|
||||
if (
|
||||
standard_logging_payload is not None
|
||||
): # [TODO] migrate completely to sl payload. currently missing pass-through endpoint data
|
||||
api_key = (
|
||||
api_key
|
||||
or standard_logging_payload["metadata"].get("user_api_key_hash")
|
||||
or ""
|
||||
)
|
||||
end_user_id = end_user_id or standard_logging_payload["metadata"].get(
|
||||
"user_api_key_end_user_id"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue