# Usage

> Usage records: one per sandbox per minute plus a final one, signed by the node; what is billed and what was measured, and how to read them.

Source: https://docs.compute.dev.ddcdragon.com/concepts/usage/

The node that runs a sandbox writes one usage record for it every minute, and a final one when it ends, and signs
each with the node's key. The records are what your bucket is billed for, and they also carry what the node measured,
so you can size your sandboxes.

## Records

A record closes at every wall-clock minute while the sandbox runs, and a final record closes when the sandbox ends,
however it ends. So a sandbox that runs from 10:00:40 to 10:02:15 has three records: 10:00:40 to 10:01:00, 10:01:00
to 10:02:00, and a final one from 10:02:00 to 10:02:15. The node samples the sandbox every second.

Each record carries:

| Field | Meaning |
| --- | --- |
| `period_start`, `period_end`, `wall_s` | The stretch of time it covers, and its length in seconds. |
| `final`, `exit_reason` | Whether it is the sandbox's last record, and why the sandbox ended. |
| `reserved_cpu`, `reserved_memory_mib` | The sandbox's reservation. |
| `reserved_cpu_s`, `reserved_ram_gib_s` | The reservation over `wall_s`: vCPU × seconds and GiB × seconds. |
| `billed_cpu_s`, `billed_ram_gib_s` | What is billed: the reservation, or the measured amount where that is more. |
| `billing_basis` | How the billed amounts were reached: `reserved`, or `request_or_usage` on a node that runs requests and limits (the larger of reserved and measured, per minute; see [Resources and billing](https://docs.compute.dev.ddcdragon.com/concepts/resources-and-billing/)). |
| `cpu_s`, `ram_gib_s` | Measured: CPU-seconds used, and memory in use integrated over time, in GiB-seconds. |
| `memory_peak_mib`, `net_egress_bytes`, `net_ingress_bytes`, `disk_peak_mib` | Measured: peak memory, network out and in, peak disk written. |
| `cpu_units`, `ram_units` | The billed amounts × 1e11, as decimal strings: the units the signed record carries. |
| `dac_status` | Whether the signed record has been delivered for billing: `pending`, `pushed` or `failed`. |

Billed and measured are different numbers on purpose. Billed is what you pay for: the CPU and memory held for you.
Measured is what the sandbox did with them. See [Resources and billing](https://docs.compute.dev.ddcdragon.com/concepts/resources-and-billing/).

## Reading usage

| Where | What it shows |
| --- | --- |
| `cere sandbox usage <id>`, `cere sandbox get <id>` | One sandbox's totals: billed next to measured. Live while it runs. |
| `cere usage [--sandbox <id>] [--since 1h]` | The records themselves, newest first, with their sums. |
| SDK: `sb.usage()`, `sb.billing()`, `cere.usage_records(sandbox_id=...)` | The same, in Python. |
| Developer Console > Sandboxes > Usage | Billed CPU-seconds and GiB-seconds over time, by sandbox. |

```sh
cere usage --sandbox sb-01m89qn5446z1k6sadagh9phx5
```

```
PERIOD END            SANDBOX                        FINAL  BASIS     RESERVED           BILLED CPU-S  MEASURED CPU-S  BILLED GIB-S  MEASURED GIB-S  MEM PEAK  NET OUT  CPU UNITS      RAM UNITS      TCA       DAC     EXIT
2026-11-25T16:12:24Z  sb-01m89qn5446z1k6sadagh9phx5  final  reserved  1.0 vCPU, 1.0 GiB  13.586        0.665           13.586        0.162           30 MiB    433 B    1358584300000  1358584300000  29927052  pushed  terminated by API

1 records: billed 13.586 CPU-s, 13.586 GiB-s (measured 0.665 CPU-s, 0.162 GiB-s)
```

## Sizing from measured

Compare what a sandbox measured with what it reserved:

- **CPU.** Measured CPU-seconds divided by wall seconds is the vCPU it used on average. The sandbox above reserved
  1 vCPU and measured 0.665 CPU-seconds in 13.6 seconds, about a twentieth of it: `--cpu 0.25` would bill a quarter
  as much for the same time.
- **Memory.** The peak (`memory_peak_mib`, 30 MiB above) is what it needed at most. Reserve the peak with some room
  (at least 128 MiB); a sandbox that needs more than it reserved ends with `oom_killed`.
- **Time.** Billing runs until the sandbox stops, so terminate it when done, and set `--idle-timeout` on one that
  waits for commands.

## Related

- [Next: Sandboxes](https://docs.compute.dev.ddcdragon.com/guides/sandboxes/)
- [Resources and billing](https://docs.compute.dev.ddcdragon.com/concepts/resources-and-billing/)
- [Guide: Resources and billing](https://docs.compute.dev.ddcdragon.com/guides/resources-and-billing/)
- [CLI reference](https://docs.compute.dev.ddcdragon.com/reference/cli/)
