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

# Count Balance Ledger

> Counts the entries of each type that balances.list_ledger lists for one customer's balance of a feature over a range, for showing beside a filter by type.

Counts the entries of each type that [List Balance Ledger](https://docs.useautumn.com/api-reference/balances/listBalanceLedger.md) lists for one customer's balance of a feature, over the same `custom_range` or `recorded_range`. Pass a type to `types` on List Balance Ledger to list only the entries of that type.

`counts.usage` counts usage events, not entries: each track once, and a lock once, when it was reserved. The other counts are how many entries List Balance Ledger lists for that type when `types` leaves out `usage`: `adjustments` counts recorded edits only (updates that don't add to the balance, deletes and recalculations), not an adjustment Autumn works out from a balance that moved with no record. The counts don't depend on `types`, so fetch them once per range.

> [!NOTE]
>
> Balance history is rolling out and isn't available for every customer yet; `coverage` says whether it is for this one. Tracks are kept for 90 days, so `counts.usage` counts only the tracks in that time.

`complete` is `false` when the count couldn't cover the whole range; each count is then at least its value.

### Body Parameters

The customer whose balance history to count.

The feature whose balance to count, as in balances.list\_ledger.

Count this entity's balance of the feature, as in balances.list\_ledger.

Only count entries that happened in this range.

**properties**

Only entries that happened at or after this time (epoch milliseconds).

Only entries that happened at or before this time (epoch milliseconds).

Only count entries Autumn recorded in this range.

**properties**

Only entries Autumn recorded at or after this time (epoch milliseconds).

Only entries Autumn recorded at or before this time (epoch milliseconds).

### Response

The entity whose own balance is counted, or null for the customer's.

How much of this customer's balance history Autumn holds. Balance history is rolling out and isn't available for every customer yet; coverage says whether it is for this one.

**properties**

Whether Autumn is recording every change to this customer's balance now. While false, some or all changes may be missing (tracks may still be recorded), so a history that is empty or missing changes is expected.

The earliest time history covers for this customer (epoch milliseconds), or null when nothing has been recorded yet. There are no entries from before it.

How many entries of each type the range holds, as balances.list\_ledger's types filter lists them.

**properties**

How many usage events the range holds: each track, with a lock counted once, when it was reserved. It counts events, not the track groups balances.list\_ledger folds them into.

How many top\_ups entries balances.list\_ledger lists for the range.

How many resets entries balances.list\_ledger lists for the range.

How many plan\_changes entries balances.list\_ledger lists for the range.

How many recorded edits the range holds: updates that don't add to the balance, deletes and recalculations. An adjustment Autumn works out from a balance that moved with no record isn't counted.

False when the count couldn't cover the whole range; each count is then at least its value.

```json 200 theme={null}
{
  "entity_id": null,
  "coverage": {
    "recording": true,
    "since": 1759300000000
  },
  "counts": {
    "usage": 9412,
    "top_ups": 2,
    "resets": 1,
    "plan_changes": 0,
    "adjustments": 1
  },
  "complete": true
}
```


## OpenAPI

````yaml openapi POST /v1/balances.count_ledger
openapi: 3.1.0
info:
  title: Autumn API
  version: 2.6.0
servers:
  - url: https://api.useautumn.com
    description: Production server
security:
  - secretKey: []
paths:
  /v1/balances.count_ledger:
    post:
      tags:
        - balances
      description: >-
        Counts the entries of each type that balances.list_ledger lists for one
        customer's balance of a feature over a range, for showing beside a
        filter by type.
      operationId: countBalanceLedger
      parameters:
        - name: x-api-version
          in: header
          required: true
          schema:
            type: string
            default: 2.6.0
          x-speakeasy-globals-hidden: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                customer_id:
                  type: string
                  minLength: 1
                  description: The customer whose balance history to count.
                feature_id:
                  type: string
                  minLength: 1
                  description: >-
                    The feature whose balance to count, as in
                    balances.list_ledger.
                entity_id:
                  type: string
                  minLength: 1
                  description: >-
                    Count this entity's balance of the feature, as in
                    balances.list_ledger.
                custom_range:
                  type: object
                  properties:
                    start:
                      type: number
                      description: >-
                        Only entries that happened at or after this time (epoch
                        milliseconds).
                    end:
                      type: number
                      description: >-
                        Only entries that happened at or before this time (epoch
                        milliseconds).
                  description: Only count entries that happened in this range.
                recorded_range:
                  type: object
                  properties:
                    start:
                      type: number
                      description: >-
                        Only entries Autumn recorded at or after this time
                        (epoch milliseconds).
                    end:
                      type: number
                      description: >-
                        Only entries Autumn recorded at or before this time
                        (epoch milliseconds).
                  description: Only count entries Autumn recorded in this range.
              required:
                - customer_id
                - feature_id
              title: CountBalanceLedgerParams
              examples:
                - customer_id: cus_123
                  feature_id: messages
                  custom_range:
                    start: 1759276800000
                    end: 1761868800000
            example:
              customer_id: cus_123
              feature_id: messages
              custom_range:
                start: 1759276800000
                end: 1761868800000
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  entity_id:
                    anyOf:
                      - type: string
                      - type: 'null'
                    description: >-
                      The entity whose own balance is counted, or null for the
                      customer's.
                  coverage:
                    type: object
                    properties:
                      recording:
                        type: boolean
                        description: >-
                          Whether Autumn is recording every change to this
                          customer's balance now. While false, some or all
                          changes may be missing (tracks may still be recorded),
                          so a history that is empty or missing changes is
                          expected.
                      since:
                        anyOf:
                          - type: number
                          - type: 'null'
                        description: >-
                          The earliest time history covers for this customer
                          (epoch milliseconds), or null when nothing has been
                          recorded yet. There are no entries from before it.
                    required:
                      - recording
                      - since
                    description: >-
                      How much of this customer's balance history Autumn holds.
                      Balance history is rolling out and isn't available for
                      every customer yet; coverage says whether it is for this
                      one.
                  counts:
                    type: object
                    properties:
                      usage:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                        description: >-
                          How many usage events the range holds: each track,
                          with a lock counted once, when it was reserved. It
                          counts events, not the track groups
                          balances.list_ledger folds them into.
                      top_ups:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                        description: >-
                          How many top_ups entries balances.list_ledger lists
                          for the range.
                      resets:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                        description: >-
                          How many resets entries balances.list_ledger lists for
                          the range.
                      plan_changes:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                        description: >-
                          How many plan_changes entries balances.list_ledger
                          lists for the range.
                      adjustments:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                        description: >-
                          How many recorded edits the range holds: updates that
                          don't add to the balance, deletes and recalculations.
                          An adjustment Autumn works out from a balance that
                          moved with no record isn't counted.
                    required:
                      - usage
                      - top_ups
                      - resets
                      - plan_changes
                      - adjustments
                    description: >-
                      How many entries of each type the range holds, as
                      balances.list_ledger's types filter lists them.
                  complete:
                    type: boolean
                    description: >-
                      False when the count couldn't cover the whole range; each
                      count is then at least its value.
                required:
                  - entity_id
                  - coverage
                  - counts
                  - complete
                examples:
                  - entity_id: null
                    coverage:
                      recording: true
                      since: 1759300000000
                    counts:
                      usage: 9412
                      top_ups: 2
                      resets: 1
                      plan_changes: 0
                      adjustments: 1
                    complete: true
              example:
                entity_id: null
                coverage:
                  recording: true
                  since: 1759300000000
                counts:
                  usage: 9412
                  top_ups: 2
                  resets: 1
                  plan_changes: 0
                  adjustments: 1
                complete: true
      x-codeSamples:
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { Autumn } from 'autumn-js'

            const autumn = new Autumn()

            const result = await autumn.balances.countLedger({
              customerId: "cus_123",
              featureId: "messages",
              customRange: {
                start: 1759276800000,
                end: 1761868800000,
              },
            });
        - lang: python
          label: Python (SDK)
          source: |-
            from autumn_sdk import Autumn

            autumn = Autumn(secret_key="am_sk_test...")

            res = autumn.balances.count_ledger(
                customer_id="cus_123",
                feature_id="messages",
                custom_range={
                    "start": 1759276800000,
                    "end": 1761868800000,
                },
            )
components:
  securitySchemes:
    secretKey:
      type: http
      scheme: bearer
      bearerFormat: JWT

````

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