Skip to content

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]

litellm always log cache_key on hits/misses

Ishaan Jaffa59ed00fd3cb
diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py
index e7fb8bb482e..d6c235d0cb7 100644
--- a/litellm/integrations/langfuse.py
+++ b/litellm/integrations/langfuse.py
@@ -605,6 +605,12 @@ class LangFuseLogger:
if "cache_key" in litellm.langfuse_default_tags:
_hidden_params = metadata.get("hidden_params", {}) or {}
_cache_key = _hidden_params.get("cache_key", None)
+ if _cache_key is None:
+ # fallback to using "preset_cache_key"
+ _preset_cache_key = kwargs.get("litellm_params", {}).get(
+ "preset_cache_key", None
+ )
+ _cache_key = _preset_cache_key
tags.append(f"cache_key:{_cache_key}")
return tags