feat(billing): per-tenant usage metering + usage API + invoice generation (Step 7.9) - #182
Merged
Merged
Conversation
…tion (Step 7.9) Per-tenant usage accounting, mirroring the 5.6c cost pattern (dataclasses in rag-observability, the gateway wraps a Pydantic response — no dist/schemas churn). - rag_observability.billing: UsageMeter (observe-only per-tenant, per-dimension counters: queries/docs_ingested/storage_gb/reranker_calls/llm_tokens), UsageSnapshot, pure generate_invoice + PricingModel/load_pricing (priced from marketplace/pricing.yaml; reconciles with usage ±0.5% by construction), and a BillingProvider Protocol seam (Stripe/marketplace, degrade-open). - GET /v1/billing/usage (BillingUsageResponse) serves the per-tenant dashboard; fed from record_request_usage independent of quotas; inert by default (cfg.billing). - ragctl billing drives meter→invoice→reconcile. No governed SPI call (policy-coverage unchanged). Only dist/openapi + dist/rag.schema regenerate. Verified: ruff, mypy --strict (330), billing unit + gateway endpoint + ragctl tests, drift gates regenerated. ADR-0051, reference/billing.md. Deferred: concrete Stripe/marketplace adapters, docs/reranker/storage feed points, admin usage card. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
officialCodeWork
force-pushed
the
build/phase-7/step-7.9-billing-metering
branch
from
June 9, 2026 21:51
1e44863 to
ac33111
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 7.9 — billing & metering. Per-tenant usage accounting that mirrors the 5.6c cost pattern (dataclasses in
rag-observability, gateway wraps a Pydantic response → nodist/schemaschurn): an observe-onlyUsageMeter(5 dimensions) fed fromrecord_request_usageindependent of quotas,GET /v1/billing/usage, a puregenerate_invoicepriced frommarketplace/pricing.yaml(reconciles with usage ±0.5% by construction), and aBillingProviderStripe/marketplace seam.cfg.billing(inert by default),ragctl billing, ADR-0051, reference/billing.md. No governed SPI call. Verified: ruff, mypy --strict (330), billing unit + gateway endpoint + ragctl tests, openapi/config drift regenerated. CI red = org Actions billing (unrelated). 🤖 Generated with Claude Code