Skip to main content

Cost Management - API Specification

Version: v1.0.0 | Status: Active | Last Updated: March 2026

1. Overview​

The cost_management module provides spend tracking, budgeting, and cost optimization. Supports multiple cost categories, budget alerts, and persistent storage backends (in-memory, JSON file).

2. Core Components​

2.1 Classes​

ClassDescription
CostTrackerRecords cost entries and generates summary reports
BudgetManagerCreates and monitors budgets with alert thresholds
CostStoreAbstract base for cost data persistence
InMemoryCostStoreEphemeral in-memory store for testing and development
JSONCostStorePersistent JSON-backed cost storage

2.2 Data Models​

ClassDescription
CostEntrySingle cost record (amount, category, timestamp, description)
CostSummaryAggregated cost report over a period
BudgetBudget definition (name, limit, period, alert thresholds)
BudgetAlertAlert triggered when spending exceeds a threshold

2.3 Enums​

EnumValues
CostCategoryCompute, storage, network, API, etc.
BudgetPeriodDaily, weekly, monthly, quarterly, annual

3. Usage Example​

from codomyrmex.cost_management import CostTracker, InMemoryCostStore, CostCategory

tracker = CostTracker(store=InMemoryCostStore())
tracker.record(amount=12.50, category=CostCategory.COMPUTE, description="GPU hours")

summary = tracker.summary()
print(f"Total: ${summary.total:.2f}")

4. Navigation​