Files
zooqueen 7cac9bad5e feat(router): meter function invocations to commerce (exemplar)
Reference wiring of the DRY usage-metering hook into a non-LLM product.
Functions now bills per invocation through commerce (the billing source of
truth) — same balance gate + usage record the LLM/cloud path uses — via the
shared github.com/hanzoai/commerce/metering client. No bespoke billing logic.
(universe task #28)

- pkg/usagemeter: thin env-gated adapter over commerce/metering. Builds the
  client from FromEnv() and exposes a gorilla/mux-compatible middleware:
  balance gate (fail-closed) + post-invocation usage record, identity from
  gateway-minted X-User-Id/X-Org-Id, skips /router-healthz + /metrics, flat
  per-call price from FUNCTIONS_PRICE_PER_CALL_CENTS.
- router.go: single mux.Use(usagemeter.Middleware(logger)) line next to the
  existing metrics middleware. Transparent pass-through until COMMERCE_URL +
  COMMERCE_SERVICE_TOKEN (KMS-backed) are set, so safe to wire now.
- go.mod: add the metering require + local replace ONLY — no go-version bump,
  no indirect churn, no go.sum change, because commerce/metering is a
  standalone stdlib-only module (its own go.mod, go 1.24, zero deps). Pinned
  to the local checkout until hanzoai/commerce#41 merges + tags.
- 4 tests: pass-through when disabled, gate+record on success, 402 on empty
  balance, infra-path skip. All green; go vet + gofmt clean.
2026-06-19 09:37:05 -07:00
..
2025-05-18 22:27:45 +05:30
2025-05-18 22:27:45 +05:30
2025-05-18 22:27:45 +05:30