@@ -941,15 +941,25 @@ def _parse_vecto_usage_metrics(self, u: Dict[str, Any]) -> VectoUsageMetrics:
941941 indexing = self ._parse_usage_metric (u ['indexing' ])
942942 )
943943
944- def usage (self , vector_space_id : int , year : int , month : int , ** kwargs ) -> MonthlyUsageResponse :
944+ def usage (self , year : int , month : int , vector_space_id : int = None , ** kwargs ) -> MonthlyUsageResponse :
945945 '''Return the usage metrics for the selected month
946946
947947 Args:
948- vector_space_id (int): The ID of the vector space.
949948 year (int): The year for the usage data.
950949 month (int): The month for the usage data.
950+ vector_space_id (int, optional): The ID of the vector space. Defaults to None.
951951 **kwargs: Other keyword arguments for clients other than `requests`
952+ Returns:
953+ MonthlyUsageResponse: Named tuple that contains the usage metrics for a specified vector space and month.
952954 '''
955+
956+ # Use provided vector_space_id or fallback to self.vector_space_id
957+ vector_space_id = vector_space_id or getattr (self , 'vector_space_id' , None )
958+
959+ # Raise an error if vector_space_id is still not available
960+ if vector_space_id is None :
961+ raise ValueError ("A vector space ID must be provided either as a parameter or set in the instance." )
962+
953963 url = f"/api/v0/space/{ vector_space_id } /usage/{ year } /{ month } "
954964 response = self ._client .get (url , ** kwargs )
955965 response_data = response .json ()
@@ -962,4 +972,4 @@ def usage(self, vector_space_id: int, year: int, month: int, **kwargs) -> Monthl
962972 usage = usage_metrics
963973 )
964974
965- return monthly_usage_response
975+ return monthly_usage_response
0 commit comments