Problem/Motivation
When ai_translate is configured to use the chat_translation provider,
every translation is recorded twice in ai_metering: once under the non-billable
chat_translation provider name and once under the real provider
(e.g. anthropic). This doubles the call count and the displayed
cost on the dashboard, and surfaces a provider name that has no pricing of its own.
The root cause is that chat_translation is a wrapper: it dispatches
its own PostGenerateResponseEvent and then makes a nested call to
the real provider, which dispatches a second event. ai_metering records both.
Steps to reproduce
- Install ai_metering and ai_translate. Configure ai_translate to use the
chat_translationprovider backed by Anthropic. - Translate a node (e.g. from English to French).
- Open
/admin/reports/ai-metering. Two rows appear with the same timestamp: one labelledchat_translationand one labelledanthropic. Token counts and cost are doubled.
Environment
- Drupal version: 11.3.11
- ai_metering version: 1.0.0-alpha1
- AI provider module + version: ai_provider_anthropic 1.x
- AI feature module tested: ai_translate 1.x
Proposed resolution
Skip wrapper-provider events in AiPostGenerateSubscriber, keyed off
a small list of known wrapper providers (starting with chat_translation).
The inner call to the real provider already records the operation with the correct
tokens, model, and billable provider, so only that row should remain.
Remaining tasks
- Skip wrapper providers in
AiPostGenerateSubscriber. - Add a kernel test asserting no row is written for a wrapper provider event.
- Verify a single row per translation appears under the real provider.
- Review.
User interface changes
Yes, the dashboard shows one row per translation with the correct provider and cost.
API changes
N/A
Data model changes
N/A
AI assistance
N/A
Comments
Comment #2
codeitwisely commentedComment #10
codeitwisely commented