orka.agents.local_cost_calculator module
Local LLM Cost Calculator
Calculates real operating costs for local LLM inference including: 1. Electricity consumption during inference 2. Hardware amortization (GPU/CPU depreciation) 3. Optional cloud compute costs
No more fantasy $0.00 costs - local models have real expenses.
- class orka.agents.local_cost_calculator.CostPolicy(value)[source]
Bases:
Enum
Cost calculation policies for local LLMs
- CALCULATE = 'calculate'
- NULL_FAIL = 'null_fail'
- ZERO_LEGACY = 'zero_legacy'
- class orka.agents.local_cost_calculator.LocalCostCalculator(policy: str = 'calculate', electricity_rate_usd_per_kwh: float = None, hardware_cost_usd: float = None, hardware_lifespan_months: int = 36, gpu_tdp_watts: float = None, cpu_tdp_watts: float = None)[source]
Bases:
object
Calculate real operating costs for local LLM inference.
Cost components: 1. Electricity: GPU/CPU power consumption during inference 2. Hardware amortization: Depreciation of compute hardware 3. Cloud costs: If running on rented cloud infrastructure
- __init__(policy: str = 'calculate', electricity_rate_usd_per_kwh: float = None, hardware_cost_usd: float = None, hardware_lifespan_months: int = 36, gpu_tdp_watts: float = None, cpu_tdp_watts: float = None)[source]
Initialize cost calculator.
- Parameters:
policy – “calculate”, “null_fail”, or “zero_legacy”
electricity_rate_usd_per_kwh – Local electricity rate (default: auto-detect)
hardware_cost_usd – Total hardware cost for amortization
hardware_lifespan_months – Hardware depreciation period
gpu_tdp_watts – GPU power consumption (default: auto-detect)
cpu_tdp_watts – CPU power consumption (default: auto-detect)
- calculate_inference_cost(latency_ms: float, tokens: int, model: str, provider: str = 'ollama') float | None [source]
Calculate the real cost of local LLM inference.
- Parameters:
latency_ms – Inference time in milliseconds
tokens – Total tokens processed
model – Model name for optimization estimation
provider – Local provider (ollama, lm_studio, etc.)
- Returns:
Cost in USD, or None if null_fail policy
- Raises:
ValueError – If null_fail policy is enabled
- orka.agents.local_cost_calculator.get_cost_calculator() LocalCostCalculator [source]
Get the global cost calculator instance.
- orka.agents.local_cost_calculator.calculate_local_llm_cost(latency_ms: float, tokens: int, model: str, provider: str = 'ollama') float | None [source]
Calculate local LLM inference cost.
Convenience function that uses the global calculator.
- Returns:
Cost in USD, or None if null_fail policy
- Raises:
ValueError – If null_fail policy is enabled