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

# Usage

> Record usage without gating it, and read usage records

## Report usage

`reportUsage()` records usage without checking a limit. Use it when access was already decided, for example to sync counts from a job or to meter work after the fact. To gate an action on a quota, use [`consume()`](https://docs.kerne.io/sdks/server/entitlements#consume-a-quota).

```typescript theme={"system"}
await kerne.reportUsage('storage_megabytes', {
  customer: userId,
  delta: 2560,
  idempotencyKey: syncJobId,
});
```

**customer** `string` *required*

The customer. It must already exist: `reportUsage()` never creates one.

**delta** `number` (default: 1)

A whole number. Fractions are rejected.

**operation** `'INCREMENT' | 'SET'` (default: INCREMENT)

`SET` sets the counter to `delta` instead of adding to it.

**idempotencyKey** `string`

A retry with the same key is recorded once.

**dimension** `string`

Which machine, project or seat to record against. Optional here: without it, usage goes to the
customer's shared counter. See [Dimensions](https://docs.kerne.io/sdks/server/entitlements.md#dimensions).

**metadata** `object`

Stored with the usage event.

## Report in batches

Up to 100 events per call:

```typescript theme={"system"}
const results = await kerne.reportUsageBatch(
  machines.map((machine) => ({
    featureKey: 'machine_minutes',
    customer: machine.ownerId,
    dimension: machine.id,
    delta: machine.minutes,
  })),
);
// [{ index, status: 'ok' | 'error', usage?, error? }, ...]
```

Each event is recorded on its own: a failing event doesn't cancel the others, so check `status` on every result.

## Read usage

```typescript theme={"system"}
const records = await kerne.usage({ customer: userId });
const apiCalls = await kerne.usage({ customer: userId, featureKey: 'api_calls' });
```

One record per feature for the current period: `{ feature_key, value, period_start, period_end, status, ... }`. This is the raw counter. For `limit` and `remaining`, with overrides and rollover applied, use [`check()`](https://docs.kerne.io/sdks/server/entitlements#check-access).

To refund or reset usage, see [usage corrections](https://docs.kerne.io/sdks/server/admin.md#usage-corrections).


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