Skip to content

[Admin][API] Meter platform-paid AI into the ledger (embeddings/summaries/translation) #44

Closed

Description

@serge-ivo

Follow-up split from #32 (PR #43). The platform-paid env.AI calls are not written to ai_usage, so platform spend is invisible in-app.

Instrument the platform call sites to ledger with provider="platform" + a CF Workers-AI neuron cost estimate (label it an estimate):

  • agent-storage.ts embeddings (@cf/baai/bge-base-en-v1.5, ~line 345) and conversation summary (~line 988) — needs the acting/owner userId threaded into the DO storage engine (getStorageEngine).
  • routes/instances-translation.ts platform path (has session.uid; the CF .run returns no token usage → estimate tokens from text length).
  • Add a CF-neuron estimator to lib/ai-pricing.ts so platform CF rows carry non-zero cost (BYOK-CF stays estimate-free — user pays CF directly).

Once done, /v1/admin/spending platformPaid.metered flips true and the split in aggregateAdminUsage (already provider-aware, PLATFORM_PROVIDER) populates automatically.

Part of the PAGS Admin Portal epic (#27). Depends on #28.

Activity

  1. serge-ivo commented on Aug 1, 2026

    @serge-ivo
    ContributorAuthor

    Done — landed on main as 8ea80e2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    admin-portalPAGS admin/operator portalenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions