# See what agents spent

Read what your agents spent under their grants, per day, grouped by category of spend or by agent, in one call.

Use this to chart your agents' spend or to answer "what did Rooms spend this month". One call returns a total, one row per group and one row per day.

**Before you begin:** your agents spend under [grants](https://provenanceauth.com/docs/mandate/concepts/grants.md) with a budget. Export the sandbox account key.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
```

## 1. Spend something to read

In the sandbox, make one purchase first: an agent named Rooms, a grant of 1,000 CHF a month, and a hotel night of 344 CHF with the lodging code 7011. The summaries below ask for CHF, so other sandbox spend doesn't change them.

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/mandate/agents \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "name": "Rooms", "description": "Books stays" }' > agent.json
export AGENT_ID=$(jq -r '.id' agent.json)
curl -s -X POST $PROVENANCE_API/v1/mandate/grants \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d "{
    \"device_id\": \"dev_00000000000000000000000000000001\",
    \"agent_id\": \"$AGENT_ID\",
    \"purpose\": \"Zurich trip\",
    \"constraints\": { \"budget_amount\": 1000, \"budget_window\": \"month\", \"currency\": \"CHF\", \"expires_at\": \"2027-12-31T23:59:59Z\" }
  }" > grant.json
export MANDATE_TOKEN=$(jq -r '.mandate_token' grant.json)
curl -s -X POST $PROVENANCE_API/v1/mandate/intents \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d "{
    \"action_description\": \"Book Hotel Limmat, 1 night: CHF 344\",
    \"agent_session_id\": \"sess_rooms_spend\",
    \"device_id\": \"dev_00000000000000000000000000000001\",
    \"mandate_token\": \"$MANDATE_TOKEN\"
  }" > intent.json
export INTENT_TOKEN=$(jq -r '.intent_token' intent.json)
curl -s -X POST $PROVENANCE_API/v1/mandate/assessments \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d "{
    \"intent_token\": \"$INTENT_TOKEN\",
    \"action_description\": \"Book Hotel Limmat, 1 night: CHF 344\",
    \"context\": { \"transaction_amount\": 344, \"currency\": \"CHF\", \"mcc\": \"7011\" }
  }"
```

**Node**

```ts
const agent = await prov.mandate.agents.create({ name: "Rooms", description: "Books stays" });
const grant = await prov.mandate.grants.create({
  deviceId: "dev_00000000000000000000000000000001",
  agentId: agent.id,
  purpose: "Zurich trip",
  constraints: { budgetAmount: 1000, budgetWindow: "month", currency: "CHF", expiresAt: "2027-12-31T23:59:59Z" },
});
const action = "Book Hotel Limmat, 1 night: CHF 344";
const intent = await prov.mandate.intents.create({
  actionDescription: action,
  agentSessionId: "sess_rooms_spend",
  deviceId: "dev_00000000000000000000000000000001",
  mandateToken: grant.mandateToken,
});
const result = await prov.mandate.assessments.create({
  intentToken: intent.intentToken,
  actionDescription: action,
  context: { transaction_amount: 344, currency: "CHF", mcc: "7011" },
});
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
headers = {"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"}
agent = httpx.post(f"{api}/v1/mandate/agents", headers=headers, json={"name": "Rooms", "description": "Books stays"}).json()
grant = httpx.post(f"{api}/v1/mandate/grants", headers=headers, json={
    "device_id": "dev_00000000000000000000000000000001",
    "agent_id": agent["id"],
    "purpose": "Zurich trip",
    "constraints": {"budget_amount": 1000, "budget_window": "month", "currency": "CHF", "expires_at": "2027-12-31T23:59:59Z"},
}).json()
action = "Book Hotel Limmat, 1 night: CHF 344"
intent = httpx.post(f"{api}/v1/mandate/intents", headers=headers, json={
    "action_description": action,
    "agent_session_id": "sess_rooms_spend",
    "device_id": "dev_00000000000000000000000000000001",
    "mandate_token": grant["mandate_token"],
}).json()
result = httpx.post(f"{api}/v1/mandate/assessments", headers=headers, json={
    "intent_token": intent["intent_token"],
    "action_description": action,
    "context": {"transaction_amount": 344, "currency": "CHF", "mcc": "7011"},
}).json()
```

The purchase passes: the answer has `valid: true`.

```json
{ "valid": true }
```

## 2. Read the summary by category

[`GET /v1/mandate/spend_summary`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-spend-summary) groups by category of spend unless you say otherwise, over the last 30 days.

**curl**

```bash
curl -s "$PROVENANCE_API/v1/mandate/spend_summary?group_by=category&window=7d&currency=CHF" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const summary = await prov.mandate.grants.spendSummary({ groupBy: "category", window: "7d", currency: "CHF" });
```

**Python**

```python
summary = prov.mandate.grants.spend_summary(group_by="category", window="7d", currency="CHF")
```

```json
{
  "object": "spend_summary",
  "group_by": "category",
  "window": "7d",
  "since": "2026-11-17T00:00:00.000Z",
  "until": "2026-11-23T09:13:23.976Z",
  "currency": "CHF",
  "total": 344,
  "entries": 1,
  "groups": [{ "key": "lodging", "label": "Lodging", "total": 344, "entries": 1 }],
  "days": [
    { "date": "2026-11-22", "total": 0, "by_group": {} },
    { "date": "2026-11-23", "total": 344, "by_group": { "lodging": 344 } }
  ],
  "truncated": false
}
```

The response also has `other_currencies`: the spend in any other currency, with its own total (see step 4).

| Parameter | Values | Default |
| --- | --- | --- |
| `group_by` | `category` or `agent` | `category` |
| `window` | `7d`, `30d` or `90d`, in whole UTC days ending today | `30d` |
| `currency` | A three-letter code | The currency most of the window's spend is in |

Every day of the window is in `days`, oldest first, so a chart needs no gap filling. A group with no spend on a day is left out of that day's `by_group`.

## 3. Know where a category comes from

Each purchase has a merchant category code: the one a payment integration reported, else the one the store declared on its cart or in `context.mcc`. A fixed table turns the code into one of nine categories.

| `key` | Label |
| --- | --- |
| `air_travel` | Air travel |
| `lodging` | Lodging |
| `dining` | Dining |
| `ground_transport` | Ground transport |
| `groceries` | Groceries |
| `software` | Software |
| `tickets` | Tickets |
| `bills` | Bills |
| `other` | Other: no code, or a code outside the table |

## 4. Group by agent

`group_by=agent` groups by the agent holding the grant each purchase was debited from. A grant that names no agent is `unassigned`.

**curl**

```bash
curl -s "$PROVENANCE_API/v1/mandate/spend_summary?group_by=agent&currency=CHF" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const byAgent = await prov.mandate.grants.spendSummary({ groupBy: "agent", currency: "CHF" });
```

**Python**

```python
by_agent = prov.mandate.grants.spend_summary(group_by="agent", currency="CHF")
```

```json
{
  "object": "spend_summary",
  "group_by": "agent",
  "window": "30d",
  "currency": "CHF",
  "total": 344,
  "entries": 1,
  "groups": [{ "key": "agt_01M83TWN1D877K95BKP2JY70PB", "label": "Rooms", "total": 344, "entries": 1 }]
}
```

Money in different currencies is never added. The summary is in one currency, and spend in any other is listed in `other_currencies` with its own total. One grant's own entries are at [`GET /v1/mandate/grants/{id}/spend`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-grants-id-spend).

In the console, **Mandate → Agents** shows each agent's spend over 30 days, and an agent's drawer shows it against what people granted.

The same categories decide a person's usual spend, which an agent's `over_usual` default compares each purchase with ([Set an agent's defaults](https://provenanceauth.com/docs/mandate/guides/set-agent-defaults.md)).

## 5. Sort grants and runs by spend

[`GET /v1/mandate/grants`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-grants) and [`GET /v1/mandate/runs`](https://provenanceauth.com/docs/api/runs.md#get-v1-mandate-runs) take `sort`, with `-` in front for descending:

| List | `sort` | Default |
| --- | --- | --- |
| Grants | `created`, `spent` (this budget window), `ends` (when the grant expires) | `-created`, newest first |
| Runs | `created`, `spent` (the run's root grant, this budget window) | `-created`, newest first |

**curl**

```bash
curl -s "$PROVENANCE_API/v1/mandate/grants?sort=-spent&limit=10" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const grants = await prov.mandate.grants.list({ sort: "-spent" });
const runs = await prov.mandate.runs.list({ sort: "-spent" });
```

**Python**

```python
grants = prov.mandate.grants.list(sort="-spent")
runs = prov.mandate.runs.list(sort="-spent")
```

A grant with no budget, or a run with no root grant, sorts last either way. A `next_cursor` carries its order: pass it back with the same `sort`, or the answer is `parameter_invalid` on `cursor`. Runs sorted by anything but newest first are read from the newest 1,000 that match your filters. The run list component takes the same orders (`sorts="-created,created,-spent,spent"`).

## Errors you might see

| Error | Why |
| --- | --- |
| `parameter_invalid` | `group_by`, `window` or `currency` isn't one of the values above; or a list's `sort` isn't one it takes, or its cursor came from another order |
| `spend_summary_unavailable` | The spend entries couldn't be read right now. Nothing is returned in their place; retry shortly |

## See also

- [Set an agent's defaults](https://provenanceauth.com/docs/mandate/guides/set-agent-defaults.md)
- [Grants](https://provenanceauth.com/docs/mandate/concepts/grants.md)
- [Halt a run](https://provenanceauth.com/docs/mandate/guides/halt-a-run.md)
