Merge pull request #1574 from BerriAI/litellm_fix_streaming_spend_tracking

[WIP] fix(utils.py): fix proxy streaming spend tracking
This commit is contained in:
Krish Dholakia 2024-01-23 17:07:40 -08:00 committed by GitHub
commit 4ca4913468
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 179 additions and 23 deletions

View file

@ -856,10 +856,15 @@ def get_logging_payload(kwargs, response_obj, start_time, end_time):
usage = response_obj["usage"]
id = response_obj.get("id", str(uuid.uuid4()))
api_key = metadata.get("user_api_key", "")
if api_key is not None and type(api_key) == str:
if api_key is not None and isinstance(api_key, str) and api_key.startswith("sk-"):
# hash the api_key
api_key = hash_token(api_key)
if "headers" in metadata and "authorization" in metadata["headers"]:
metadata["headers"].pop(
"authorization"
) # do not store the original `sk-..` api key in the db
payload = {
"request_id": id,
"call_type": call_type,