[docs]asyncdefget_cost(self,plugin_id:str,cost_type_id:str,model_id:Optional[str]=None)->float:"""Get the cost for a specific usage type and optional model"""costs=awaitself.storage.load_costs()try:plugin_costs=costs[plugin_id]type_costs=plugin_costs[cost_type_id]# Try model-specific cost firstifmodel_idand'model_specific'intype_costs:ifmodel_idintype_costs['model_specific']:returntype_costs['model_specific'][model_id]# Fall back to default costreturntype_costs.get('default',0.0)exceptExceptionase:trace=traceback.format_exc()logger.error(f"Error getting cost: {e}\n\n{trace}")return0.0
[docs]asyncdeftrack_usage(self,event:UsageEvent):"""Track a usage event and store it with calculated cost"""unit_cost=awaitself.get_cost(event.plugin_id,event.cost_type_id,event.model_id)total_cost=unit_cost*event.quantityawaitself.storage.store_event(event,total_cost)
[docs]asyncdefget_usage(self,username:str,start_date=None,end_date=None):"""Get usage records for a user"""returnawaitself.storage.get_usage(username,start_date,end_date)
[docs]asyncdefget_total_cost(self,username:str,start_date=None,end_date=None):"""Get total cost for a user"""returnawaitself.storage.get_total_cost(username,start_date,end_date)