Install
Works with Drupal: ^10.5 || ^11.2Using Composer to manage Drupal site dependencies
Alternative installation files
Release notes
### Fixed
- CSV export on `/admin/reports/ai-metering/log` now exports the filtered raw
log (provider, model, period, role) instead of the aggregated dashboard data.
Powered by Views Data Export with batch processing. (#3605378)
- JSON export on `/admin/reports/ai-metering/log` now exports filtered raw log
rows via a dedicated controller route; `token_details` is decoded JSON (never
HTML-encoded). (#3605379)
**Known issue:** The VDE CSV export does not apply formula-injection escaping
to string cells. Values starting with `=`, `+`, `-`, or `@` will open as
formulas in Excel or LibreOffice. A fix will be tracked separately and resolved
before 1.0.0 stable.
### Fixed (CI)
- Fix 17 PHPStan level-6 violations: narrow `?string` to `string` on install
hooks, annotate `$valueOptions` as `array|null` in Views filter subclasses,
fix `@return` key types on `getAvailableYears()`/`getMonthOptions()`, add
`instanceof Sql` guard in `UsagePeriodFilter::query()`, and tighten four test
assertions (#3605367)
- Add `phpcs.xml.dist`, exclude `node_modules/` and `vendor/`, fix line-length
violation in `ai_metering.views.inc`; remove broken `includes:` block from
`phpstan.neon` so both PHPCS and PHPStan jobs pass on DrupalCI (#3605324)
### Performance
- Cache `UsageProviderFilter` and `UsageModelFilter` option queries with
`Cache::PERMANENT` and `ai_metering_usage` tag; redundant `SELECT DISTINCT`
on every page load is eliminated (#3605212)
- Add standalone `timestamp` and `model_id` indexes to `ai_metering_usage`;
timestamp-only range queries and `SELECT DISTINCT model_id` no longer cause
full-table scans (#3605209)
- Replace PHP aggregation loop in `getDashboardData()` with two SQL `GROUP BY`
queries; data transferred from DB to PHP shrinks from O(rows) to O(users),
and `loadMultiple()` replaces per-uid entity loads (#3605210)
### Security
- Hex-encode HTML-sensitive characters in dashboard chart JSON output (inline
script hardening)
- Require a CSRF token on the pricing sync route (state-changing GET)
- Check entity view access before returning token estimates
- Neutralize spreadsheet formula injection in the CSV export
- Render the LiteLLM API key field as a password input; the stored key is no
longer echoed back into the settings form
### Added
- Add exposed filters to the AI Usage Log view: Provider and Model select lists
populated from live data, and a Period (month) picker. Implemented as three
custom Views filter plugins (#3605193).
- Add "AI Usage Log" card to the AI Metering hub page; reorder hub cards into a
logical sequence: Usage Dashboard, Dashboard by Role, AI Usage Log, Metering
Settings, drupal/ai Core Settings, Permissions (#3605193).
- Remove duplicate "AI Metering Reports" menu link that pointed to the same
route as the Usage Dashboard (#3605193).
- Introduce `PricingSource` plugin type; `LiteLLMPricingSource` and
`ModelsDotDevPricingSource` ship out of the box; third-party modules can add
custom sources (#3604256).
- Settings page gains a "Pricing source" selector;
`ModelPricingService::syncFromSource()` dispatches to the selected plugin
(#3604256).
- `ai_metering_update_9008()`: adds the uid contextual argument to the AI Usage
Log view if missing, and lowers the pager from 50 to 10 on existing
installations (#3604228).
- Add `token_details` JSON blob column to `ai_metering_usage` to capture
provider-specific token breakdowns: reasoning tokens (Claude extended
thinking), provider-reported total, and any future fields from
`TokenUsageDto` (#3604255).
- Expose `token_details` in the AI Usage Log view; the column is hidden when
empty so it only appears for calls that carry extended token data (#3604255).
- Add toolbar icon for AI Metering admin links: monochrome SVG gauge,
compatible with both Gin 5.x and core toolbar (#3604240).
- Add by-role dashboard at `/admin/reports/ai-metering/by-role`: aggregates
per-user usage into role buckets; includes CSV and JSON exports (#3604346).
### Changed
- `computeDollarBudget()` now falls back to synced source rates when no manual
pricing entry matches the model; `drush aim-sync` now respects the configured
pricing source instead of hardcoding LiteLLM (#3604238).
- Raise PHPStan analysis to level 6 (#3593077)
- Exclude developer tooling from drupal.org Composer packages via
`.gitattributes` (#3593077)
### Fixed
- Fix "View calls" link in the dashboard to use a path argument (`/uid`) instead
of a query string (`?uid=`), so the AI Usage Log view filters by user
correctly (#3604228).
- Add uid argument and filter integration to `ai_metering.views.inc` (#3604228).
- Lower AI Usage Log view default pager from 50 to 10 items per page (#3604228).
- Skip recording events from wrapper providers (e.g. `chat_translation`) to
prevent double-counting every AI Translate operation (#3604229).
- Fall back to a cross-provider rate match in `calculateCost()` when a wrapper
provider has no pricing of its own, ensuring calls are not logged at $0
(#3604229).
- Declare `log_base_url` in `hook_theme()` so the dashboard template receives
the per-user log link variable (#3604227).
- Dashboard charts failed to render because the inline script ran before
Chart.js loaded (#3604226). Chart rendering, table sorting, and the month
filter now live in `js/ai-metering-dashboard.js`; chart data reaches it
through `drupalSettings`.
- Sort buttons targeted the wrong table columns since the Provider column was
added (#3604226): Calls sorted by provider, Cost by tokens, Quota % by cost.
- Move the per-role overlap note above the table in the by-role dashboard so it
is visible before the apparent totals discrepancy, not after (#3605190).
- Move AI Metering settings link from top-level admin sidebar into
Configuration | AI, consistent with other AI-related modules (#3604240).
- Fix camelCase dispatch for multi-word operation types on ProviderProxy
(#3593077)
- Replace hardcoded role check with `use ai_metering` permission; anonymous
users bypass silently (#3593077)
- Add `translate_output_ratio` to config schema and install defaults; fix
config:export diffs (#3593077)
- Move `pricing_sync` counters to State-only; add `ai_metering_update_9006()`
for existing sites (#3593077)
- Remove unsupported `max_tokens` parameter from Anthropic count_tokens request
(#3593077)
- Deduplicate quota exceeded hook invocations via State guard (once per user
per month) (#3593077)
- Fix generic return types in CostReporter; replace string callable with typed
closure in MeteringSettingsForm (#3593077)