# Usage, activity & audit log

`GET /api/usage` reports counts against plan limits, the AI credit position, and measured usage for a period. Dashboard → Analytics shows the same data, with a list of what is not measured yet.

## Usage

- `?period=` month, last_month, 7d, 30d (default) or 90d, in whole UTC days; `?project=<id>` for one project.
- Returns `totals` per metric, a daily `series`, `byProject`, measured storage and database sizes (with when they were measured), deploy time and build-machine time, and `notMeasured`.
- Measured: resource counts, deploys and build time, database queries and rows read and written, storage bytes and object counts (daily), database sizes (daily), memory and vector operations, emails, end-user logins, checkout sessions, agent runs, AI requests, embeddings and AI cost.
- Not measured yet: requests and bandwidth to sites and apps, server-app running time, function-URL traffic, errors and latency.
- Function test runs (Invoke in the dashboard, the API or a connector) are their own metric, `function_test_runs`, never counted as traffic. In the 30-day `metrics`, `testRuns30d` and `totalTestRuns` count them; `invocations30d` and `totalInvocations` are null while function-URL traffic is not measured.

## What needs attention

`GET /api/attention` is a ranked to-do list: failed or stuck deploys, domains expiring or waiting on nameservers, failed renewals, refunds owed, plan limits and AI credit running low, failed mail and an unverified email. Each item links to the page that fixes it. The dashboard Overview shows it at the top; the AI connector's needs_attention tool reads it.

## Audit log

- Records changes: creates, deletes, settings, keys, members, money events. Admins read it in Dashboard → Audit Log (filter, export to CSV) or `GET /api/orgs/:id/audit-logs`.
- High-volume data calls (queries, memory writes, vector upserts, object deletes, sends, checkout creation, agent runs) are counted in usage instead of written one row each.
- `GET /api/activity` is the short recent feed on the Overview; non-admins do not see member, key, billing or account rows.

## Reference

**SDK**

```js
const usage = await hk.usage.get();   // counts, limits, aiCredits, metrics (30 days)
```

**CLI**

```bash
harakumo usage
```

**REST**

```http
GET /api/usage?period=30d&project=12
GET /api/attention
GET /api/activity
GET /api/orgs/:id/audit-logs?action=&before=&limit=     # admin
```
