# Reconcile runs and costs

> **TL;DR** — Tag each job with your own id (`client_reference_id`). `GET /v2/runs?from=…&to=…` lists your runs (jobs, Wandura Ref 1.0 tasks and runs together) with when each started and ended, what it made and what it cost in the end. `GET /v2/usage` gives your spend per day. A day's total equals the sum of its runs' `amount_charged`, to the micro-dollar, so you can match it against your own records like an invoice.

Both routes take your API key and read only your key's product: a live key lists live runs, a test key test runs.

## Tag a run with your own id
Send `client_reference_id` (a string of 1 to 255 characters, for example the run id in your backend) when you create the work:

| Where | How |
|---|---|
| `POST /v2/jobs` | `"client_reference_id": "be_run_8812"` in the body. |
| `POST /v2/runs`, `POST /v2/styles/{style}` | The same field in the body. |
| Wandura Ref 1.0 (`POST /api/v3/contents/generations/tasks`) | `client_reference_id` beside your `id`. Without it, your `id` is used. |

It comes back on the job (`client_reference_id`), the run, the task (`wandura.client_reference_id`) and their webhooks, and `GET /v2/runs?client_reference_id=be_run_8812` finds it. It is part of the request: the same `Idempotency-Key` (or Ref `id`) with another value is refused with `409`. Runs made before you sent it have none: match those by `id` and `created_at`.

## List runs
```bash
curl "https://api.wandura.ai/v2/runs?from=2026-10-30&to=2026-10-30&timezone=Asia/Ho_Chi_Minh" \
  -H "Authorization: Bearer $WANDURA_API_KEY"
```

| Query | Meaning |
|---|---|
| `from`, `to` | A date (`2026-10-30`) is that whole day in `timezone`: `from` from its start, `to` through its end. A time (`2026-10-30T07:00:00Z`) is that instant; `to` is then excluded. Both optional. |
| `timezone` | An IANA name such as `Asia/Ho_Chi_Minh`. Default `UTC`. |
| `client_reference_id`, `status`, `path`, `style` | Filters. `path` is `jobs`, `ref`, `direct`, `gateway` or `standard` (runs made at `POST /v2/runs`). |
| `limit` | 1 to 100, default 50. |
| `starting_after` | The `id` of the last run of the previous page. Keep paging while `has_more` is true. |

Newest first. Each item is a [run object](https://docs.wandura.ai/developers/api-v2/concepts) (a job's `job_id` and a Ref task's `id` are its `id`; `path` says which door it came through; a failed run carries `error.code`) plus:

| Field | Meaning |
|---|---|
| `started_at` | When it started running, after any wait for a slot. `null` until then. Time in line = `started_at` − `created_at`. |
| `finished_at` | When it ended. `null` until then. Time running = `finished_at` − `started_at`. |
| `resolution` | The resolution asked for (for example `480p`), else read off the video it made. |
| `output_duration_s` | Seconds of the video (or audio) it delivered. `null` without one. |
| `amount_charged` | What it costs you in the end, `{credits, usd}`: its price when it delivered, `0` when it ended free (failed, blocked, timed out, cancelled while queued) or ran on a test key. `null` while its money is still held. |

`price` stays what it always was (the amount held, then charged); with a partner price, `list_price` and `discount` sit beside it.

## Spend per day
```bash
curl "https://api.wandura.ai/v2/usage?from=2026-10-01&to=2026-10-30&timezone=Asia/Ho_Chi_Minh" \
  -H "Authorization: Bearer $WANDURA_API_KEY"
```

```json
{
  "object": "usage", "product": "prod_…", "livemode": true, "timezone": "Asia/Ho_Chi_Minh",
  "from": "2026-10-01", "to": "2026-10-30", "group_by": "day", "path": null,
  "total": { "runs": 412, "charged_runs": 398, "held_runs": 2, "amount_charged": { "credits": 31250.4, "usd": 312.504 }, "list_amount": { "credits": 65105, "usd": 651.05 } },
  "data": [
    { "day": "2026-10-30", "runs": 26, "charged_runs": 24, "held_runs": 2, "amount_charged": { "credits": 1248, "usd": 12.48 }, "list_amount": { "credits": 2600, "usd": 26 } }
  ]
}
```

| Query | Meaning |
|---|---|
| `from`, `to` | Days, both included. Default: the last 30 days up to today. At most 90 days. |
| `timezone` | The days are cut in this zone. Default `UTC`. |
| `group_by` | `day` (default) or `day_style`: one line per day and style. |
| `path` | Only one door, as in the list. |

- A run counts on the day of its `created_at`. Days without runs are left out.
- `amount_charged` = the sum of the `amount_charged` of the runs `GET /v2/runs` lists for that day with the same `timezone`. `list_amount` = the same runs at list price, before a partner discount.
- `held_runs` above 0 means some runs of that day have not ended: the day's amount can still grow. Close a day once its `held_runs` is 0.
