# `Agentic.LLM.SpendTracker`

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 dashboards

The 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).

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `for_canonical`

Return spend windows for a canonical model id.

# `for_provider`

Return spend windows for a provider.

# `snapshot`

Return current spend windows. Filter by `:period` (`:daily | :monthly`),
`:provider`, or `:since` (DateTime).

# `start_link`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
