Problem/Motivation
ai_metering records provider, model, operation, tokens, cost and latency for
each AI call, but not which feature or agent triggered it. The usage log and
dashboard cannot answer "which feature is driving spend", which is the
per-feature attribution the AI Initiative's AI Cost & Usage RFC
(#3586519)
asks for. The AI call already carries tags that identify the caller
(ai_ckeditor, ai_search, agents, ...), but they are not persisted.
Steps to reproduce
- Trigger AI operations from different features (CKEditor, Search, an agent).
- Open /admin/reports/ai-metering/log. There is no column or filter for the
calling feature; rows from different features are indistinguishable.
Environment
- Drupal version: 11.x
- ai_metering version: 1.0.x
Proposed resolution
- Add a
callercolumn (varchar) to the usage and rollup tables. - Populate it in AiPostGenerateSubscriber from the AI call tags: an explicit
aim_feature:<name>tag wins when present; otherwise take the
first tag that is not internal (aim_context:*,
ai_translate,smart_route:*,route_*).
Empty when no feature tag is available. - Expose
calleras a column and an exposed filter in the AI
Usage Log view. - Add the column via hook_update_N (additive, so historical rollups stay
comparable).
Remaining tasks
- Implementation, kernel test for the tag derivation, MR, review.
- Follow-up (separate issue): a "top feature areas" chart on the dashboard.
User interface changes
New "Caller" column and exposed filter in the usage log.
API changes
New optional call-tag convention aim_feature:<name> so
features and agents can self-identify. No breaking change.
Data model changes
New caller column on ai_metering_usage and ai_metering_rollup,
added by hook_update_N.
AI assistance
N/A
Issue fork ai_metering-3610924
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
codeitwisely commentedComment #6
codeitwisely commented