ECA integration
drush en ai_metering_eca -y
Exposes AI Metering's per-user quota data to ECA
models as an action, a condition, and an event, no code required to react to
a user's AI usage. Nothing to configure: enabling the submodule makes
everything below available in the ECA modeler at /admin/config/workflow/eca.
Requirements
ai_meteringeca
What you get
- Action: "AI Metering: get user quota" — looks up a user's quota for
the current month and writes it into named tokens:
monthly_budget,tokens_used,tokens_remaining,pct_used,exceeded,alert_threshold. - Condition: "AI Metering: user over quota" — true once a user reaches
their quota (the same 100%
exceededflag AI Metering itself enforces), or an earlier threshold percentage you configure. - Event: "AI Metering: user quota exceeded" — fires at most once per
user per month, the moment their quota is reached:
[event:uid],[event:provider_id],[event:monthly_budget],[event:tokens_used],[event:tokens_remaining],[event:pct_used].
Three ready-made examples
The submodule ships three real, tested models in its examples/ directory —
not snippets to retype, but .eca.yml files you import as-is and adapt:
- Notify on user quota exceeded — the event straight into a log message.
- Warn user at 80% of quota on login — login gated by the "over quota"
condition at an earlier threshold, then a warning with the live numbers.
Needs
eca_userenabled in addition to this module's own requirements. - Tag user with a quota-watch role on quota exceeded — reacts to the same event with a role assignment instead of a notification, so support staff can filter affected users later. Ships its own role config, imported first.
Import them through Drupal's Configuration > Single import
(/admin/config/development/configuration/single/import) with
Configuration type set to ECA (and Role first, for the
quota-watch example's companion role) — not through ECA's own Import tab,
which expects a BPMN.iO diagram file rather than this config format. See the
submodule's own README for the exact steps.
This runs alongside hook_ai_metering_quota_exceeded() (see
Hooks API) with no interaction between the two: both react to the
same moment, through different mechanisms, so adding the ECA event never
changes what the hook implementations already do.
Other use cases
- Gate a custom AI feature (hide a button, swap a message) with the "user over quota" condition, without writing a line of PHP.
- Route the alert to a different channel per role, by combining the event with ECA's own user/role conditions.
Why a submodule, not ai_integration_eca
None of these plugins depend on
ai_integration_eca or
its ai_eca_interceptor submodule: getting a user's quota has nothing to do
with intercepting an AI call in flight. ECA discovers plugins from any
enabled module, so both can be mixed freely in the same model.