Daily and monthly cost summaries per agent and per company, the built-in cost chart views, writing custom cost queries, and exporting cost_events to CSV for finance teams.
Build cost dashboards from cost_events, identify expensive agents and tasks, and apply four proven cost-reduction techniques.
-- Monthly cost summary dashboard
WITH monthly AS (
SELECT
a.name AS agent,
a.role,
ce.model,
COUNT(*) AS invocations,
SUM(ce.input_tokens) AS total_input_tokens,
SUM(ce.output_tokens) AS total_output_tokens,
SUM(ce.cost_usd) AS total_cost,
AVG(ce.cost_usd) AS avg_cost_per_call,
a.monthly_budget_usd AS budget,
ROUND(100 * SUM(ce.cost_usd)
/ a.monthly_budget_usd) AS pct_of_budget
FROM cost_events ce
JOIN agents a ON a.id = ce.agent_id
WHERE ce.company_id = 'your-company-id'
AND date_trunc('month', ce.created_at) = date_trunc('month', now())
GROUP BY a.id, a.name, a.role, ce.model, a.monthly_budget_usd
)
SELECT *
FROM monthly
ORDER BY total_cost DESC;
-- Most expensive individual issues
SELECT
i.title,
a.name AS agent,
ce.model,
ce.cost_usd,
ce.input_tokens + ce.output_tokens AS total_tokens,
i.created_at
FROM cost_events ce
JOIN issues i ON i.id = ce.issue_id
JOIN agents a ON a.id = ce.agent_id
WHERE ce.company_id = 'your-company-id'
ORDER BY ce.cost_usd DESC
LIMIT 20;
Not every agent needs Opus. A classification or summarisation agent can often use Haiku at 1/100th the cost:
{ "model": "claude-haiku-3-5" } // $0.00025/1K input vs $0.015 for Opus
Savings: up to 98% for compatible tasks.
Every token in the system prompt is re-sent as input on every call. Audit your prompts:
SELECT name, length(system_prompt) AS prompt_chars
FROM agents
WHERE company_id = 'your-company-id'
ORDER BY prompt_chars DESC;
Reduce from 800 → 200 characters = 25% input token reduction per call.
Instruct agents to be concise. Add to every system prompt:
Be concise. Maximum 3 paragraphs unless detail is explicitly requested.
From every 5 minutes to every 15 minutes = 3x fewer invocations for low-urgency agents:
UPDATE companies
SET heartbeat_cron = '*/15 * * * *'
WHERE slug = 'my-company';
-- Project end-of-month spend based on current burn rate
SELECT
SUM(cost_usd) AS mtd_spend,
SUM(cost_usd)
/ EXTRACT(day FROM now())
* EXTRACT(day FROM date_trunc('month', now())
+ interval '1 month' - interval '1 day') AS projected_month_total
FROM cost_events
WHERE company_id = 'your-company-id'
AND date_trunc('month', created_at) = date_trunc('month', now());