The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Fix langfuse input tokens logic for cached tokens (#16203)
Fabrício Ceschin387982fcbf07
diff --git a/litellm/integrations/langfuse/langfuse.py b/litellm/integrations/langfuse/langfuse.pyindex a067d285245..b71cba62046 100644--- a/litellm/integrations/langfuse/langfuse.py+++ b/litellm/integrations/langfuse/langfuse.py@@ -688,16 +688,19 @@ class LangFuseLogger:"completion_tokens": _usage_obj.completion_tokens,"total_cost": cost if self._supports_costs() else None,}+ cache_read_input_tokens = _usage_obj.get(+ "cache_read_input_tokens", 0+ )+ # According to langfuse documentation: "the input value must be reduced by the number of cache_read_input_tokens"+ input_tokens = _usage_obj.prompt_tokens - cache_read_input_tokensusage_details = LangfuseUsageDetails(- input=_usage_obj.prompt_tokens,+ input=input_tokens,output=_usage_obj.completion_tokens,total=_usage_obj.total_tokens,cache_creation_input_tokens=_usage_obj.get("cache_creation_input_tokens", 0),- cache_read_input_tokens=_usage_obj.get(- "cache_read_input_tokens", 0- ),+ cache_read_input_tokens=cache_read_input_tokens,)generation_name = clean_metadata.pop("generation_name", None)