Skip to main content

Ai Usage

@webframp/ai-usagev2026.08.21.2· 1d agoMODELSWORKFLOWSREPORTS
01README

Unified cross-provider AI token usage monitoring — workflow, model, and report that aggregates Bedrock, Vertex AI, Azure OpenAI, and Anthropic (Claude Enterprise Analytics) token data into a single view.

Gracefully handles partial provider configurations. Unconfigured providers are shown with setup hints in the report output.

Quick Start

# Pull the extension (also pulls provider dependencies)
swamp extension pull @webframp/ai-usage

# Configure providers you use (any subset works)
swamp model create @webframp/aws/bedrock-usage bedrock-usage \
  --global-arg 'profiles=["default"]' --global-arg 'regions=["us-east-1"]'

swamp model create @webframp/gcp/vertex-usage vertex-usage \
  --global-arg 'projects=["my-project"]'

swamp model create @webframp/azure/openai-usage azure-ai-usage \
  --global-arg 'subscriptions=["sub-id"]'

swamp model create @webframp/anthropic/analytics claude-analytics \
  --global-arg 'analyticsKey=<vault-reference>'

# Create the unified model
swamp model create @webframp/ai-usage ai-usage

# Check provider status
swamp model method run ai-usage status

# Run the full scan workflow
swamp workflow run @webframp/ai-usage-scan

# Or generate report from existing data
swamp model method run ai-usage generate

Methods

  • status — Check which providers are configured, with setup hints
  • generate — Produce unified report from collected scan data

Workflow

  • @webframp/ai-usage-scan — Orchestrates scan across all configured providers then generates the unified report

Report

  • @webframp/ai-usage-report — Workflow-scope report for standalone use
02Release Notes

2026.08.21.2

Changed: The unified report's provider-coverage lookup used to swallow lookup failures silently — a provider was marked "Not configured" with no indication of whether it was truly unconfigured or the underlying findBySpec call failed (network error, malformed data, etc.). It now logs a warning naming the provider, model instance, resource spec, and the underlying error message before falling back to "Not configured," so a scan outage is distinguishable from a provider that was never set up.

03Models1
@webframp/ai-usagev2026.08.20.1ai_usage.ts
fn status()
Check which provider models are configured. Returns setup guidance
fn generate(days: number)
Generate a unified cross-provider AI usage report from collected scan data.
ArgumentTypeDescription
daysnumberExpected lookback period

Resources

status(1h)— Provider configuration status
report(6h)— Unified cross-provider AI usage report
04Workflows1
@webframp/ai-usage-scan239ea328-2c6d-4e77-8790-cda67e5715fe

Scan AI token usage across all configured providers (AWS Bedrock, GCP Vertex AI, Azure OpenAI, Anthropic Claude Enterprise) and generate a unified cross-provider report. Gracefully handles missing providers — unconfigured provider steps fail silently (allowFailure: true) and the report shows coverage gaps with setup hints. All steps (including `anthropic-usage`) are wired to the same `days` lookback so the unified report's per-minute rates share one consistent window. collect_user_usage reject

