# Usage API

> Read your requests, tokens and cost in pounds over HTTP with a platform:read key: endpoints, filters, paging, CSV export, freshness and errors.

The usage API is read-only. It returns the requests, tokens and cost that the [Usage](https://platform.projecthollow.com/usage/) and [Cost](https://platform.projecthollow.com/cost/) pages show, so a script, a dashboard or a billing job can read the same figures. It never changes a project, a key or a limit.

## Address and key

The usage API is served by the Hollow API gateway at `https://api.projecthollow.com`. That is a different address from the model API (`https://models.projecthollow.com`): send usage requests to the gateway and model requests to the model API.

Send the key as a Bearer token in the `Authorization` header, as for the model API. The gateway reads no other header.

**The header**

```http
Authorization: Bearer hlw_sk_...
```

The key needs the `platform:read` scope (Read usage and cost). On the [Keys](https://platform.projecthollow.com/keys/) page, choose New API key, then under More access levels choose Read usage and cost. A key with only this scope cannot call a model, so keep it apart from the key your application uses for models. A model key does not carry the scope and cannot read usage. The same gateway also runs workflows, with a separate `platform:run` scope: see [Run workflows over the API](https://platform.projecthollow.com/docs/workflow-api.md). Spend by workflow agent steps appears in these figures under the key that started the run.

## Which project a key can read

- A key belongs to the project it was made in, which is the default project when none was named, and it can read that project only. Its projects list holds that project alone, and usage, cost and CSV reads are limited to it whether or not you pass `projectId`.
- Passing the `projectId` of any other project is refused with HTTP 403 and the code `FORBIDDEN`. Nothing is returned.
- A key that belongs to no project, such as one from before projects existed or one made by signing in with the Hollow CLI, reads every project on the account, and `projectId` narrows the read to one of them. A `projectId` that is not on the account is a 404.

**A refused project**

```json
{
  "error": {
    "code": "FORBIDDEN",
    "status": 403,
    "message": "This API key is bound to a different project."
  }
}
```

## Endpoints

**The usage API endpoints**

| Method and path | Returns |
| --- | --- |
| `GET /v1/platform/projects` | The projects the key can read: id, name, status and limits. |
| `GET /v1/platform/usage` | Rows of requests and tokens, with totals and freshness. |
| `GET /v1/platform/costs` | The same rows with cost in pounds, the currency and the pricing version. |
| `GET /v1/platform/usage.csv` | Every row of a usage read as CSV. |

Usage, costs and the CSV take the query parameters below. The projects endpoint takes none.

## Query parameters

**Query parameters for usage, costs and usage.csv**

| Parameter | Required | Default | What it does |
| --- | --- | --- | --- |
| `from` | Yes | None | The start of the range, a UTC time ending in Z, such as `2026-10-01T00:00:00Z`. |
| `to` | Yes | None | The end of the range, in the same form. It must be after `from` and not in the future, and the range can span at most 400 days. |
| `projectId` | No | All readable projects | Only this project. A key bound to a project always reads that project. |
| `apiKeyId` | No | All keys | Only this key. Use the `apiKeyId` of a row. |
| `model` | No | All models | Only this model id. |
| `groupBy` | No | `day` | How rows are grouped: `day`, `model`, `key`, `project`, `day_model`, `day_key` or `cell` (day, project, key and model together). |
| `bucket` | No | `day` | `day` or `hour`. `hour` reads hourly totals for the last 7 days only; see Hourly usage below. |
| `pageSize` | No | 50 | Rows per page, from 1 to 200. |
| `pageToken` | No | First page | The `nextPageToken` of the previous response. |

Usage is totalled per UTC day, so `from` and `to` select whole days: a range that starts or ends part-way through a day includes all of that day. Rows are never finer than a day unless you ask for `bucket=hour`, and daily totals are kept for 400 days.

## Hourly usage

Add `bucket=hour` to read per UTC hour. Hourly totals are recorded from the day hourly recording was switched on and are not backfilled, so an hour before that is absent, which is not the same as no usage. A read covers at most the last 7 days (`from` no earlier than that), and `from` and `to` select whole hours. Hourly totals are kept for 35 days.

- With `bucket=hour` the groupings that name a day (`day`, `day_model`, `day_key` and `cell`) give one row per hour, and `bucketStart` is the start of that hour. The other groupings add up the whole range.
- `coverageStart` is the start of the first hour recorded for the account. A range that starts earlier covers time that cannot be shown.
- Hourly reads are bounded: a read that matches more than 5,000 hourly records is refused with HTTP 400. Name a `projectId` or choose a shorter range.
- Daily and hourly figures describe the same requests, but a day before hourly recording began has no hours, so the days can total more than the hours shown.

## Read your cost

**Cost by model, curl**

```bash
curl 'https://api.projecthollow.com/v1/platform/costs?from=2026-10-01T00:00:00Z&to=2026-10-18T00:00:00Z&groupBy=model' \
  -H "Authorization: Bearer $HOLLOW_API_KEY"
```

**Cost by model, Python and TypeScript**

**Python**

```python
import os

import requests

response = requests.get(
    "https://api.projecthollow.com/v1/platform/costs",
    headers={"Authorization": f"Bearer {os.environ['HOLLOW_API_KEY']}"},
    params={"from": "2026-10-01T00:00:00Z", "to": "2026-10-18T00:00:00Z", "groupBy": "model"},
    timeout=30,
)
response.raise_for_status()
print(response.json()["totals"]["costGbp"])
```

**TypeScript**

```typescript
const params = new URLSearchParams({ from: "2026-10-01T00:00:00Z", to: "2026-10-18T00:00:00Z", groupBy: "model" });
const response = await fetch(`https://api.projecthollow.com/v1/platform/costs?${params}`, {
  headers: { Authorization: `Bearer ${process.env.HOLLOW_API_KEY}` },
});
if (!response.ok) throw new Error(`Usage request failed: ${response.status}`);
const { totals } = await response.json();
console.log(totals.costGbp);
```

## The response

A usage read returns `rows`, `totals` and `freshness`, and a cost read adds `currency` and `pricingVersion`. Each response can also carry `coverageStart` and `nextPageToken`.

**Fields of a row**

| Field | Meaning |
| --- | --- |
| `key` | The group the row stands for: a day, a model id, a key id or a project id, as `groupBy` says. |
| `projectId`, `apiKeyId`, `model` | The dimensions the row is grouped by. A dimension the grouping does not use is `null`. `apiKeyId` is also `null` for usage with no key. |
| `bucketStart` | The start of the UTC day (or of the UTC hour, with `bucket=hour`), for a grouping by day. Otherwise `null`. |
| `inputTokens`, `outputTokens` | Tokens sent and received. `inputTokens` is the input that was not read from the cache. |
| `cacheReadTokens`, `cacheWriteTokens` | Input read from, and written to, the provider cache. They are counted apart from `inputTokens`. |
| `calls` | The number of requests. |
| `costGbp` | The charge in pounds sterling, to nine decimal places. It is a number, not a formatted string. |
| `status` | `settled` for a final figure. `partial` when some requests in the row had no price, so the cost is not complete. `unknown` when some could not be measured, so the figure must not be treated as final. |

- `totals` adds up every matching row, not only the page you received, so a total never depends on `pageSize`.
- `currency` is always `GBP`. `pricingVersion` names the price list the cost was calculated with (`2026-10-30` in the example).
- Cost is what the request charged to your prepaid credit. A request with no price adds nothing to `costGbp` and turns its row `partial`, so a missing price is never shown as spend.
- Rows grouped by day are in date order. Every other grouping lists the most expensive first.
- Usage that happened before attribution began is not in the figures. `coverageStart` is the first day the account has attributed usage, and a range that starts earlier covers history that cannot be shown.

**A cost response**

```json
{
  "rows": [
    {
      "key": "example-model",
      "projectId": null,
      "apiKeyId": null,
      "model": "example-model",
      "bucketStart": null,
      "inputTokens": 1820400,
      "outputTokens": 412900,
      "cacheReadTokens": 96000,
      "cacheWriteTokens": 0,
      "calls": 1284,
      "costGbp": 3.482117,
      "status": "settled"
    }
  ],
  "totals": {
    "inputTokens": 1820400,
    "outputTokens": 412900,
    "cacheReadTokens": 96000,
    "cacheWriteTokens": 0,
    "calls": 1284,
    "costGbp": 3.482117
  },
  "currency": "GBP",
  "pricingVersion": "2026-10-30",
  "freshness": {
    "asOf": "2026-10-18T09:30:12.481Z",
    "freshThrough": "2026-10-18T09:29:47.903Z",
    "status": "fresh"
  },
  "coverageStart": "2026-09-14T00:00:00.000Z"
}
```

## Paging

A response holds up to `pageSize` rows (50 unless you say otherwise, at most 200). While more rows remain it carries `nextPageToken`. Send that value back as `pageToken`, with every other parameter unchanged, until a response has none. Treat the token as opaque. A token the API did not give you is refused with HTTP 400.

**Page through a read**

```bash
curl 'https://api.projecthollow.com/v1/platform/usage?from=2026-10-01T00:00:00Z&to=2026-10-18T00:00:00Z&groupBy=cell&pageSize=100' \
  -H "Authorization: Bearer $HOLLOW_API_KEY"

