AI metering monitors the AI costs

AI Metering adds token usage tracking, cost estimation, per-user monthly quotas, and two usage dashboards to any Drupal site running the AI module. It subscribes to drupal/ai's event system and records every AI call automatically: any provider registered with the AI module is covered, with no per-provider configuration.

Features

  • Automatic call interception: every provider registered with the AI module is tracked, with zero per-provider configuration.
  • Per-user monthly quotas with pre-flight checks: over-budget calls are rerouted to a local fallback provider (e.g. Ollama) at zero cost, or blocked before the remote API is contacted.
  • Cost tracking in USD, displayed in USD, CAD, EUR, GBP, AUD, or JPY with live exchange rates.
  • Pluggable pricing sources (LiteLLM cost map, models.dev); manual overrides survive every sync.
  • Dashboard by User and Dashboard by Role, with CSV and JSON export.
  • Per-call usage log: tokens, latency, calling feature, and cost at 8-decimal precision; filterable and exportable.
  • Pluggable alert channels: email and webhook (Slack/Teams-compatible) ship built in.
  • Personal usage self-service: a block and a profile tab let editors see their own monthly usage and quota.
  • Monthly rollup and retention purge, without losing historical dashboard totals.
  • GDPR-aware data lifecycle: usage purged on account deletion, reassigned to anonymous on cancellation.
  • Context grouping, hooks and events for grouping agent runs and extending the module.

Getting started

Enable the module, then go to Admin → Configuration → AI → AI Metering (/admin/config/ai/ai-metering). The documentation site covers installation, permissions, configuration, both dashboards, Drush commands, and the hooks API.

Additional Requirements

  • Drupal 10.5+ or 11.2+
  • PHP 8.2+ (8.3+ on Drupal 11)
  • AI module (drupal/ai)
  • At least one AI provider module (e.g. ai_provider_anthropic, ai_provider_openai, or any community provider)
  • Key module: used by the Anthropic token-counting adapter when available.
  • Ollama provider: a zero-cost local fallback for quota-exhausted calls.
  • LiteLLM proxy (optional): proxy-level spend reports via Drush.

Similar projects

Two other contrib modules address AI usage governance:

  • AI Usage Limits: per-provider token limits with hard blocking.
  • AI Budget Control: declarative limit rules, scopes, sliding time windows, and anti-flood protection.

AI Metering overlaps with both on core metering, and is closest in scope to AI Budget Control. The main differences are cost transparency across providers (pricing from a 100+ model cost map, multi-currency), a graceful local-model fallback instead of a hard block, and a per-user dashboard backed by a full per-call audit trail. There is an active conversation about consolidating this overlapping functionality: #3595756.

Supporting this Module

Use the issue queue for bug reports and feature requests. When filing a bug, include your Drupal and module versions and any relevant output from drush watchdog:show --type=ai_metering.

Built by a human using an AI assistant: 🤖 ➕ 🧠

Note that extensive parts of this module were generated via AI coding agents under human supervision.

Supporting organizations: 
Development and maintenance
AttachmentSize
Top of the Dashboard page231.23 KB

Project information

Releases