Agents

An agent's tokens and cost per model per day

Tokens (input, output, cache reads and writes) and cost per model per UTC day over the range, from the daily dependency aggregate. Costs a model call did not report are estimated from LastPing's price table and labelled estimated.

Usage an agent reported only through an OTLP metrics export (for example Cursor, which sends metrics and no traces) fills the days and models its traces do not cover, with origin: metrics. Trace and metric figures for the same day, provider and model are never added together: the trace-derived row wins.

get/api/v1/agents/{id}/usage

Request

  • Base URL: https://app.lastping.dev
  • URL: https://app.lastping.dev/api/v1/agents/{id}/usage
  • Auth: API key in header X-Api-Key

Query parameters

range'24h' | '7d' | '30d'

24h, 7d (default) or 30d. The data is daily, so a range covers every UTC day that overlaps it: 24h reads yesterday and today.

projectstring

Only usage from the traced runs of this project: runs whose Claude Code hook start carried this label (Run.project, the name of the folder that holds the git repository the session worked in, or the folder's name when it is not in a repository; a name, never a path). days is then read from those runs' own totals (each run's tokens and cost, as the Runs list shows them): ONE row per UTC day of the run's start, with model and provider empty (a run's totals are not split by model), and origin: traces. Usage reported only through a metrics export carries no project and is left out (project_scope). by_project narrows to the label too. Cleaned like GET /api/v1/runs's project; a value that cleans to nothing is refused with 400 INVALID_FILTER.

Response

The agent's usage.

range'24h' | '7d' | '30d' required
projectstring required

The project filter this response applied, after cleaning (a path reduced to its last element), or an empty string when there was none.

project_scopestring required

Where every figure that names a project comes from: traces_only. A project label rides a Claude Code hook's start ping, so only traced runs carry one; usage reported only through an OTLP metrics export has no project and is in no by_project row, nor in days under a project filter. A plain string, not an enum, so a new value never breaks a client.

Example response

{
  "range": "7d",
  "days": [
    {
      "day": "2026-09-20",
      "model": "claude-sonnet-4-5",
      "provider": "anthropic",
      "tokens_in": 182340,
      "tokens_out": 20411,
      "tokens_cache_read": 95012,
      "tokens_cache_write": 4100,
      "cost_usd": "0.853221",
      "cost_source": "estimated",
      "origin": "traces"
    }
  ],
  "project_scope": "traces_only",
  "by_project": [
    {
      "project": "reddit-bot",
      "runs": 14,
      "tokens_in": 1402211,
      "tokens_out": 38120,
      "tokens_cache_read": 1190455,
      "tokens_cache_write": 60102,
      "cost_usd": "3.412210",
      "cost_source": "mixed"
    }
  ]
}

Changes

No recorded changes to this operation across all 2 revisions of this API.