> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tensorcost.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pull customer usage

> Read each customer's daily AI cost and tokens from your own billing job, so you can bill cost-plus.

If you bill your customers for what their AI usage costs, your billing system needs a number for each customer and day. TensorCost has one endpoint for that. Your job calls it with a key, reads the rows, and prices them however you like. TensorCost never creates invoices, and it holds no credential to your billing system. Your job holds ours and comes to us.

> [!NOTE]
>
> Available on Scale and Enterprise, including BYOC. An admin or finance member makes the key. Below Scale, existing usage keys can still be listed and revoked, but the endpoint refuses them.

## Make a usage key

Open **Connect › API keys** and choose **New usage key**. Give it a name. The key is shown once, so put it in your job's secret store straight away.

A usage key reads one route and nothing else. Any other path answers 403 with `This is a usage key: it can only read GET /v1/api/cost/customer-usage.` The endpoint, in turn, refuses every other kind of key and any console session.

Usage keys belong to the workspace, not to the person who made them. If that person leaves, the key keeps working and the admins get an alert saying it's worth rotating. Nothing revokes it for you. To rotate, make a new key, switch your job over, then revoke the old one from the same page.

The calls you want priced need the `customer` tag, because usage is read per customer. See [Attribution](https://docs.tensorcost.com/developers/attribution.md).

## The request

```http theme={null}
GET https://api.tensorcost.com/v1/api/cost/customer-usage?since=2026-11-01&until=2026-11-15
Authorization: Bearer <usage key>
```

| Parameter | Required | Meaning |
| - | - | - |
| `since` | Yes | First day, `YYYY-MM-DD`, UTC. |
| `until` | Yes | Last day, `YYYY-MM-DD`, UTC, inclusive. Not later than today. |
| `page_size` | No | Customers per page, 1 to 1,000. Default 100. |
| `cursor` | No | The `next_cursor` from the previous page. |

A range spans at most 92 days, counting both ends. For a longer stretch, make several calls.

```bash curl theme={null}
curl "https://api.tensorcost.com/v1/api/cost/customer-usage?since=2026-11-01&until=2026-11-15" \
  -H "Authorization: Bearer $TENSORCOST_USAGE_KEY"
```

```js Node.js theme={null}
const res = await fetch(
  "https://api.tensorcost.com/v1/api/cost/customer-usage?since=2026-11-01&until=2026-11-15",
  { headers: { Authorization: `Bearer ${process.env.TENSORCOST_USAGE_KEY}` } },
);
const page = await res.json();
```

## The response

```json theme={null}
{
  "since": "2026-11-01",
  "until": "2026-11-15",
  "settled_through": "2026-11-12",
  "rows": [
    {
      "customer": "acme",
      "day": "2026-11-11",
      "cost_cents": 18342,
      "input_tokens": 9120000,
      "output_tokens": 1404000,
      "calls": 5210,
      "settled": true
    },
    {
      "customer": "acme",
      "day": "2026-11-14",
      "cost_cents": 6120,
      "input_tokens": 3010000,
      "output_tokens": 480000,
      "calls": 1733,
      "settled": false
    }
  ],
  "next_cursor": "Z2xvYmV4"
}
```

Each row is one customer on one UTC day. `cost_cents` is the same counted figure **Spend › Customers** shows, matched to the provider's bill where the bill is known. See [How TensorCost counts AI spend](https://docs.tensorcost.com/concepts.md).

## Settled days

A day is **settled** once it is three days old. `settled_through` is the latest settled day: today (UTC) minus three days. A row's `settled` is `true` when its day is on or before that date.

Settled figures are final. Unsettled rows are there so you can watch the month build, but the figure can still move while calls are counted and bills arrive. If you invoice from this endpoint, price only the rows where `settled` is `true` and pick up the rest on a later run.

## Paging

`page_size` counts customers, not rows. Each page holds every row in your range for that many customers, in customer-id order. When `next_cursor` is `null`, you have everything. Otherwise pass it back as `cursor` with the same `since`, `until` and `page_size`.

The cursor is only good for values this endpoint gave you. An invented one is a 400.

The first page on a large workspace can take several seconds, because it matches the range against provider bills. The endpoint gives up at 55 seconds.

## Errors

| Status | Meaning |
| - | - |
| 400 | `since` or `until` isn't a date, `since` is after `until`, `until` is after today (UTC), the range is over 92 days, `page_size` isn't a whole number from 1 to 1,000, or the `cursor` isn't one we gave. The message says which. |
| 401 | No key, or a key that isn't valid. |
| 403 | The key isn't a usage key, or the workspace isn't on Scale or Enterprise. |
| 502 | The usage couldn't be read just now. Try again in a moment. |

## A job that bills from it

Run it daily, ask for the days since you last finished, and keep only settled rows.

```js theme={null}
const base = "https://api.tensorcost.com/v1/api/cost/customer-usage";
const headers = { Authorization: `Bearer ${process.env.TENSORCOST_USAGE_KEY}` };

async function settledUsage(since, until) {
  const out = [];
  let cursor;
  do {
    const q = new URLSearchParams({ since, until, page_size: "500" });
    if (cursor) q.set("cursor", cursor);
    const res = await fetch(`${base}?${q}`, { headers });
    if (!res.ok) throw new Error(`usage pull ${res.status}: ${await res.text()}`);
    const page = await res.json();
    out.push(...page.rows.filter((r) => r.settled));
    cursor = page.next_cursor;
  } while (cursor);
  return out;
}
```

## Moving from the Stripe export

TensorCost used to send each customer's usage to Stripe as Meter events. That is gone, and so is the Stripe connection it used. The pull replaces it: your job reads the rows above and sends them to Stripe, or to any other billing system, itself.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.