scanCollect token usage from each configured provider
1.aws-bedrockbedrock-usage.scan_accounts— Scan AWS Bedrock token usage across profiles/regions
2.gcp-vertexvertex-usage.scan_projects— Scan GCP Vertex AI token usage across projects
3.azure-openaiazure-ai-usage.scan_subscriptions— Scan Azure OpenAI token usage across subscriptions
4.anthropic-usageclaude-analytics.collect_user_usage— Per-user Claude Enterprise token usage + cost. days is capped at 31 by the method (the Analytics API's max window).
reportGenerate unified cross-provider usage report
1.generateai-usage.generate— Aggregate scan data into unified report with coverage hints
05Reports1
@webframp/ai-usage-reportworkflow
ai_usage_report.ts

Cross-provider AI token usage report with coverage status, per-provider breakdown, and highlights

aitoken-usagefinopsmonitoring
06Previous Versions14
2026.08.21.1

2026.08.21.1

Changed: Added descriptions to the previously undocumented fields in the ProviderSetupSchema, ProviderStatusSchema, StatusSchema, and ReportSchema resource schemas (setup guidance, coverage entries, and the unified report's per-provider/top-account/top-model/grand-totals fields). No behavioral change.

2026.08.20.1

Changed: Bump @webframp/aws/bedrock-usage 2026.08.05.1 → 2026.08.20.1

2026.08.15.1

Changed: Bump @webframp/aws/bedrock-usage 2026.08.02.1 → 2026.08.05.1

2026.08.14.1

Added: Anthropic (Claude Enterprise Analytics) as a fourth provider in the registry, sourced from @webframp/anthropic/analytics's userUsage resource (collect_user_usage method). Groups by user (keyed by email) with a per-product (claude_code, chat, etc.) breakdown, using the totals field that extension's 2026.08.14.1 release added specifically to match this registry's expected shape — no bespoke adapter code needed here.

Changed: Bumped the @webframp/azure/openai-usage dependency to 2026.08.14.4 (pagination + 429/5xx retry + dedup fixes) and added the @webframp/anthropic/analytics@2026.08.14.1 dependency (needed for its new days argument on collect_user_usage and the totals field on userUsage). Wired an anthropic-usage step into the @webframp/ai-usage-scan workflow using the same days input as the other providers, so the unified report's per-minute rates share one consistent window.

Fixed: lastScanned in status and generate fell back straight to the data-write timestamp when a provider's attributes had no scannedAt field. Anthropic's userUsage resource uses fetchedAt instead of scannedAt — both methods now check fetchedAt before falling back to the write timestamp, matching how the field is actually named across providers.

2026.08.11.1

Fixed: status and generate always reported every provider as unconfigured, even with valid scan data present. Both methods called context.dataRepository.findBySpec(modelName, specName), which does not exist on the method-execution context — only findAllForModel (metadata) and getContent (raw bytes) are available there. The call threw a TypeError on every invocation, silently caught and logged as a warning, so every provider always fell back to "unconfigured" regardless of actual scan state.

Fixed: The replacement findAllForModel-based lookup sorted results by calling .localeCompare() on createdAt, assuming it was a string — but swamp's real Data.createdAt is a Date object, so this threw on every invocation with scan data present. Sorting now uses Date.getTime(), and generate's error path now logs failures via context.logger.warn like status already did. Added a runtime shape guard on createdAt so a future mismatch between this extension's local type guess and swamp's actual API surfaces as a clear error instead of a silent miscalculation.

Upgrade note: No schema or behavioral changes to the status/report resource shapes — this is purely an internal data-access fix. Re-run swamp model method run ai-usage status after upgrading to see accurate coverage.

2026.08.05.1

Changed: Bump @webframp/aws/bedrock-usage 2026.08.01.1 → 2026.08.02.1

2026.08.02.1

Changed: Bump @webframp/aws/bedrock-usage 2026.07.29.1 → 2026.08.01.1

2026.07.31.2

Changed: Breaking schema change — the hint string field in status and report coverage entries is replaced by a setup object containing command, permissions (array of least-privilege IAM/RBAC permissions), and authNotes (authentication mechanism description). Consumers parsing the status resource must update to the new shape.

Changed: The extensionType field is now included in provider status entries (e.g. @webframp/aws/bedrock-usage).

Added: Setup guidance now includes the full model create command with all required arguments (including auth credentials for GCP and Azure that were previously missing), the exact permissions needed, and a description of how authentication works for each provider.

Added: Data-driven provider registry. Adding a new provider (Anthropic, Moonshot, etc.) requires only appending a ProviderDefinition object — no new code blocks in status, generate, or the report.

Changed: The report extension now imports provider definitions from the model, eliminating duplicated per-provider rendering logic.

Upgrade note: This is a breaking change. If you parse the status resource programmatically, update from provider.hint (string) to provider.setup (object with command, permissions, authNotes fields). Configured providers have these fields blanked (empty string / empty array).

2026.08.20.1

2026.08.20.1

Changed: Bump @webframp/aws/bedrock-usage 2026.08.05.1 → 2026.08.20.1

2026.08.15.1

Changed: Bump @webframp/aws/bedrock-usage 2026.08.02.1 → 2026.08.05.1

2026.08.14.1

Added: Anthropic (Claude Enterprise Analytics) as a fourth provider in the registry, sourced from @webframp/anthropic/analytics's userUsage resource (collect_user_usage method). Groups by user (keyed by email) with a per-product (claude_code, chat, etc.) breakdown, using the totals field that extension's 2026.08.14.1 release added specifically to match this registry's expected shape — no bespoke adapter code needed here.

Changed: Bumped the @webframp/azure/openai-usage dependency to 2026.08.14.4 (pagination + 429/5xx retry + dedup fixes) and added the @webframp/anthropic/analytics@2026.08.14.1 dependency (needed for its new days argument on collect_user_usage and the totals field on userUsage). Wired an anthropic-usage step into the @webframp/ai-usage-scan workflow using the same days input as the other providers, so the unified report's per-minute rates share one consistent window.

Fixed: lastScanned in status and generate fell back straight to the data-write timestamp when a provider's attributes had no scannedAt field. Anthropic's userUsage resource uses fetchedAt instead of scannedAt — both methods now check fetchedAt before falling back to the write timestamp, matching how the field is actually named across providers.

2026.08.11.1

Fixed: status and generate always reported every provider as unconfigured, even with valid scan data present. Both methods called context.dataRepository.findBySpec(modelName, specName), which does not exist on the method-execution context — only findAllForModel (metadata) and getContent (raw bytes) are available there. The call threw a TypeError on every invocation, silently caught and logged as a warning, so every provider always fell back to "unconfigured" regardless of actual scan state.

Fixed: The replacement findAllForModel-based lookup sorted results by calling .localeCompare() on createdAt, assuming it was a string — but swamp's real Data.createdAt is a Date object, so this threw on every invocation with scan data present. Sorting now uses Date.getTime(), and generate's error path now logs failures via context.logger.warn like status already did. Added a runtime shape guard on createdAt so a future mismatch between this extension's local type guess and swamp's actual API surfaces as a clear error instead of a silent miscalculation.

Upgrade note: No schema or behavioral changes to the status/report resource shapes — this is purely an internal data-access fix. Re-run swamp model method run ai-usage status after upgrading to see accurate coverage.

2026.08.05.1

Changed: Bump @webframp/aws/bedrock-usage 2026.08.01.1 → 2026.08.02.1

2026.08.02.1

Changed: Bump @webframp/aws/bedrock-usage 2026.07.29.1 → 2026.08.01.1

2026.07.31.2

Changed: Breaking schema change — the hint string field in status and report coverage entries is replaced by a setup object containing command, permissions (array of least-privilege IAM/RBAC permissions), and authNotes (authentication mechanism description). Consumers parsing the status resource must update to the new shape.

Changed: The extensionType field is now included in provider status entries (e.g. @webframp/aws/bedrock-usage).

Added: Setup guidance now includes the full model create command with all required arguments (including auth credentials for GCP and Azure that were previously missing), the exact permissions needed, and a description of how authentication works for each provider.

Added: Data-driven provider registry. Adding a new provider (Anthropic, Moonshot, etc.) requires only appending a ProviderDefinition object — no new code blocks in status, generate, or the report.

Changed: The report extension now imports provider definitions from the model, eliminating duplicated per-provider rendering logic.

Upgrade note: This is a breaking change. If you parse the status resource programmatically, update from provider.hint (string) to provider.setup (object with command, permissions, authNotes fields). Configured providers have these fields blanked (empty string / empty array).

updated dependencies

2026.08.14.1

2026.08.14.1

Added: Anthropic (Claude Enterprise Analytics) as a fourth provider in the registry, sourced from @webframp/anthropic/analytics's userUsage resource (collect_user_usage method). Groups by user (keyed by email) with a per-product (claude_code, chat, etc.) breakdown, using the totals field that extension's 2026.08.14.1 release added specifically to match this registry's expected shape — no bespoke adapter code needed here.

Changed: Bumped the @webframp/azure/openai-usage dependency to 2026.08.14.4 (pagination + 429/5xx retry + dedup fixes) and added the @webframp/anthropic/analytics@2026.08.14.1 dependency (needed for its new days argument on collect_user_usage and the totals field on userUsage). Wired an anthropic-usage step into the @webframp/ai-usage-scan workflow using the same days input as the other providers, so the unified report's per-minute rates share one consistent window.

Fixed: lastScanned in status and generate fell back straight to the data-write timestamp when a provider's attributes had no scannedAt field. Anthropic's userUsage resource uses fetchedAt instead of scannedAt — both methods now check fetchedAt before falling back to the write timestamp, matching how the field is actually named across providers.

2026.08.11.1

Fixed: status and generate always reported every provider as unconfigured, even with valid scan data present. Both methods called context.dataRepository.findBySpec(modelName, specName), which does not exist on the method-execution context — only findAllForModel (metadata) and getContent (raw bytes) are available there. The call threw a TypeError on every invocation, silently caught and logged as a warning, so every provider always fell back to "unconfigured" regardless of actual scan state.

Fixed: The replacement findAllForModel-based lookup sorted results by calling .localeCompare() on createdAt, assuming it was a string — but swamp's real Data.createdAt is a Date object, so this threw on every invocation with scan data present. Sorting now uses Date.getTime(), and generate's error path now logs failures via context.logger.warn like status already did. Added a runtime shape guard on createdAt so a future mismatch between this extension's local type guess and swamp's actual API surfaces as a clear error instead of a silent miscalculation.

Upgrade note: No schema or behavioral changes to the status/report resource shapes — this is purely an internal data-access fix. Re-run swamp model method run ai-usage status after upgrading to see accurate coverage.

2026.08.05.1

Changed: Bump @webframp/aws/bedrock-usage 2026.08.01.1 → 2026.08.02.1

2026.08.02.1

Changed: Bump @webframp/aws/bedrock-usage 2026.07.29.1 → 2026.08.01.1

2026.07.31.2

Changed: Breaking schema change — the hint string field in status and report coverage entries is replaced by a setup object containing command, permissions (array of least-privilege IAM/RBAC permissions), and authNotes (authentication mechanism description). Consumers parsing the status resource must update to the new shape.

Changed: The extensionType field is now included in provider status entries (e.g. @webframp/aws/bedrock-usage).

Added: Setup guidance now includes the full model create command with all required arguments (including auth credentials for GCP and Azure that were previously missing), the exact permissions needed, and a description of how authentication works for each provider.

Added: Data-driven provider registry. Adding a new provider (Anthropic, Moonshot, etc.) requires only appending a ProviderDefinition object — no new code blocks in status, generate, or the report.

Changed: The report extension now imports provider definitions from the model, eliminating duplicated per-provider rendering logic.

Upgrade note: This is a breaking change. If you parse the status resource programmatically, update from provider.hint (string) to provider.setup (object with command, permissions, authNotes fields). Configured providers have these fields blanked (empty string / empty array).

updated dependencies

2026.08.11.1

2026.08.11.1

Fixed: status and generate always reported every provider as unconfigured, even with valid scan data present. Both methods called context.dataRepository.findBySpec(modelName, specName), which does not exist on the method-execution context — only findAllForModel (metadata) and getContent (raw bytes) are available there. The call threw a TypeError on every invocation, silently caught and logged as a warning, so every provider always fell back to "unconfigured" regardless of actual scan state.

Fixed: The replacement findAllForModel-based lookup sorted results by calling .localeCompare() on createdAt, assuming it was a string — but swamp's real Data.createdAt is a Date object, so this threw on every invocation with scan data present. Sorting now uses Date.getTime(), and generate's error path now logs failures via context.logger.warn like status already did. Added a runtime shape guard on createdAt so a future mismatch between this extension's local type guess and swamp's actual API surfaces as a clear error instead of a silent miscalculation.

Upgrade note: No schema or behavioral changes to the status/report resource shapes — this is purely an internal data-access fix. Re-run swamp model method run ai-usage status after upgrading to see accurate coverage.

2026.08.05.1

Changed: Bump @webframp/aws/bedrock-usage 2026.08.01.1 → 2026.08.02.1

2026.08.02.1

Changed: Bump @webframp/aws/bedrock-usage 2026.07.29.1 → 2026.08.01.1

2026.07.31.2

Changed: Breaking schema change — the hint string field in status and report coverage entries is replaced by a setup object containing command, permissions (array of least-privilege IAM/RBAC permissions), and authNotes (authentication mechanism description). Consumers parsing the status resource must update to the new shape.

Changed: The extensionType field is now included in provider status entries (e.g. @webframp/aws/bedrock-usage).

Added: Setup guidance now includes the full model create command with all required arguments (including auth credentials for GCP and Azure that were previously missing), the exact permissions needed, and a description of how authentication works for each provider.

Added: Data-driven provider registry. Adding a new provider (Anthropic, Moonshot, etc.) requires only appending a ProviderDefinition object — no new code blocks in status, generate, or the report.

Changed: The report extension now imports provider definitions from the model, eliminating duplicated per-provider rendering logic.

Upgrade note: This is a breaking change. If you parse the status resource programmatically, update from provider.hint (string) to provider.setup (object with command, permissions, authNotes fields). Configured providers have these fields blanked (empty string / empty array).

2026.08.05.1

2026.08.05.1

Changed: Bump @webframp/aws/bedrock-usage 2026.08.01.1 → 2026.08.02.1

2026.08.02.1

Changed: Bump @webframp/aws/bedrock-usage 2026.07.29.1 → 2026.08.01.1

2026.07.31.2

Changed: Breaking schema change — the hint string field in status and report coverage entries is replaced by a setup object containing command, permissions (array of least-privilege IAM/RBAC permissions), and authNotes (authentication mechanism description). Consumers parsing the status resource must update to the new shape.

Changed: The extensionType field is now included in provider status entries (e.g. @webframp/aws/bedrock-usage).

Added: Setup guidance now includes the full model create command with all required arguments (including auth credentials for GCP and Azure that were previously missing), the exact permissions needed, and a description of how authentication works for each provider.

Added: Data-driven provider registry. Adding a new provider (Anthropic, Moonshot, etc.) requires only appending a ProviderDefinition object — no new code blocks in status, generate, or the report.

Changed: The report extension now imports provider definitions from the model, eliminating duplicated per-provider rendering logic.

Upgrade note: This is a breaking change. If you parse the status resource programmatically, update from provider.hint (string) to provider.setup (object with command, permissions, authNotes fields). Configured providers have these fields blanked (empty string / empty array).

updated dependencies

2026.08.02.1

2026.08.02.1

Changed: Bump @webframp/aws/bedrock-usage 2026.07.29.1 → 2026.08.01.1

2026.07.31.2

Changed: Breaking schema change — the hint string field in status and report coverage entries is replaced by a setup object containing command, permissions (array of least-privilege IAM/RBAC permissions), and authNotes (authentication mechanism description). Consumers parsing the status resource must update to the new shape.

Changed: The extensionType field is now included in provider status entries (e.g. @webframp/aws/bedrock-usage).

Added: Setup guidance now includes the full model create command with all required arguments (including auth credentials for GCP and Azure that were previously missing), the exact permissions needed, and a description of how authentication works for each provider.

Added: Data-driven provider registry. Adding a new provider (Anthropic, Moonshot, etc.) requires only appending a ProviderDefinition object — no new code blocks in status, generate, or the report.

Changed: The report extension now imports provider definitions from the model, eliminating duplicated per-provider rendering logic.

Upgrade note: This is a breaking change. If you parse the status resource programmatically, update from provider.hint (string) to provider.setup (object with command, permissions, authNotes fields). Configured providers have these fields blanked (empty string / empty array).

updated dependencies

2026.07.31.2

2026.07.31.2

Changed: Breaking schema change — the hint string field in status and report coverage entries is replaced by a setup object containing command, permissions (array of least-privilege IAM/RBAC permissions), and authNotes (authentication mechanism description). Consumers parsing the status resource must update to the new shape.

Changed: The extensionType field is now included in provider status entries (e.g. @webframp/aws/bedrock-usage).

Added: Setup guidance now includes the full model create command with all required arguments (including auth credentials for GCP and Azure that were previously missing), the exact permissions needed, and a description of how authentication works for each provider.

Added: Data-driven provider registry. Adding a new provider (Anthropic, Moonshot, etc.) requires only appending a ProviderDefinition object — no new code blocks in status, generate, or the report.

Changed: The report extension now imports provider definitions from the model, eliminating duplicated per-provider rendering logic.

Upgrade note: This is a breaking change. If you parse the status resource programmatically, update from provider.hint (string) to provider.setup (object with command, permissions, authNotes fields). Configured providers have these fields blanked (empty string / empty array).

updated dependencies

2026.07.24.1

2026.07.24.1

Changed: Bump dependency pins to latest published versions:

  • @webframp/aws/bedrock-usage 2026.07.18.1 → 2026.07.21.1
  • @webframp/gcp/vertex-usage 2026.07.10.1 → 2026.07.21.1
  • @webframp/azure/openai-usage 2026.06.21.1 → 2026.07.21.1

updated dependencies

2026.07.20.1

2026.07.20.1

Changed: Refreshed dependency pins to the latest published releases. Model version bumped to match the manifest; no schema changes (identity upgrade).

Upgrade note: Bumps @webframp/aws/bedrock-usage 2026.05.12.1 → 2026.07.18.1, @webframp/gcp/vertex-usage 2026.05.12.1 → 2026.07.10.1, and @webframp/azure/openai-usage 2026.05.12.1 → 2026.06.21.1, pulled automatically with this extension.

updated dependencies

2026.07.18.1

2026.07.18.1

Added: An upgrades array entry (no-op) to ai_usage.ts for proper typeVersion tracking on existing instances. No schema or behavior changes.

2026.07.16.1

Changed: README and LICENSE reformatted (deno fmt) in PR #134; this is the first version bump to publish that formatting to the registry. No functional or behavioral change.

2026.07.16.1

2026.07.16.1

Changed: README and LICENSE reformatted (deno fmt) in PR #134; this is the first version bump to publish that formatting to the registry. No functional or behavioral change.

2026.06.21.1
2026.06.15.1
2026.05.12.1
07Stats
A
100 / 100
Downloads
2
Archive size
124.1 KB
  • Has README or module doc2/2earned
  • README has a code example1/1earned
  • README is substantive1/1earned
  • Most symbols documented1/1earned
  • No slow types (deprecated)1/1earned
  • Dependencies pass trust audit2/2earned
  • Has description1/1earned
  • Platform support declared (or universal)2/2earned
  • License declared1/1earned
  • Verified public repository2/2earned
08Platforms
09Labels