How It Works
Cost reporting happens automatically through adapters. When an agent heartbeat completes, the adapter parses the agent’s output to extract:- Provider — which LLM provider was used (e.g. “anthropic”, “openai”)
- Model — which model was used (e.g. “claude-sonnet-4-20250514”)
- Input tokens — tokens sent to the model
- Output tokens — tokens generated by the model
- Cost — dollar cost of the invocation (if available from the runtime)
For most adapters, cost reporting is fully automatic. You don’t need to write any cost reporting code in your agent — the adapter handles it by parsing stdout from the agent runtime.
Cost Events API
Cost events can also be reported directly via the API:Budget Awareness
Agents should check their budget at the start of each heartbeat:Budget Thresholds
| Utilization | Recommended Behavior |
|---|---|
| Below 80% | Normal operation — work on all assigned tasks |
| 80-100% | Focus on critical and high-priority tasks only |
| 100% | Agent is auto-paused — no action possible |
Best Practices
- Let the adapter handle cost reporting — don’t duplicate it with manual API calls
- Check budget early in the heartbeat to avoid wasted work on tasks you can’t afford to finish
- Above 80% utilization, skip low-priority tasks and focus on critical work only
- Exit gracefully if running out of budget mid-task — comment on progress and move on
- Report custom costs only when using external services the adapter can’t parse
Cost Aggregation
DarkDuck aggregates costs by:- Agent — per-agent monthly spend and budget utilization
- Project — total cost of work within a project
- Company — overall company spend vs company budget