AI Usage Record¶
What one model call spent, and what it cost at the price of the day.
This app writes no row here¶
The app makes no model call, so it has nothing to record. Whatever ran the agent writes these, the same way it writes the AI Agent Thread. The app owns the table, the read views, and the retention.
Write one over the REST API:
curl -s -X POST -H "Authorization: Token $NAUTOBOT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"thread": "<uuid>", "agent": "<uuid>", "model": "<uuid>",
"input_tokens": 1200, "output_tokens": 340}' \
"https://nautobot.example.com/api/plugins/ai-models/ai-usage-records/"
Post a list to write a whole run at once. Eight rows per run as eight HTTP calls is not viable.
There is no update route. Nothing rewrites a spend that already happened. Delete a wrong row.
Fields¶
| Field | Type | Required | Description |
|---|---|---|---|
thread |
AI Agent Thread | Yes | The run this call belongs to. If you delete the thread, you also delete its usage. |
agent |
AI Agent | Yes | Which agent made the call. A subagent call is its own, not the supervisor's. |
model |
AI Model | Yes | The model that the call used, which is not always the model of the thread agent. |
input_tokens |
Integer | Yes | Tokens sent. |
output_tokens |
Integer | Yes | Tokens returned. |
cached_input_tokens |
Integer | Yes | Input tokens the provider served from its cache. |
reasoning_tokens |
Integer | Yes | Tokens that the model used to think. Usually billed as output. |
input_cost |
Decimal | No | What the input cost. Written by the app, read-only over the API. |
output_cost |
Decimal | No | What the answer cost. Written by the app, read-only over the API. |
usage_payload |
JSON object | No | The usage object the provider returned, stored whole. |
recorded_at |
Date and time | Yes | When the call was made. Retention measures from here. |
The cost is frozen¶
AIModel.input_cost_per_million changes when a vendor changes its price. If the app calculated a
cost on read, the cost of last quarter would change with no notice.
So the app calculates the cost once, at the price on record when it writes the row, and stores it. A client cannot set it: the two fields are read-only over the API.
CAUTION: An empty cost means that the model had no recorded price at that time. It does not mean the call was free.
The write helper does the arithmetic:
from nautobot_ai_models.services import usage
usage.record(thread, agent, ai_model, input_tokens=1200, output_tokens=340)
Why this model is different¶
Every other model in this app is an OrganizationalModel or a PrimaryModel. This one is a
BaseModel, and it declares only two extras_features.
The volume decides it. AI Agent Thread argues the other way in its own docstring: a thread changes state two or three times in a whole run, so change logging costs a few rows. There is a usage row for every model call. A change log entry for each one would double the write cost and fill the log that an operator reads for governance. A webhook for each one would send too many events.
What this costs you: no custom fields, no tags, no notes, no relationships, and no change log on these rows.
Totals¶
The app stores neither. total_tokens adds the input and the output. The provider's own figure is
in usage_payload, and it does not always equal the sum.
Retention¶
The Prune Agent Threads Job deletes these. It deletes the usage of every expired thread whether or not you ask it to delete the thread rows, because usage is state and the cascade from the thread only fires when the thread itself goes.
The window is checkpoint_retention_days. See Install and Configure.
NOTE: A deployment that reports on cost over years needs a daily roll-up of these rows. Build that in a reporting system. This table holds the record of each call, and the report belongs in that system.

