Installation
composer require drupal/ai_metering
drush en ai_metering -y
drush cr
The module creates three database tables on install/update: ai_metering_usage (one row per AI call), ai_metering_quota (per-user monthly budgets), and ai_metering_rollup (monthly per-user aggregates, see Monthly rollup and retention purge). No manual schema changes are required.
Two optional Views are shipped as config/optional and activate automatically when the Views module is enabled:
- ai_usage_log — the raw per-call log described below.
- ai_quota_status — a per-user quota/usage summary view (base table ai_metering_quota), available for site builders who want a custom block or page beyond the two shipped dashboards.
Requirements
- Drupal 10.5+ or 11.2+
- PHP 8.2+ (PHP 8.3+ required when running on Drupal 11)
- AI module (
drupal/ai,^1.4.2or later) - At least one AI provider module
views_data_export(declared as a hard dependency; powers the usage log's CSV export)
Optional integrations
- ai_usage_limits: when installed, its provider-level system ceiling is shown as a read-only banner at the top of Dashboard by User.
- Ollama (
ai_provider_ollama): local LLM runtime, commonly configured as the quota-exceeded fallback. - LiteLLM proxy: self-hosted cost proxy; enables the two
litellm-*Drush spend reports.