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]

Using typed dict in usage_details

Fabricio Ceschinbd0369dd887e
diff --git a/litellm/integrations/langfuse/langfuse.py b/litellm/integrations/langfuse/langfuse.py
index a98771387c0..f116eb8041b 100644
--- a/litellm/integrations/langfuse/langfuse.py
+++ b/litellm/integrations/langfuse/langfuse.py
@@ -642,7 +642,7 @@ class LangFuseLogger:
generation_id = None
usage = None
- usage_details : Optional[LangfuseUsageDetails] = None
+ usage_details = None
if response_obj is not None:
if (
hasattr(response_obj, "id")
@@ -659,12 +659,10 @@ class LangFuseLogger:
"completion_tokens": _usage_obj.completion_tokens,
"total_cost": cost if self._supports_costs() else None,
}
- usage_details = {
- "input": _usage_obj.prompt_tokens,
- "output": _usage_obj.completion_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)
- }
+ usage_details = LangfuseUsageDetails(input=_usage_obj.prompt_tokens,
+ output=_usage_obj.completion_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))
generation_name = clean_metadata.pop("generation_name", None)
if generation_name is None: