InitRunner

Cost Tracking

InitRunner estimates USD cost for every agent run using the genai-prices library (a transitive dependency of pydantic-ai). A live run surfaces PydanticAI's RunUsage.cost on the result (and in the CLI stats line as $0.0123) when the model is priced. Historical initrunner cost reports still recompute from token counts stored in the audit trail — nothing extra to configure.

Cap a single logical run with guardrails.cost_limit (since v2026.8.2). Approval resume keeps one logical budget by replaying prior RunUsage. Unpriced models skip enforcement. Daemon, bot, and delegation budget trackers prefer live cost and fall back to the token estimate.

When a provider reports a prompt-cache hit, the tokens: … stats line appends cache hit: NN% (since v2026.7.4). The suffix is omitted when the ratio is zero or unreported.

Supported providers: OpenAI, Anthropic, Google, Groq, Mistral, xAI, DeepSeek, OpenRouter, Together, Fireworks.

CLI Commands

The initrunner cost command group provides cost analytics from the audit database.

cost report

Cost breakdown by agent.

initrunner cost report
initrunner cost report --agent my-agent
initrunner cost report --since 2026-04-01T00:00:00Z --until 2026-04-07T00:00:00Z

Output:

              Cost Report
┏━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━┓
┃ Agent      ┃ Requests ┃ Tokens In ┃ Tokens Out ┃ Est. Cost ┃ Avg/Request ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━┩
│ code-review│    142   │   890,200 │    312,400 │    $4.82  │    $0.0340  │
│ support    │     38   │   210,500 │     95,300 │    $1.22  │    $0.0321  │
└────────────┴──────────┴───────────┴────────────┴───────────┴─────────────┘

Total: 180 requests, $6.04 estimated

Filters: --agent, --since, --until, --audit-db.

cost summary

High-level spend overview with time breakdowns and top agents.

initrunner cost summary

Shows today, this week, this month, and all-time totals. Lists the top 5 costliest agents and a 7-day daily trend.

cost by-model

Cost grouped by model and provider.

initrunner cost by-model
initrunner cost by-model --since 2026-04-01T00:00:00Z

cost estimate

Predict per-run cost from a role YAML before deploying.

initrunner cost estimate role.yaml
initrunner cost estimate role.yaml --prompt-tokens 1000

Output:

            Cost Estimate
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Metric                        ┃     Value ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Model                         │ openai:…  │
│ Est. input tokens             │    3,400  │
│ Est. output tokens (typical)  │    1,228  │
│ Est. output tokens (max)      │    4,096  │
│ Per-run cost (typical)        │  $0.0098  │
│ Per-run cost (max)            │  $0.0241  │
│ Trigger firings/day           │      24.0 │
│ Daily estimate                │  $0.2352  │
│ Monthly estimate              │  $7.0560  │
└───────────────────────────────┴───────────┘

The estimator uses the raw system prompt only (skills are excluded and labeled conservative). If the model is unresolved (no provider/name in the role config), token estimates are shown but USD projections are skipped.

USD Cost Budgets

In addition to token budgets, daemon and bot modes support USD-based cost limits via guardrails.

guardrails:
  daemon_daily_cost_budget: 5.00    # USD per day
  daemon_weekly_cost_budget: 25.00  # USD per week
FieldTypeDefaultDescription
daemon_daily_cost_budgetfloat > 0nullMaximum USD spend per calendar day
daemon_weekly_cost_budgetfloat > 0nullMaximum USD spend per ISO week

Cost is estimated after each run using genai-prices and accumulated in the tracker. Daily cost resets at midnight in the configured budget_timezone (UTC by default). Weekly cost resets when the ISO year-week changes. Warnings are logged at 80% and 95% consumption. When the budget is exhausted, further trigger executions are skipped.

Budget counters are persisted to the audit database after each run. Restarting a daemon or bot restores the counters, so spend tracking survives process restarts (since v2026.4.11).

When a cost budget is configured, InitRunner validates at startup that pricing data is available for the role's model and provider. If genai-prices doesn't cover that model, the daemon exits with a clear error rather than silently skipping enforcement.

Budget Timezone

By default, daily and weekly resets use UTC. Set budget_timezone to use a different IANA timezone:

guardrails:
  daemon_daily_cost_budget: 5.00
  budget_timezone: "America/New_York"

budget_timezone is a role field. The --budget-timezone flag was removed in v2026.8.11, along with the --autopilot and --bot modes it applied to.

