@@ -875,22 +875,28 @@ def _parse_usage_model(usage: typing.Union[pydantic.BaseModel, dict]) -> Any:
875875 usage_model = cast (Dict , usage .copy ()) # Copy all existing key-value pairs
876876
877877 # Skip OpenAI usage types as they are handled server side
878- if not all (
878+ if all (
879879 openai_key in usage_model
880- for openai_key in ["prompt_tokens" , "completion_tokens" , "total_tokens" ]
880+ for openai_key in [
881+ "prompt_tokens" ,
882+ "completion_tokens" ,
883+ "total_tokens" ,
884+ "prompt_tokens_details" ,
885+ "completion_tokens_details" ,
886+ ]
881887 ):
882- for model_key , langfuse_key in conversion_list :
883- if model_key in usage_model :
884- captured_count = usage_model . pop ( model_key )
885- final_count = (
886- sum ( captured_count )
887- if isinstance ( captured_count , list )
888- else captured_count
889- ) # For Bedrock, the token count is a list when streamed
890-
891- usage_model [ langfuse_key ] = (
892- final_count # Translate key and keep the value
893- )
888+ return usage_model
889+
890+ for model_key , langfuse_key in conversion_list :
891+ if model_key in usage_model :
892+ captured_count = usage_model . pop ( model_key )
893+ final_count = (
894+ sum ( captured_count )
895+ if isinstance ( captured_count , list )
896+ else captured_count
897+ ) # For Bedrock, the token count is a list when streamed
898+
899+ usage_model [ langfuse_key ] = final_count # Translate key and keep the value
894900
895901 if isinstance (usage_model , dict ):
896902 if "input_token_details" in usage_model :
0 commit comments