Skip to content

Add tenant column to ai_usage_events for centralized hosted billing across ORB + AMS #7176

Description

@JSONbored

Problem

ai_usage_events (src/db/schema.ts) already records AI usage/cost per event, but has no installation_id/tenant column — identity today is only recoverable indirectly via actor/route/metadata_json. A central hosted-billing aggregator (shared by both ORB and AMS once AMS's storage migration lands) needs a real tenant column to attribute usage without parsing free-form metadata.

Area

src/db/schema.ts (aiUsageEvents), src/db/repositories.ts (recordAiUsageEvent and its callers), a new migration.

Proposal

Add an installation_id (or tenant_id) column, backfill-nullable for existing self-host rows (self-host has no installation concept and should keep working unchanged), populated going forward by hosted containers at insert time.

Note this table double-purposes as a BYOK key-lifecycle audit log too (model prefixed byok:...) — the new column applies to both purposes; don't special-case one away.

Deliverables

  • Migration adding the column
  • recordAiUsageEvent accepts and writes it
  • Existing self-host call sites unaffected (column nullable, no behavior change when absent)
  • A basic aggregation query (e.g. sumAiCostForTenantSince) mirroring the existing sumAiEstimatedNeuronsSince/sumByokAiUsageForRepoSince pattern

Links & Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:featureGittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.help wantedExtra attention is needed

    Projects

    Status
    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions