Files
ai-agent/docs/local-energy.md
Gabriel VidalandClaude Opus 5.5 d969112d92 feat(pricing): cut pricing, the parser's UsageMeter, project costs and the usage service over to ProviderRegistry (Wave 3B)
- conversations/pricing.py holds no table any more (MODEL_PRICES, FAMILY_FALLBACK,
  FAST_MULT, HAIKU_LONG, OPENAI_*, GEMINI_*, OTHER_PRICES, LOCAL_WATTS,
  ELECTRICITY_EUR_PER_KWH, EVOX2_*, PLAN_METER_AS, PLAN_FABLE_WEIGHT gone): a
  facade over the provider plugins' registry, same names and signatures;
  PRICE_BOOK / USD_PER_EUR / LOCAL_* derived lazily from the plugins;
  book_key() replaces openai_model / gemini_model; price_call() exposed.
- plugins/seed_registry.py: effective() = the bound store's registry when it
  has ever known a provider (strict plugin-only), else the default plugins
  read from PLUGINS_SEED_DIR / the plugins checkout / fixtures — offline
  parses, scripts and unit tests price with zero setup, no network.
- parser: each API call priced once through ProviderRegistry.price_call
  (UsageMeter.price) — list cost, cache share and the EVOX2's time from the
  CallCost, plan units passed apart into the meter; priceBook = price_book().
- projects/costs.py: rates + local outputWeight from provider-evox2's pricing.
- usage/service.remote_snapshots: one loop over the providers with a
  usageReader, GET /usage/{vendor} on the lab and online workers, the legacy
  /claude|opencode|agy/usage only on a 404 (or the lab not answering);
  per-vendor merge policies keep the exact old results.
- providers.py: per-id memo of the claiming pricer and the token-table key
  (fixed per registry) — the parse prices at the old speed.
- plugins/metering.py reads USD_PER_EUR at use time.

A/B: scripts/ab/pricing-dump.py --base 1e431f52 → identical (10104 lines);
scripts/ab/parse-ab.py --base 1e431f52 --chunked → 499 files × 2 modes,
0 differing; chunked == one-shot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 16:41:01 +01:00

5.2 KiB
Raw Permalink Blame History

What a local run costs

A conversation on the EVOX2's local models (pi's evox2 provider and its opencode twins evox2/<id>, served by the box's llm-server) has no API price. pi records costUSD: 0 for it. Its real cost is the box's time: the electricity the box draws while it works, plus a share of the box itself. The provider-evox2 plugin's local_energy pricing (read through backend/conversations/pricing.py → local_call) prices every local call that way, and the parser uses that price instead of the runner's zero.

The formula

For one call that kept the box busy for t seconds:

Wh          = W(model) × t / 3600
electricity = Wh / 1000 × tariff(date of the call)                 €
hardware    = t / 3600 × 2049 € / (5 years × busy hours per year)   €
cost        = (electricity + hardware) × USD_PER_EUR               $ (the book's unit)
  • t is the call's wall-clock duration, timed the way the parser times every call (turn_ms): from the transcript record that unblocked it (the prompt, or the last tool result) to the reply. An opencode step writes its usage only after its tools have run, so its duration comes from the step's first (content) record (_unpriced[…]["ms"]), not from the usage record. Anything longer than an hour is treated as a stall and capped there.
  • Time, not tokens. llm-server reuses its prompt cache without reporting it, so a run's token counts don't track how long the box worked. The qwen 3.6 runs to date billed 116 M input tokens in all; prefilling those cold would have taken ~40 h, but the box worked 15.6 h.
  • Full wall power. The ~9 W the box draws while idle counts too: that is what the plug measures while the model works.
  • Hardware. Gabriel's choice (2026-11-01 form): €2049, straight-line over 5 years, spread over the hours the box is busy (above 30 W), not over every hour of the year. At ~7 % utilisation that makes a busy hour cost ~€0.67 of hardware against ~€0.02 of electricity. Utilisation drives the local cost, not the electricity price.
  • Tokens stay free (OTHER_PRICES["qwen-local"] = 0) and count for no plan. The hourly meterBins, which feed the plan calibration, leave local calls out.

The measurements (2026-10-09 → 11-01, Performance mode)

The source is the Tuya plug under the box → Home Assistant sensor.evox2_wall_power (services/home-assistant/config/packages/evox2_power.yaml in the homelab; it reads 0 W while the plug is off) → Prometheus homeassistant_sensor_power_w, kept 30 days.

qwen 3.6 35B-A3B, during its calls 111 W (13.8 h of calls)
qwen 3.8 27B 116 W (2.8 h)
qwen 3.8 Flash-Next Coder 138 W (0.4 h)
any other local model 112 W (the pricing's defaultWatts)
awake, idle 9 W (median)
asleep / plug off ≤ 5 W
busy (> 30 W) 38 h in 22.9 days → 613 h/year
the whole box, 22.9 days 7.2 kWh ≈ €1.44

Re-fit them with:

scripts/local-energy-calibration.py                 # last 30 days (Prometheus' retention)
scripts/local-energy-calibration.py --since 2026-10-15 --json out.json

It prints the per-model mean wall power over the calls' windows (only windows that hold a plug sample), the busy hours per year and the idle draw. Copy the figures into the provider-evox2 plugin by hand (each model's watts, the pricing's busyHoursPerYear), bump its pricing bookDate, and bump the indexer's PARSER_VERSION so every stored summary is re-priced.

The tariff

electricityTariffs (in provider-evox2's pricing) is a dated table: EDF Tarif Bleu, option Base, 6 kVA, TTC. Each call is priced at the tariff in force on its own date. The regulated tariff changes on 1 February and 1 August; add one line each time (and bump PARSER_VERSION). Values: 0.1940 € from 2026-02-01, 0.2001 € from 2026-08-01.

The book is in USD, and € converts at USD_PER_EUR = 1 / 0.92, the frontend's default usdToEur. With that default, a € shown in the app matches the € entered in the book.

Where it shows

  • The summary's local field (seconds, wh, electricity, hardware; USD) is set whenever a local model ran, and cost includes it everywhere: cards, totals, dashboards, project and skill rollups.
  • On a conversation card, a ⚡ Wh chip sits under the cost, in the slot the plan-% chip takes on Claude runs. Its tooltip splits electricity from hardware.
  • The Details drawer has an EVOX2 time card: box time, electricity with its Wh, hardware.
  • Footprint comes from the measured kWh, not the Claude token factors: France's consumption mix, 0.0461 kgCO2e/kWh (ADEME Base Empreinte, « Électricité 2025 – mix moyen – consommation »). Water is the Jegham et al. off-site WUE only (3.142 L/kWh); there is no data-centre cooling at home. The dashboards apply the Claude token estimate only to the Claude models of such a run. analytics.modelFamily files every other id under "opus", which would otherwise charge a local run Opus's carbon.
  • In the token-type split, a local model's cost is divided by the box's time per token type: llm-server decodes ~16× slower than it prefills, and its prompt cache is free (costAnalysis.ts, LOCAL_OUTPUT_WEIGHT).