Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# mindroot.coreplugins.usage package

## Submodules

## mindroot.coreplugins.usage.handlers module

class mindroot.coreplugins.usage.handlers.UsageTracker(storage: UsageStorage)

  Bases: `object`

  async get_cost(plugin_id: str, cost_type_id: str, model_id: str | None = None) → float

    Get the cost for a specific usage type and optional model

  async get_total_cost(username: str, start_date=None, end_date=None)

    Get total cost for a user

  async get_usage(username: str, start_date=None, end_date=None)

    Get usage records for a user

  async track_usage(event: UsageEvent)

    Track a usage event and store it with calculated cost

## mindroot.coreplugins.usage.mod module

mindroot.coreplugins.usage.mod.get_base_path() → str

async mindroot.coreplugins.usage.mod.get_cost(plugin_id: str, cost_type_id: str, model_id: str | None = None, context=None) → float

async mindroot.coreplugins.usage.mod.get_cost_summary(username: str, start_date: str | None = None, end_date: str | None = None, context=None) → Dict

  Get a cost summary for a user.

async mindroot.coreplugins.usage.mod.get_cost_types(context=None)

  Get all registered cost types.

async mindroot.coreplugins.usage.mod.get_daily_costs(username: str, start_date: str | None = None, end_date: str | None = None, context=None) → Dict

  Get daily cost breakdown for a user.

async mindroot.coreplugins.usage.mod.get_usage_report(username: str, start_date: str | None = None, end_date: str | None = None, context=None) → Dict

  Get a detailed usage report for a user.

async mindroot.coreplugins.usage.mod.register_cost_type(plugin_id: str, cost_type_id: str, description: str, unit: str, context=None)

  Register a new cost type for a plugin.

async mindroot.coreplugins.usage.mod.set_cost(plugin_id: str, cost_type_id: str, unit_cost: float, model_id: str | None = None, context=None)

  Set the cost for a specific usage type.

async mindroot.coreplugins.usage.mod.track_usage(plugin_id: str, cost_type_id: str, quantity: float, metadata: dict, context=None, model_id: str | None = None)

  Track usage for a plugin.

## mindroot.coreplugins.usage.models module

class mindroot.coreplugins.usage.models.CostTypeInfo(name, description, unit)

  Bases: `NamedTuple`

  description: str

    Alias for field number 1

  name: str

    Alias for field number 0

  unit: str

    Alias for field number 2

class mindroot.coreplugins.usage.models.UsageEvent(timestamp: datetime.datetime, plugin_id: str, cost_type_id: str, quantity: float, metadata: Dict[str, Any], username: str, model_id: Optional[str] = None, session_id: Optional[str] = None, request_id: str = <factory>)

  Bases: `object`

  cost_type_id: str
  metadata: Dict[str, Any]
  model_id: str | None = None
  plugin_id: str
  quantity: float
  request_id: str
  session_id: str | None = None
  timestamp: datetime
  to_dict() → dict
  username: str

## mindroot.coreplugins.usage.reporting module

class mindroot.coreplugins.usage.reporting.UsageReport(storage: UsageStorage)

  Bases: `object`

  async get_cost_summary(username: str, start_date: date | None = None, end_date: date | None = None) → Dict

    Generate a simplified cost summary for a user

  async get_daily_costs(username: str, start_date: date | None = None, end_date: date | None = None) → Dict

    Generate daily cost breakdown for a user

  async get_user_report(username: str, start_date: date | None = None, end_date: date | None = None) → Dict

    Generate a complete usage report for a user

## mindroot.coreplugins.usage.router module

mindroot.coreplugins.usage.router.get_base_path()

async mindroot.coreplugins.usage.router.get_user_daily(request: Request, username: str, start_date: str | None = None, end_date: str | None = None)

  Get daily cost breakdown for a specific user

async mindroot.coreplugins.usage.router.get_user_report(request: Request, username: str, start_date: str | None = None, end_date: str | None = None)

  Get usage report for a specific user

async mindroot.coreplugins.usage.router.get_user_summary(request: Request, username: str, start_date: str | None = None, end_date: str | None = None)

  Get cost summary for a specific user

async mindroot.coreplugins.usage.router.update_costs(request: Request)

  Update cost configuration

async mindroot.coreplugins.usage.router.usage_admin(request: Request)

  Admin interface for usage tracking configuration

## mindroot.coreplugins.usage.storage module

class mindroot.coreplugins.usage.storage.UsageStorage(base_path: str)

  Bases: `object`

  async get_total_cost(username: str, start_date: date | None = None, end_date: date | None = None) → float

    Calculate total cost for a user within date range

  async get_usage(username: str, start_date: date | None = None, end_date: date | None = None) → List[Dict]

    Get usage records for a user within date range

  async load_cost_types() → Dict

    Load cost type definitions

  async load_costs() → Dict

    Load cost configurations

  async save_cost(plugin_id: str, cost_type_id: str, unit_cost: float, model_id: str | None = None)

    Save a cost configuration

  async save_cost_type(cost_type_id: str, info: Dict)

    Save a cost type definition

  async store_event(event: UsageEvent, cost: float)

    Store a usage event with its calculated cost

## Module contents