# The response ends with "nextPageToken" while more rows remain. Send it back unchanged:
curl 'https://api.projecthollow.com/v1/platform/usage?from=2026-10-01T00:00:00Z&to=2026-10-18T00:00:00Z&groupBy=cell&pageSize=100&pageToken=TOKEN_FROM_THE_LAST_RESPONSE' \
  -H "Authorization: Bearer $HOLLOW_API_KEY"
```

Usage that arrives while you page can move rows between pages, so for an exact total read `totals` from the first page.

## Export as CSV

`GET /v1/platform/usage.csv` takes the same parameters and returns the whole result in one response as `text/csv`, with CRLF line endings. It ignores `pageToken` and returns every row; `pageSize` is still checked, so a value outside its range is refused. The header is:

**The CSV header**

```text
bucketStart,projectId,apiKeyId,model,inputTokens,outputTokens,cacheReadTokens,cacheWriteTokens,calls,costGbp,status
```

A value that starts with `=`, `+`, `-` or `@` gets a leading apostrophe, so a spreadsheet reads it as text and never as a formula. A read that matches more than 10,000 daily records is refused with HTTP 400: choose a shorter range.

## How fresh the figures are

- A request is recorded when its cost is settled, which happens as the model finishes and its usage is known. It is written in the same step as the cost, so a request is not counted without its cost or the other way round. Refused requests, and requests that produce no usage, are not counted. Playground requests are.
- A settlement that cannot be written straight away is retried in the background. A retry sweep runs every 10 minutes, and a settlement that keeps failing waits longer between tries, up to six hours. While any is waiting, every usage and cost read of the account says `processing`, because the figures may be short. After eight failed tries it is set aside for Hollow to reconcile by hand, and reads stop saying `processing` for it.
- Every response states how current it is. `freshness.status` is `fresh`, `processing` or `unavailable`. `unavailable` means the account has no attributed usage at all yet. It is not zero, and `rows` is empty.
- `freshness.asOf` is the time of the read. `freshness.freshThrough` is the time of the newest settlement among the days you asked for, or the time of the read when there are none.

## Errors

A failure is a JSON body with an `error` object holding `code`, `status` and `message`. The same codes apply on every endpoint.

**Errors from the usage API**

| Situation | HTTP status | Code |
| --- | --- | --- |
| No `Authorization: Bearer` header, a malformed key, or a key that does not exist | 401 | `MISSING_AUTH_HEADER`, `INVALID_KEY_FORMAT` or `INVALID_KEY` |
| The key is disabled, deleted, suspended or expired | 401 | `KEY_REVOKED`, `ANOMALY_SUSPENDED` or `KEY_EXPIRED` |
| The key lacks the `platform:read` scope | 403 | `INSUFFICIENT_SCOPE` |
| The account is not approved for Hollow | 403 | `ACCOUNT_NOT_APPROVED` |
| A `projectId` other than the one the key is bound to | 403 | `FORBIDDEN` |
| A missing or invalid parameter, `to` before `from`, a future `to`, a range over 400 days, `bucket=hour` over a range that starts more than 7 days ago, a bad `pageToken`, or too many records in the range | 400 | `INVALID_REQUEST` |
| A `projectId` that is not on the account | 404 | `NOT_FOUND` |
| More than 600 requests a minute from one key | 429 | `RATE_LIMITED` |
| The service is busy | 503 | `UNAVAILABLE` |

The model API reports its own failures differently. See [Errors and status codes](https://platform.projecthollow.com/docs/errors.md) for those, and [Authentication](https://platform.projecthollow.com/docs/authentication.md) for keys, scopes and expiry.

> **Note: Where else to find these figures**
>
> The same numbers are in the app. The [Usage](https://platform.projecthollow.com/usage/) page can export what it shows as CSV, and the [Cost](https://platform.projecthollow.com/cost/) page shows what it cost.
