From bd0369dd887e3fb9f630c6e25d6962f42635a0b5 Mon Sep 17 00:00:00 2001 From: Fabricio Ceschin Date: Wed, 21 May 2025 13:35:21 -0400 Subject: [PATCH] Using typed dict in usage_details --- litellm/integrations/langfuse/langfuse.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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: