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

# AI cost per customer

> See what every customer or workspace costs you in model usage, per billing period or per month, and across your whole business.

> **Every plan:** AI answers included. **Your dashboard:** what each workspace's AI cost you this month, and across all of them.

Ledger shows what each customer costs you in AI, so you know your margin on every account and every plan. Track each model call's cost to Ledger as it happens, in a fixed unit of **\$0.0001**, and Ledger keeps the total per customer. Make each workspace its own Ledger customer to see the cost per workspace. Pick the feature type by whether the customer pays for that cost:

| | Metered feature, unlimited | Credits feature |
| - | - | - |
| Use it when | AI is included in a flat price, and the cost is yours | Customers pay for usage at cost from a [dollar balance](https://docs.integrateledger.com/pricing/dollar-balance.md) |
| Each call | `quantity`: the cost in \$0.0001 units | `quantity`: the cost in credits of \$0.0001, at `creditCost: 1` |
| Limits or bills the customer | Never | Yes: it spends their balance |
| Read the total | `balance.used` on the customer, this billing period | [`GET /v1/usage/totals`](https://docs.integrateledger.com/api-reference/usage/totals): `chargedCredits` per month, per customer or for the environment |

## With a metered feature

An `unlimited: true` item allows every use and records its `quantity`, so the feature tracks your cost without limiting or billing the customer.

```ts ledger.config.ts theme={"system"}
import { defineCatalog, feature, plan } from "integrateledger-cli";

export default defineCatalog({
	features: [
		feature({ id: "ai_answer", name: "AI answer", type: "boolean" }),
		feature({ id: "ai_cost", name: "AI cost, $0.0001 units", type: "metered" }),
	],
	plans: [
		plan({
			id: "team",
			name: "Team",
			monthlyCredits: 0,
			priceCents: 4900,
			items: [
				{ featureId: "ai_answer" },
				{ featureId: "ai_cost", unlimited: true },
			],
		}),
	],
	creditPacks: [],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [
    { "id": "ai_answer", "name": "AI answer", "type": "boolean" },
    { "id": "ai_cost", "name": "AI cost, $0.0001 units", "type": "metered" }
  ],
  "plans": [
    { "id": "team", "name": "Team", "monthlyCredits": 0, "priceCents": 4900,
      "items": [{ "featureId": "ai_answer" }, { "featureId": "ai_cost", "unlimited": true }] }
  ],
  "addOns": []
}
```

After each call, track its cost. Use the call's own ID as `request_id`, so a retry records it once.

```typescript TypeScript theme={"system"}
const UNITS_PER_DOLLAR = 10_000;
const result = await runModel(prompt); // result.costDollars: 0.0123

await billing.trackUsage({
	customerId: workspace.id,
	featureId: "ai_cost",
	requestId: result.id,
	quantity: Math.max(1, Math.ceil(result.costDollars * UNITS_PER_DOLLAR)), // 123
});
```

```python Python theme={"system"}
import math

UNITS_PER_DOLLAR = 10_000
result = run_model(prompt)  # result.cost_dollars: 0.0123

billing.track_usage(
    customer_id=workspace.id,
    feature_id="ai_cost",
    request_id=result.id,
    quantity=max(1, math.ceil(result.cost_dollars * UNITS_PER_DOLLAR)),  # 123
)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/track \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "ws_42", "featureId": "ai_cost", "request_id": "gen_77120", "quantity": 123}'
```

Read the period's total from the customer. `balance.used` adds up every `quantity` tracked since the billing period began:

```typescript TypeScript theme={"system"}
const customer = await billing.getCustomer({ customerId: workspace.id });
const aiCost = customer.features.find((feature) => feature.featureId === "ai_cost");
const costDollars = (aiCost?.balance?.used ?? 0) / UNITS_PER_DOLLAR; // 184.27
```

```python Python theme={"system"}
customer = billing.get_customer(customer_id=workspace.id)
ai_cost = next(f for f in customer["features"] if f["featureId"] == "ai_cost")
cost_dollars = ai_cost["balance"]["used"] / UNITS_PER_DOLLAR  # 184.27
```

```bash cURL theme={"system"}
curl "https://api.integrateledger.com/v1/customers?customerId=ws_42" \
  -H "Authorization: Bearer $LEDGER_API_KEY"
```

```json Response (features entry) theme={"system"}
{
  "featureId": "ai_cost",
  "type": "metered",
  "unlimited": true,
  "balance": { "included": null, "used": 1842700, "remaining": null, "overageAllowed": false, "resetsAt": "2026-12-07T07:40:58.000Z" }
}
```

$184.27 against a $49 plan. `resetsAt` is when the period ends and `used` starts again from 0, so read it before then to keep each period's figure.

## With a credits feature

When customers pay for usage at cost, the cost is already in Ledger: each call's `quantity` is what it cost you, in credits ([Prepaid dollar balance](https://docs.integrateledger.com/pricing/dollar-balance.md#the-calls)). Read a month's total per customer:

```typescript TypeScript theme={"system"}
const totals = await billing.getUsageTotals({ month: "2026-11", customerId: "ws_42" });
const costDollars = totals.chargedCredits / 10_000; // 61.04
```

```python Python theme={"system"}
totals = billing.get_usage_totals(month="2026-11", customer_id="ws_42")
cost_dollars = totals["chargedCredits"] / 10_000  # 61.04
```

```bash cURL theme={"system"}
curl -G https://api.integrateledger.com/v1/usage/totals \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  --data-urlencode "month=2026-11" \
  --data-urlencode "customerId=ws_42"
```

```json Response theme={"system"}
{
  "month": "2026-11",
  "customerId": "ws_42",
  "events": 4120,
  "charged": 4102,
  "blocked": 18,
  "failed": 0,
  "chargedCredits": 610400,
  "reasons": { "insufficient_credits": 18 }
}
```

Leave out `customerId` for the month across every customer. [`GET /v1/usage`](https://docs.integrateledger.com/api-reference/usage/list) lists each call with its `chargedCredits`, for a breakdown by request.

## Rules

* **`quantity` is a whole number,** at least 1 on a metered feature. Round each call up to the next $0.0001; that adds at most $0.0001 per call.
* **One track is at most 2,147,483,647 units,** \$214,748.36 at this scale.
* **Usage totals' `chargedCredits` sums credits features.** A metered feature's units are in its `balance`; totals count its calls in `events` and `charged`.
* **Totals are by UTC month** of the customer's time; `balance.used` is by billing period.
* **Each workspace is a customer** for its own totals. [Entities](https://docs.integrateledger.com/customers/entities.md) split one customer's credits within its totals.

## Related

* [Prepaid dollar balance](https://docs.integrateledger.com/pricing/dollar-balance.md): bill the same cost to the customer.
* [Usage events](https://docs.integrateledger.com/concepts/usage-events.md): what each track records.
* [Metered allowances](https://docs.integrateledger.com/pricing/metered.md#unlimited): unlimited items.


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