Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

AI Metering

41 sites No security coverage Ai ecosystem
View on drupal.org

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 an admin dashboard 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. Subscribes to PostGenerateResponseEvent and PostStreamingResponseEvent, fired by every provider through ai\Plugin\ProviderProxy. No per-provider or per-feature configuration needed.
  • Per-user monthly quotas. Set a global default, per-role defaults, or per-user overrides. When a user's budget is reached, the module either reroutes the call to a local fallback provider (e.g. Ollama) at zero cost, or throws an AiQuotaException to block the paid call. A pre-flight estimate runs before dispatch — if the request would push the user over budget, the call is rerouted before the remote API is contacted.
  • Multi-currency cost display. Costs are tracked in USD. Display currency is configurable: USD, CAD, EUR, GBP, AUD, JPY. Exchange rates are fetched from Frankfurter (ECB reference rates, no API key), cached for one hour, with a fallback to manually configured rates.
  • Pluggable pricing sources. The PricingSource plugin type ships with LiteLLMPricingSource (100+ models) and ModelsDotDevPricingSource. Third-party modules can register additional sources. Sync on demand via the admin UI or drush ai-metering:sync-pricing. Manual overrides are preserved across syncs.
  • Usage dashboard. Per-editor breakdown of token consumption, cost, call counts, and quota percentage for any calendar month. Local providers (Ollama, LM Studio, etc.) appear tracked at zero cost, separate from billed cloud providers. Exportable as CSV or JSON.
  • By-role dashboard. Aggregates per-user usage into role buckets at /admin/reports/ai-metering/by-role. Includes CSV and JSON exports.
  • Usage log. Per-call audit trail at /admin/reports/ai-metering/log: user, timestamp, provider, model, operation type, input/output/cached token counts, cost in USD at 8-decimal precision, and a token_details column for provider-specific breakdowns (reasoning tokens, provider-reported totals). Filterable by provider, model, and period. Exportable as CSV or JSON.
  • Email alerts. Fires once per threshold crossing per month (default 75%). Per-user threshold overrides supported.
  • Context grouping. Tag AI events with aim_context:UUID to group all calls from a single agent run. Calls sharing the same UUID appear as a single session in the usage log.
  • Extensibility hooks. hook_ai_metering_quota_exceeded(), hook_ai_metering_record_alter(), and MeteringRecordCreatedEvent.

Post-Installation

  1. Go to Admin → Configuration → AI → AI Metering (/admin/config/ai/ai-metering) for the hub page linking to all sections: dashboard, settings, usage log, and permissions.
  2. In Settings, configure display currency, quota defaults, fallback provider, pricing source, and alert threshold.
  3. Sync model pricing from the settings form or via drush ai-metering:sync-pricing. Optional — the module falls back to manually entered rates if no sync has run.
  4. Assign Administer AI Metering to administrator roles and View AI usage dashboard to roles that should see the dashboard.

Additional Requirements

  • Drupal 10.5+ or 11.2+
  • PHP 8.1+ (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: the Anthropic token-counting adapter uses key.repository when available. If you manage API keys with Key site-wide, the integration is detected automatically.
  • Ollama provider (ai_provider_ollama): exposes a local Ollama runtime as a provider, useful as the fallback for quota-exhausted calls at zero cost.
  • LiteLLM proxy (optional): when configured, Drush commands expose proxy-level spend reports (ai-metering:litellm-user-spend, ai-metering:litellm-report).

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-editor 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.

This module is developed by Jérôme Tchania (CodeIt Wisely).

Community Documentation

  • AI module: upstream provider abstraction this module builds on
  • LiteLLM cost map: source for automated pricing sync
  • Models.Dev: source for automated pricing sync
  • Frankfurter: ECB exchange rates used for multi-currency display
  • Module wiki: installation guide, permissions, Drush commands, and hooks API reference
AI Disclosure.

Significant portions of this module's code were written with AI coding assistance under developer supervision.

Activity

Total releases
2
First release
Jun 2026
Latest release
3 weeks ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Active

Releases

Version Type Release date
1.0.0-beta1 Pre-release Jun 22, 2026
1.0.0-alpha1 Pre-release Jun 2, 2026