Documentation · SQL

Query it in SQL

Roles with APP_VIEWER can query AgentLedger's core views directly, without opening the dashboard. These queries cover the questions finance and platform teams ask most.

Roles with APP_VIEWER can query the core views directly. Some starting points:

Agent cost per developer, last 30 days
SELECT user_name, agent, COUNT(*) AS sessions, SUM(turns) AS turns,
             ROUND(SUM(cost_usd), 2) AS cost_usd
      FROM AGENTLEDGER.CORE.SESSIONS
      WHERE started_at >= DATEADD(day, -30, CURRENT_TIMESTAMP())
      GROUP BY 1, 2
      ORDER BY cost_usd DESC;
Agent cost behind each pull request
SELECT repo_slug, number, title, state, sessions, developers,
             ROUND(cost_usd, 2) AS cost_usd
      FROM AGENTLEDGER.CORE.PR_COSTS
      WHERE sessions > 0
      ORDER BY merged_at DESC NULLS FIRST;
Cost by branch
SELECT repo_slug, branch, sessions, turns, ROUND(cost_usd, 2) AS cost_usd, last_activity
      FROM AGENTLEDGER.CORE.BRANCH_COSTS
      ORDER BY last_activity DESC;

Other views

Beyond the three above, these views are available to APP_VIEWER:

  • core.request_costs — cost per model request.
  • core.daily_costs — spend by day, developer and agent.
  • core.session_work_types — the work tags for each session.
  • core.session_prs — sessions matched to pull requests.
  • core.pr_activity — pull request events and timing.
  • core.branch_activity — activity per repository and branch.

Next steps