Usage and cost¶
The Chat, Simple Chat and Decision nodes return a usage object with the
token counts the AI provider reported. With the optional FlowDrop AI Provider Metering
submodule enabled, usage also carries an estimated cost. The AI nodes of this
module tag their provider calls with the FlowDrop run they belong to, so AI
Metering can group the calls of one run.
The usage output¶
| Key | Type | Notes |
|---|---|---|
input |
integer or null | Input tokens. |
output |
integer or null | Output tokens. |
total |
integer or null | Total tokens. |
reasoning |
integer or null | Reasoning tokens. |
cached |
integer or null | Cached input tokens read. |
cache_write |
integer or null | Input tokens written to the cache. |
cost |
object | Only when a cost calculator prices the call. See Cost. |
A count is null when the provider does not report it. A null is not a zero.
A call that reports neither input nor output tokens has no cost key.
usage is an output port of the Chat, Simple Chat and Decision nodes, so the
next node in the workflow can read it. The Decision node hides the port by
default; show it on the node to connect it.
Example output of a Chat node without the submodule. The numbers are an example.
{
"response": "The tone is formal and matches the guide.",
"model": "claude-sonnet-5-5",
"provider": "anthropic",
"usage": {
"input": 1840,
"output": 312,
"total": 2152,
"reasoning": null,
"cached": 1200,
"cache_write": null
}
}
Which nodes return usage¶
Chat, Simple Chat and Decision return this usage object. The Decision node
needs drupal/ai 1.6 or later, the first release with the Decision operation
type, and hides its usage port by default. AI Metering reads the
token counts only from chat responses: for a Decision call it estimates them
from the input text, so its log can differ from the node's usage. The
Reason node, which FlowDrop provides, shows no usage. The other AI nodes of
this module do not return it.
tokens_used is deprecated¶
The Chat and Simple Chat nodes still return tokens_used. It is deprecated in
2.2.0 and removed in 3.0.0. Read usage.total instead. Unlike tokens_used,
which is 0 when the provider reports nothing, usage.total is null.
Run tags¶
The AI nodes of this module pass these tags with their provider calls. They identify the workflow run, so a logger or event subscriber can attribute the call. Calls from the Reason node and from the guardrail plugins in the Guardrails node carry no run tags.
| Tag | Value |
|---|---|
flowdrop |
Always present. |
flowdrop_workflow:<id> |
The workflow ID. |
flowdrop_execution:<id> |
The execution ID of the run. |
flowdrop_node:<id> |
The node ID. |
A tag with an empty ID is left out. If the runtime gives the node no execution
context, only flowdrop is set.
Cost¶
Install the optional FlowDrop AI Provider Metering submodule
(flowdrop_ai_provider_metering). It needs the
AI Metering module, version
1.1.0 or later.
composer require drupal/ai_metering
drush pm:enable flowdrop_ai_provider_metering
The submodule replaces the module's cost calculator with one that prices the
call with AI Metering's price list. usage.cost then appears on the nodes
that expose usage:
| Key | Notes |
|---|---|
input |
Cost of the input tokens. |
output |
Cost of the output tokens. |
cached |
Cost of the cached tokens read. |
cache_write |
Cost of the cache writes. |
total |
Sum of the four. |
currency |
Always USD. |
The cost is an estimate in US dollars, based on the prices AI Metering holds.
It is not an invoice. The submodule prices the call with AI Metering's public
cost calculator (ai_metering.cost_calculator), the same one AI Metering uses
for its own log. For providers that report the input tokens inclusive of the
cached tokens, the cached tokens are taken out of the input before pricing
(quota.cache_inclusive_providers in ai_metering.settings).
A model AI Metering has no pricing entry for, such as one its price sync has
not picked up yet, gets no cost. A cost of 0 means AI Metering prices
the model as free. On a fresh install of AI Metering 1.1.0 that is the case
for every Ollama model (the ollama:_default entry). If pricing a call fails,
the node keeps its output without a cost and the error is logged in the
flowdrop_ai_provider channel. AI Metering's own log stores a call without a
price with a cost of 0.
The cost of a node matches the cost AI Metering logs, except in these cases (AI Metering 1.1.0):
- Provider without token counts. AI Metering estimates the tokens from the
text and logs a cost. The node keeps the counts
nulland has nocost. - Calls AI Metering reroutes. When a user is over quota, AI Metering can answer with a fallback provider and log the call at no cost. The node still prices the call at the rate of the model it asked for, so its cost is higher than in AI Metering's log.
- Wrapper providers. AI Metering does not log calls of a wrapper provider
such as
chat_translation, only the inner call to the real provider. The Chat and Simple Chat nodes call the real provider, so this does not apply to them.
Example, the same Chat node with the submodule enabled. The numbers are an example.
{
"usage": {
"input": 1840,
"output": 312,
"total": 2152,
"reasoning": null,
"cached": 1200,
"cache_write": null,
"cost": {
"input": 0.00192,
"output": 0.00468,
"cached": 0.00036,
"cache_write": 0,
"total": 0.00696,
"currency": "USD"
}
}
}
Run totals in AI Metering¶
With the submodule enabled, it reads the flowdrop_execution:<id> tag before
each call and adds two tags that AI Metering understands:
aim_context:<UUID>, a UUID derived from the execution ID. All calls of one run get the same one, so AI Metering can group them.aim_feature:flowdrop, which AI Metering uses as the caller.
AI Metering stores both with each call, in the context_id and caller
columns of its ai_metering_usage table. The total of a run is the sum of the
rows that share its context_id. If a call already carries an aim_context
tag, the submodule leaves it alone.
Calls not in a run total¶
A run total in AI Metering does not include:
- calls from the Reason node. FlowDrop's
ReasonRequestcarries no run IDs, so the call reaches AI Metering without the run tags and is logged on its own; - calls from guardrail plugins inside the Guardrails node.