This module tracks AI token usage, estimates costs, and allows setting per-user monthly quotas. It automatically records every AI call the system makes, providing a dashboard for usage overviews and a detailed log for auditing.
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)
Recommended modules/libraries
- 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.
Note that extensive parts of this module were generated via AI coding agents under human supervision.
Depends on
Dependencies of the latest stable release
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
Activity
Release Timeline
Releases
| Version | Type | Core | Notes | Release date | |
|---|---|---|---|---|---|
| 1.0.2 | Stable | 10–11 | Aug 14, 2026 | ||
| 1.0.1 | Stable | 10–11 | Aug 7, 2026 | ||
| 1.0.x-dev | Dev | 10–11 | Aug 4, 2026 | ||
| 1.0.0 | Stable | 10–11 | Aug 3, 2026 | ||
| 1.0.0-beta1 | Pre-release | 10–11 | First beta: by-role dashboard, CSV/JSON filtered exports, PricingSource plugin system, performance improvements (SQL GROUP BY, DB indexes), and 5 security fixes. | Jun 22, 2026 | |
| 1.0.0-alpha1 | Pre-release | 10–11 | First alpha, per-user token quotas, cost tracking, multi-currency display, Ollama fallback, and role-based budget pools coming in 1.1.0. | Jun 2, 2026 |