Documentation Index
Fetch the complete documentation index at: https://mintlify.com/holzerjm/civichacks-demo/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Thecost_estimator.py module calculates the actual electricity cost of local LLM inference and compares it to published cloud API pricing. It’s used by all demo scripts to show cost savings in real-time.
Location: scripts/cost_estimator.py
Key functions
detect_power_watts()
Auto-detects hardware wattage based on your system.
Apple Silicon detection
Apple Silicon detection
Checks
platform.machine() for ARM architecture, then uses sysctl to read the CPU brand string:- If “max” or “ultra” in brand → 50W (M_-Max chips)
- If “pro” in brand → 35W (M_-Pro chips)
- Otherwise → 15W (M1/M2/M3/M4 base)
x86 detection
x86 detection
Defaults to laptop profile:
- x86 laptop (CPU-only) → 45W
- Desktop profiles available but not auto-detected
These are conservative whole-system estimates including screen, SSD, and RAM during inference.
estimate_local_cost(duration_secs, watts=None)
Calculates the electricity cost of a local inference run.
estimate_cloud_cost(input_tokens, output_tokens, model="GPT-4o")
Calculates what a cloud API would charge for the same query.
format_cost_comparison(duration_secs, input_tokens, output_tokens, watts=None)
Formats a one-line cost comparison for terminal output.
format_cost_short(duration_secs, input_tokens, output_tokens, watts=None)
Shorter format for inline display (e.g., Gradio chat metadata).
Usage examples
Step 1: Terminal output (demo_step1_ollama.py)
Step 1: Terminal output (demo_step1_ollama.py)
Step 3: Gradio chat metadata (demo_step3_app.py)
Step 3: Gradio chat metadata (demo_step3_app.py)
Real-world cost examples
Short query (50 input tokens, 100 output tokens, 8 seconds)
| Metric | Value |
|---|---|
| Local energy | 0.033 Wh |
| Local cost | $0.000006 |
| GPT-4o cost | $0.0011 |
| Savings ratio | 183x |
Medium query (200 input tokens, 300 output tokens, 25 seconds)
| Metric | Value |
|---|---|
| Local energy | 0.104 Wh |
| Local cost | $0.000019 |
| GPT-4o cost | $0.0035 |
| Savings ratio | 184x |
Long query (500 input tokens, 800 output tokens, 60 seconds)
| Metric | Value |
|---|---|
| Local energy | 0.250 Wh |
| Local cost | $0.000045 |
| GPT-4o cost | $0.0093 |
| Savings ratio | 207x |
Customization
Change the electricity rate
Edit the constant inscripts/cost_estimator.py:
Add new cloud models
Add entries to theCLOUD_PRICING dictionary:
Override power detection
Passwatts explicitly to any function: