-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Labels
Description
What happened?
The cost_per_token() function sometimes returns negative input cost when using cached prompts with bedrock anthropic models. It seems cache_creation_input_tokens and cache_read_input_tokens are subtracted from the prompt_tokens, resulting in a negative value.
Update: This issue seems to be related to claude 4.5. Everything looks legit after downgrading to claude 4.
Relevant log output
# minimal reproduction code
# token counts are taken from the usage object
from litellm import cost_per_token
print(cost_per_token(
model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
completion_tokens=497,
prompt_tokens=22475,
cache_creation_input_tokens=7183,
cache_read_input_tokens=22465,
))
# Output: (-0.132944625, 0.008200500000000001)Are you a ML Ops Team?
No
What LiteLLM version are you on ?
v1.77.7
Twitter / LinkedIn details
No response