How Drupal Sites Track AI Requests, Token Costs and Budgets
Every call a Drupal site makes through the AI (Artificial Intelligence) module can be logged, counted, priced and capped inside Drupal. Three contributed tools handle event logging, conversation history and cost budgets separately, and a site can enable one or combine them.
In local testing by The DropTimes, AI Metering priced OpenAI calls as each row was written, while any provider or model missing from its price lists recorded $0 until a manual rate was added. In the same testing, AI Observability kept prompt and response text off by default, whereas the recipe that adds database reports turned both on when applied with its defaults.
How the Modules Divide the Job
All three listen to the AI module's request and response events; calls made directly through a vendor's software development kit outside the AI module are not seen.
- AI Observability, a submodule of the AI module, emits structured events describing each call: provider, model, operation, request ID and token usage.
- AI Logging, downloaded automatically with the AI module and enabled separately, stores prompts and replies and groups agent runs into conversation threads.
- AI Metering records per-call token usage and cost, and enforces monthly token budgets and threshold alerts.
Event Logging with AI Observability
The submodule's README says it "only produces logs that can be stored anywhere": the Drupal database, Syslog, a file or a cloud log collector. For local development it recommends the Logger and Logger DB modules, and for production it recommends dedicated log tools. 1
By default, it logs events before a response is generated, after it arrives and after a streamed response finishes, with prompt and response text turned off and long metadata values shortened.
Database Reports from the Observability Recipe
The AI DB Observability Recipe, supported by FreelyGive, turns those events into Views reports under Reports › AI requests. They include a searchable event log, an event detail page, daily and per-model request and token charts, a guardrail report, and a conversation view that groups the calls made for one request. 2
The charts count request-start events and the tokens that providers report, leaving out missing token figures rather than counting them as zero. Failed or guardrail-stopped requests appear as start events only, and latency and cost are not tracked here.
Applying the recipe installs Logger and Logger DB and sets Logger to write to the database only, replacing existing log targets across every channel, not only AI. Viewing the reports requires the "Administer AI Observability" permission, which no role is given automatically.
Exporting Traces and Metrics with OpenTelemetry
AI Observability can also export each call as a timed span and a token-usage metric using OpenTelemetry's GenAI conventions for attributes such as provider, model and token counts. Export is off by default and requires the OpenTelemetry module. A separate AI Observability OpenTelemetry Recipe configures the export, as shown in an earlier DropTimes self-hosted Grafana observability stack walkthrough. 3
Prompt and Thread History with AI Logging
When enabled, AI Logging stores prompts and replies as Drupal records, groups multi-step agent runs into conversation threads, and provides restricted actions to delete a single thread or clear all logs. Its project page describes it as safe for production once maximum record-count and age limits are configured so a daily cron task prunes old logs automatically. 4
Pricing Calls in AI Metering
AI Metering, supported by CodeIt Wisely, stores each call's cost in US dollars (with optional multi-currency display) when the usage row is written and never recalculates earlier rows. When a provider response carries token counts, the module uses them; when none arrive, as with embeddings calls, it estimates tokens from text length at roughly four characters per token, mixing reported and estimated totals. 5
The pricing service looks for a rate in four places, in order:
- A manual price for the exact provider and model, or for the model name alone.
- A synced public price list.
- A manual default price for the provider.
- A price for the same model name under another provider.
Default configuration ships manual prices for three Anthropic Claude models and OpenAI's GPT-4o and GPT-4o mini, plus a zero default for local Ollama models. For other models, the settings page and drush ai-metering:sync-pricing sync rates from the LiteLLM public cost map or the models.dev catalogue. Nothing syncs on install or cron, manual prices are never overwritten by a sync, and when setting manual prices in configuration or Drush, dots in model IDs are encoded as __.
What Testing Showed on Pricing and Callers
In local testing by The DropTimes with OpenAI's GPT-4o mini and embeddings, each row was priced as it was recorded, bringing 25 logged calls to about $0.0015 across reported and estimated tokens. Syncing LiteLLM loaded prices for 3,223 models; any provider or model ID absent from both the manual entries and the synced list falls through the lookup to $0. 6
Testing also showed how failed calls and callers are recorded:
- A failed call left no row. A request to a model name that did not exist was not logged, because usage is recorded only when a response or streamed response arrives.
- Both modules tested named their calls. Calls from AI Automators recorded the caller "ai_automator", and an AI Validations rule recorded "ai_validations".
Monthly Token Budgets and Permissions
Each signed-in user gets a 100,000-token monthly budget by default, with per-role defaults and per-user overrides. Anonymous visitors share a 5,000-token monthly ceiling, alongside a toggle to leave user 0 unrestricted so cron and Drush tasks are not blocked, plus settings to exclude chosen providers or operation types such as embeddings from quotas and logging.
When a user reaches their limit, AI Metering either blocks the call or routes it to a fallback provider such as Ollama. Threshold alerts fire once per month by email, webhook or both, and an optional ai_metering_eca submodule exposes user quota checks and quota-exceeded events to ECA workflows.
Installing AI Metering grants the "Use AI Metering (trigger AI calls)" permission to the Authenticated user role automatically, so signed-in users keep AI access out of the box. Administrators who want to limit AI calls to specific roles can revoke it from Authenticated user; a signed-in user without it is blocked and a warning is logged.
Signed-in users also get a personal "AI usage" tab and block once granted "View own AI usage", which AI Metering's bundled setup recipe grants automatically (or an administrator grants after enabling the module directly). Viewing the admin dashboards, exporting the usage log and administering settings use separate restricted permissions.
Prompt Privacy and Log Retention
AI Metering's usage table stores only numbers and labels (user, provider, model, operation, tokens, cost, latency and caller), never prompt or answer text, and purges a user's records if their account is deleted. 7
AI Observability keeps text off unless enabled, whereas the AI DB Observability Recipe enables prompt and response storage by default unless its inputs are switched off when applying it. In testing with the recipe's defaults, the logged request for a follow-up question to AI Answers search contained the earlier question in the conversation. Guardrail verdicts are saved inside the prompt record, so the guardrail report requires prompt logging.
Retention differs across the three stores:
| Store | What it keeps | Default retention |
|---|---|---|
| Logger DB (AI Observability events) | Event metadata, plus prompt and response text if enabled | 93 days, removed on cron |
| AI Logging | Prompts and replies, if enabled | Pruned on cron by configured record count and age limits |
| AI Metering | Per-call usage rows, no text | Kept until a retention period is set; finished months are summarised on cron |
General Logger DB tools use their own permissions, so access to those should be reviewed alongside AI Observability.
Release Status and Security Coverage
All three core modules (AI, AI Logging and AI Metering) have stable releases covered by Drupal security advisories. Only the optional database reporting and OpenTelemetry add-ons remain in alpha or beta; Drupal's security advisory policy covers stable releases of projects that have opted in, and alpha, beta and release candidate releases are not covered. 8
| Project | Newest release | Status | Advisory coverage |
|---|---|---|---|
| AI (Artificial Intelligence), with AI Observability | 1.5.3 (19 November 2026) | Released | Yes |
| AI Logging | 1.3.4 (16 November 2026) | Released | Yes |
| AI Metering | 1.0.3 (19 November 2026) | Released | Yes |
| AI DB Observability Recipe | 1.0.0-beta3 (16 September 2026) | In development (beta) | No (not opted in) |
| Logger | 1.0.0-alpha6 (27 March 2026) | In development (alpha) | No |
| Logger DB | 1.0.0-alpha5 (17 September 2026) | In development (alpha) | No |
| OpenTelemetry | 1.0.0-beta7 (1 April 2026) | In development (beta) | No |
| AI Observability OpenTelemetry Recipe | 1.0.0-alpha3 (20 July 2026) | In development (alpha) | No (not opted in) |
Before Switching Them On
- Set prices before the first call: AI Metering calculates each call's cost once, when the usage row is written. Sync a price list first, and add manual prices or a provider default for any provider or model ID the public lists do not cover.
- Decide whether to store prompts and replies: switch off the AI DB Observability Recipe's prompt and response inputs when applying it if prompt text should stay out of the database, noting that the guardrail report requires prompt logging.
- Restrict the AI Metering trigger permission if needed: installing AI Metering grants "Use AI Metering (trigger AI calls)" to all signed-in users automatically; revoke it from Authenticated user if only selected roles should spend the AI budget.
- Review log targets and retention: the database recipe sets Logger to write to the database across every channel, and AI Metering keeps per-call rows until a retention period is configured.
The DropTimes was a media sponsor of DrupalCon Rotterdam 2026, where FreelyGive was also a sponsor.
Footnotes
- 1AI Observability README, install configuration and AiLoggingEventSubscriber, AI 1.5.3 and 1.5.0 source code, git.drupalcode.org/project/ai. git.drupalcode.org/project/ai/-/tree/1.5.3/modules/ai_observa…
- 2AI DB Observability Recipe project page, and its README and recipe.yml at 1.0.0-beta3, 16 September 2026. drupal.org/project/ai_recipe_observability_viewsgit.drupalcode.org/project/ai_recipe_observability_views/-/tr…
- 3AI (Artificial Intelligence) 1.5.3 release notes (19 November 2026) and 1.5.0 release notes (25 September 2026), Drupal.org. drupal.org/project/ai/releases/1.5.3drupal.org/project/ai/releases/1.5.0
- 4AI Logging project page and 1.3.4 source code (README, install configuration, delete forms and pruning code), 16 November 2026. drupal.org/project/ai_logginggit.drupalcode.org/project/ai_logging/-/tree/1.3.4
- 5AI Metering project page and 1.0.3 source code: README, CHANGELOG, composer.json, ai_metering.info.yml, ai_metering.install, src/Service/TokenEstimator.php and event subscribers, git.drupalcode.org/project/ai_metering, 14 August 2026. drupal.org/project/ai_meteringgit.drupalcode.org/project/ai_metering/-/tree/1.0.3
- 6Local test by The DropTimes, Drupal CMS 2.2.3 with AI 1.5.0, AI Metering 1.0.2, AI DB Observability Recipe 1.0.0-beta3 and AI Validations 1.3.0, 10 October 2026; AI Validations 1.4.0 caller check, 20 October 2026.
- 7Logger DB 1.0.0-alpha5, install configuration. drupal.org/project/logger_db
- 8Drupal.org release history for each project, accessed 10, 14 and 20 October and 17 and 20 November 2026.


