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

  1. Trigger AI operations from different features (CKEditor, Search, an agent).
  2. 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 caller column (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 caller as 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

Command icon 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

codeitwisely created an issue. See original summary.

  • 77c8e666 committed on 1.0.x
    Issue #3610924 by codeitwisely: Record the calling feature for each AI...
codeitwisely’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

codeitwisely’s picture

Category: Task » Feature request

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.