How do I track cost per agent run?
Add a run ID header to your agent workflow so Cognocient shows total cost, step count, and model breakdown for each individual execution.
Goal: See exactly what each agent run cost — not just an aggregate monthly total — and set a per-run budget so a single runaway execution can't consume your entire feature budget.
Time: 15 minutes to instrument. Data appears immediately.
Step 1 — Generate a unique run ID per execution
The key change: generate a fresh UUID at the start of each agent execution and pass it as X-Cost-Run-ID on every API call within that run.
Generate run_id once per agent execution, not once per step. Every step in the same run gets the same ID — that's how Cognocient groups them into a single cost entry.
Step 2 — View runs in the dashboard
Go to Dashboard → Run Budgets. Each X-Cost-Run-ID value appears as a row showing:
- Feature and subagent count
- Number of API calls
- Spend against its ceiling
- Status (active / blocked)
- Last activity timestamp
Workstreams (Dashboard → Workstreams) is a related but separate view — it groups calls by X-Cost-Session, not by run ID, so use it for session-level grouping rather than per-run cost.
Step 3 — Set a per-run spending limit (recommended)
A per-run limit can only be set when you create a budget, not added afterward — decide on it up front.
Go to Budgets → New Budget:
| Field | Value |
|---|---|
| Name | document-processor per run |
| Scope | Feature |
| Scope value | document-processor |
| Monthly limit | Your normal monthly budget |
| Per-Run Spend Limit (checkbox) | e.g. $1.00 (or whatever a normal run should cost) |
| Enforcement | Block |
When a single run exceeds its per-run limit, only that run is blocked — other concurrent runs with different IDs continue normally. If you don't set an explicit per-run limit, runs still fall back to Cognocient's account-wide default run budget ($25).
Step 4 — Check budget before each step (for long-running agents)
For agents that run dozens of steps, check the budget before each step so you can exit gracefully instead of being cut off mid-execution:
Related articles
Tag Your First AI Call
Add 2 headers to your existing code and see per-feature spend in under 5 minutes.
Set a Monthly Spending Limit
Create a hard budget enforced at the proxy before charges reach your provider bill.
Cut Your AI Bill with One Click
Use AI Advisor recommendations to apply model downgrades and caching without code changes.