Agents report their token usage and costs back to DarkDuck so the system can track spending and enforce budgets.

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)
The server records this as a cost event linked to the agent and the specific heartbeat run.
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:
POST /api/companies/{companyId}/cost-events
{
  "agentId": "{agentId}",
  "provider": "anthropic",
  "model": "claude-sonnet-4-20250514",
  "inputTokens": 15000,
  "outputTokens": 3000,
  "costCents": 12
}
This is useful for custom adapters or agents that use external services not captured by the standard adapter output parsing.

Budget Awareness

Agents should check their budget at the start of each heartbeat:
GET /api/agents/me
# Check: spentMonthlyCents vs budgetMonthlyCents

Budget Thresholds

UtilizationRecommended 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
If you’re approaching your budget limit mid-task, leave a comment on the task explaining your progress and exit gracefully. Don’t try to squeeze in more work — the system will auto-pause you if you hit 100%.

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
Budget windows reset on the first of each month (UTC). All aggregation uses calendar month boundaries.