Token budgets and cost budgets are enforced independently. You can use both:

guardrails:
  daemon_token_budget: 5000000
  daemon_daily_token_budget: 500000
  daemon_daily_cost_budget: 10.00
  daemon_weekly_cost_budget: 50.00

Either limit being hit will pause the daemon.

Dashboard

The /cost page in the dashboard provides visual cost analytics.

  • Summary strip at the top shows today, this week, this month, and all-time spend totals.
  • Period selector (7d / 30d / 90d) controls the chart and both breakdown tables below.
  • Spend chart shows daily cost as a bar chart. Hover any bar for date, cost, and run count.
  • By Agent table breaks down cost per agent with runs, tokens, avg cost/run, and total. It also shows thinking and reasoning token counts per agent. Rows link to the agent detail page.
  • By Model table breaks down cost per model/provider combination, including thinking and reasoning token counts per model.

The audit log (/audit) also shows a per-run cost column and the per-run thinking and reasoning token counts, and includes all three in the detail drawer.

All cost values show N/A when pricing data is unavailable for a model/provider.

Thinking and Reasoning Tokens

For models with extended thinking enabled (configured through model.thinking, see Reasoning), InitRunner reads the thinking/reasoning token count from the model's usage details and records it on every run. The counts are stored in the audit trail as thinking_tokens and reasoning_tokens and default to 0 for models that do not produce thinking tokens.

Both fields come from the same underlying usage count. thinking_tokens is captured on the non-streaming path, and reasoning_tokens carries the count from the final streaming event; for non-streaming runs reasoning_tokens mirrors thinking_tokens.

The dashboard surfaces these counts in the By Agent and By Model tables on the /cost page and in the audit table and run detail drawer. They are informational only. USD cost is still computed from input and output tokens (tokens_in and tokens_out) through genai-prices, and thinking/reasoning tokens are not priced separately.

Live Cost During Streaming

When streaming a run from the dashboard, the TokenMeter shows a running estimated output cost (prefixed with ~). The estimate uses a character-to-token heuristic (chars / 4) and is corrected by the final result event. Input cost is unknown mid-stream and only appears in the final total.

Budget Progress Bar

Agent detail pages show a budget progress bar for any daemon agent with cost or token budgets configured. Each configured budget (daily tokens, daily cost, weekly cost, lifetime tokens) gets a gauge showing current consumption, limit, and percentage. Colors: green (under 80%), yellow (80-95%), red (over 95% or exhausted). The bar auto-refreshes every 30 seconds.

Dashboard API

EndpointDescription
GET /api/cost/summaryToday/week/month/all-time totals, top agents (each carries thinking_tokens and reasoning_tokens), daily trend
GET /api/cost/by-agentPer-agent cost breakdown. Each row includes thinking_tokens and reasoning_tokens. Filters: since, until, agent_name
GET /api/cost/dailyDaily cost time series. Params: days (default 30), agent_name
GET /api/cost/by-modelCost grouped by model/provider. Each row includes thinking_tokens and reasoning_tokens. Filters: since, until
GET /api/cost/by-toolPer-tool cost breakdown. Each row includes tool_name, usage_count, run_count, tokens_in, tokens_out, total_cost_usd, and avg_cost_per_use. Filters: agent_name, since, until
GET /api/agents/{id}/budget-progressLive budget gauges (consumed/limit/percent/warning level) per budget type

How Cost is Calculated

  1. Every agent run records tokens_in, tokens_out, model, and provider in the audit database.
  2. Cost queries aggregate tokens via SQL (GROUP BY agent/model/day) and apply genai-prices per group.
  3. If any group in a rolled-up total is unpriceable (unknown model/provider), the aggregate total shows N/A rather than a misleading partial sum.

Per-Tool Cost Attribution

Since v2026.4.12, the audit trail also records cost at the individual tool-call level. This happens automatically, with no configuration needed.

Each tool call tracks:

FieldDescription
tool_nameName of the tool invoked
usage_countTotal number of individual calls
run_countDistinct runs that used this tool
tokens_inInput tokens attributed to the tool
tokens_outOutput tokens attributed to the tool
total_cost_usdAggregated USD cost
avg_cost_per_useAverage cost per invocation

The dashboard cost page includes a Tool Cost table showing this breakdown. Use it to identify which tools drive the most spend (e.g., shell calls that produce large outputs vs. lightweight datetime lookups).

On this page