Agentic.LLM.SpendTracker
(agentic v0.3.0)
Copy Markdown
Per-request cost accumulator backed by SQLite.
Subscribes to [:gateway, :request, :stop] telemetry from
Agentic.LLM.Gateway and writes one row per LLM request to
~/.agentic/spend.sqlite3. The Gateway already auto-injects its
base URL into Claude Code / OpenCode / Codex subprocesses via
Gateway.inject_env/2, so subprocess-driven LLM calls flow through
the same telemetry as in-process ones.
Schema
spend_events — one row per request (audit log for X-Ray)
spend_windows — materialized aggregate per (provider, account_id,
canonical_id, period, period_start) for dashboardsThe window row is upserted in the same transaction that inserts the event, so dashboard queries stay constant-time as the event log grows.
Currency
All amounts are Money.t() from :ex_money. The native currency is
preserved in the row; the dashboard normalizes for display. Sub-cent
precision is preserved via Decimal (Money's internal representation).
Summary
Functions
Returns a specification to start this module under a supervisor.
Return spend windows for a canonical model id.
Return spend windows for a provider.
Return current spend windows. Filter by :period (:daily | :monthly),
:provider, or :since (DateTime).
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Return spend windows for a canonical model id.
Return spend windows for a provider.
Return current spend windows. Filter by :period (:daily | :monthly),
:provider, or :since (DateTime).