Skip to main content

Agent activity reports

When teams call agents through the gateway, every call is recorded against the agent as well as the key, in a daily rollup per agent, model and key. The agent activity routes read that rollup and answer "what did this agent do, which keys drove it and what did it cost, day by day". This is the data behind the Agent Usage (A2A) view of the Usage page and the spend column of the Agents page. Nothing needs to be turned on, the rollup is written for every agent call.

The routes need a database and no license feature. They are also one of the places where /agent is a plain report prefix, the same family as /team/daily/activity and /tag/daily/activity, so the query parameters match those pages.

Scenario​

Finance asks the platform team to split last month's agent spend between the two product teams that call the research agent. The team opens the Usage page in the agent view, picks the agent and the month, reads the per key breakdown, which names each team's key, and downloads the day by day CSV for the finance ticket. From the API the same numbers come back in three calls.

Steps​

  1. In the Admin UI open Usage, switch the view to Agent Usage (A2A), pick the month in the date picker and the agent in Filter by agent. The Cost tab shows the agent's spend by model, Top Agents ranks the agents and Top Virtual Keys names the keys that drove the spend.

  2. From the API, read the paged day by day report for the agent.

    curl "http://localhost:4000/agent/daily/activity?agent_ids=agt_01J...&start_date=2026-10-01&end_date=2026-10-31&page=1&page_size=31" \
    -H "Authorization: Bearer $SPANWAY_API_KEY"
  3. For one total with the breakdown by model, provider and key, call the aggregated route with the same filters, and page through the keys with /agent/daily/activity/aggregated/keys when an agent is driven by more keys than one page shows.

    curl "http://localhost:4000/agent/daily/activity/aggregated?agent_ids=agt_01J...&start_date=2026-10-01&end_date=2026-10-31" \
    -H "Authorization: Bearer $SPANWAY_API_KEY"
  4. Click Export Data on the Usage page and pick Day-by-day breakdown by agent and key with the CSV format, or download the same file from the API.

    curl -o agent-october.csv "http://localhost:4000/agent/daily/activity/export?agent_ids=agt_01J...&start_date=2026-10-01&end_date=2026-10-31&export_type=daily_with_keys&format=csv" \
    -H "Authorization: Bearer $SPANWAY_API_KEY"

Expected result​

The paged report answers 200 with one entry per day, each with its metrics and a breakdown by model, provider, key and agent, and metadata with the totals for the whole range.

{
"results": [
{"date": "2026-10-31", "metrics": {"spend": 41.2, "prompt_tokens": 2100000, "completion_tokens": 410000, "total_tokens": 2510000, "successful_requests": 1840, "failed_requests": 3, "api_requests": 1843},
"breakdown": {"models": {"claude-sonnet-5-5": {"metrics": {"spend": 41.2, "total_tokens": 2510000, "api_requests": 1843}}}, "api_keys": {"sk-...a1b2": {"metrics": {"spend": 27.9}, "metadata": {"key_alias": "team-payments"}}}, "entities": {"agt_01J...": {"metrics": {"spend": 41.2}, "metadata": {"agent_name": "research-assistant"}}}}}
],
"metadata": {"total_spend": 1180.4, "total_tokens": 71000000, "total_api_requests": 52110, "total_successful_requests": 52001, "total_failed_requests": 109, "page": 1, "total_pages": 1, "has_more": false}
}

The aggregated route answers the same shape with one result for the range, and the export streams a CSV whose first line is date,entity_id,entity_alias,api_key,key_alias,user_id,user_email,model,spend,flat_cost,prompt_tokens,completion_tokens,api_requests,successful_requests,failed_requests,cache_read_input_tokens,cache_creation_input_tokens or a JSON array of the same rows. The daily_with_users breakdown fills user_id and user_email, so treat the file as personal data and share it only with people who may see who used which agent. The spend in the file adds up to the Total Spend tile of the Usage page for the same filters.

Routes​

MethodPathSummary
GET/agent/daily/activity/aggregatedDaily activity per agent
GET/agent/daily/activity/aggregated/keysKeys ranked by spend for a agent
GET/agent/daily/activity/aggregated/searchSearch the keys with activity for a agent
GET/agent/daily/activity/aggregated/model_top_keysTop keys for one model in a agent
GET/agent/daily/activity/exportDownload agent daily activity as CSV or JSON
GET/agent/daily/activityShow daily spend and usage per agent

agent_ids and exclude_agent_ids are comma separated lists of agent ids. model and api_key narrow the report to one model or one key. start_date and end_date are YYYY-MM-DD, and timezone is an offset in minutes so the days line up with the caller's calendar. /aggregated/search finds keys of the agent by alias with search, and /aggregated/model_top_keys ranks the keys that drove one model_group.

Who can use it​

The routes are for proxy admins and admin viewers by default, and they see every agent and may pass any agent_ids. Any other key is refused with a 401 that says only a proxy admin may use the route, unless an admin grants the routes to it through the key's allowed_routes or a custom role. A key granted the routes sees only the agents its key and team are granted, or that it owns when its access is unrestricted, and ids outside that set are dropped from the request silently, so a report for an agent it cannot see comes back empty rather than refused. Agents are also hidden from internal users when disable_agents_for_internal_users is set, see the settings reference. The routes answer 405 to any method but GET.

Errors​

StatusWhat it meansFix
401The call carried no key or an invalid one.Send Authorization: Bearer <virtual key>.
401 Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams. Route=/agent/daily/activity...The key is not a proxy admin or admin viewer, and the route is not granted to it.Use an admin key, or add the routes to the key's allowed_routes or custom role.
403 agents disabled for internal usersdisable_agents_for_internal_users hides agents from the caller's role.Call with an admin key, or turn on allow_agents_for_team_admins for team admins.
400 on an aggregated routestart_date and end_date are missing or the range is longer than the aggregated routes allow.Send both dates and a shorter range, or use the paged route.
422export_type or format is not one of the allowed values, or page_size is out of range.Use daily, daily_with_keys, daily_with_models or daily_with_users and csv or json.
500 database not connectedThe gateway has no database.Set DATABASE_URL and restart the gateway.
500 Failed to fetch analytics. The gateway log has the cause.The aggregated, keys, search, top keys or export query failed in the database.Read the gateway log line Daily activity export failed or the error logged just before it, fix the database problem and retry.
Empty results with total_pages 0No agent in the request is visible to the caller, or no call was made in the range.Check the ids on the Agents page and widen the range.

Logs​

LevelLineMeaningAction
ERRORDaily activity export failed: ...An export or aggregated query failed, and the caller got the Failed to fetch analytics 500.Check the database connection and the error after the colon.

Audit​

Every export writes an exported row on Spanway_DailySpend with the entity, the agent ids, the date range, the breakdown and the format, so you can see who downloaded usage data. Reading the report on screen writes nothing.

  • Usage page describes the Agent Usage (A2A) view and the Export Data dialog.
  • A2A agents explains how agent calls are recorded and granted.
  • Agents page shows the per agent spend column that reads the same rollup.
  • User agent analytics report per tool and SDK instead of per registered agent.
  • Run ledger explains one agent run in detail.
  • Cost exports cover the export formats.