mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
fix(spend-tracking): guard json decode and clamp negative base model cost
This commit is contained in:
parent
a7c2d25dcb
commit
beb83c3b8d
1 changed files with 5 additions and 2 deletions
|
|
@ -324,7 +324,10 @@ class DBSpendUpdateWriter:
|
|||
if not metadata_str:
|
||||
return None
|
||||
|
||||
metadata: SpendLogsMetadata = json.loads(metadata_str)
|
||||
try:
|
||||
metadata: SpendLogsMetadata = json.loads(metadata_str)
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
return None
|
||||
response_model = metadata.get("response_model")
|
||||
if not response_model:
|
||||
return None
|
||||
|
|
@ -336,7 +339,7 @@ class DBSpendUpdateWriter:
|
|||
router_flat_cost = additional_costs.get("azure_model_router_flat_cost", 0.0)
|
||||
|
||||
total_spend = payload.get("spend", 0) or 0
|
||||
base_model_cost = total_spend - router_flat_cost
|
||||
base_model_cost = max(0.0, total_spend - router_flat_cost)
|
||||
|
||||
# Router entry: flat cost only, no tokens
|
||||
router_payload = cast(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue