# Read a credit statement

Operation / SDK: `readCreditStatement` · `read_credit_statement` · `ReadCreditStatement`

Read a consistent credit statement for a time range and snapshot.

Last updated: 2026-11-06

[Web version](https://www.longplayai.com/docs/api/read-credit-statement)

<a id="request"></a>

## Request

- **Credential**: Server Key (with `customerId`) or Customer Token, scope `credits:read`.
- **SDK**: JavaScript `createLongplayServer().readCreditStatement` · JavaScript `createLongplay().readCreditStatement` · Python `read_credit_statement` · Go `ReadCreditStatement`
- **Success**: HTTP 200

The response shows example data.

**cURL: request.sh**

```bash
curl -X POST "$LONGPLAY_API_URL/api/v1/credit-statements/read" \
  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \
  -H "X-Indiana-Protocol: 0.10" \
  -H "Content-Type: application/json" \
  -d '{
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
  "from": "2026-10-01T00:00:00Z",
  "to": "2026-11-01T00:00:00Z",
  "snapshotAt": null,
  "after": null,
  "limit": 50
}'
```

**TypeScript: readCreditStatement.ts**

```ts
import { createLongplayServer } from "@tinkerlandai/longplay-sdk/server";

const longplay = createLongplayServer({
  baseUrl: process.env.LONGPLAY_API_URL!,
  apiKey: process.env.LONGPLAY_SERVER_KEY!,
  scope: { projectId: process.env.LONGPLAY_PROJECT_ID!, environment: "sandbox" },
});

export async function readCreditStatement() {
  return longplay.readCreditStatement({
    customerId: "8b258f8b-4228-40fa-8d24-5b16428e686d",
    from: "2026-10-01T00:00:00Z",
    to: "2026-11-01T00:00:00Z",
    snapshotAt: null,
    after: null,
    limit: 50,
  });
}
```

**Request body: request.json**

```json
{
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
  "from": "2026-10-01T00:00:00Z",
  "to": "2026-11-01T00:00:00Z",
  "snapshotAt": null,
  "after": null,
  "limit": 50
}
```

**Response: response.json**

```json
{
  "requestId": "44f5fcb8-6ed8-41b8-818f-7571941c5fd5",
  "scope": {
    "projectId": "df5426d6-b335-403c-8f3e-b0f73d2e3511",
    "environment": "sandbox"
  },
  "statement": {
    "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
    "entityId": "3c287fb0-fbf3-4e56-8a3b-0cad92605411",
    "from": "2026-10-03T12:00:00.000Z",
    "to": "2026-10-03T12:00:00.000Z",
    "snapshotAt": "2026-10-03T12:00:00.000Z",
    "totals": [
      {
        "internal_credit_feature_id": "e6b730c5-64ec-4232-8fd2-a24ce9a6b5c9",
        "name": "Pro",
        "consumed": "1",
        "refunded": "1",
        "net": "-1"
      }
    ],
    "rows": [
      {
        "operationId": "a8b14e0c-6576-49a4-812c-7a1587e55255",
        "position": 0,
        "kind": "consume",
        "originalId": "f9cc89b8-f161-49f2-84d5-7e1109f316ad",
        "occurredAt": "2026-10-03T12:00:00.000Z",
        "internal_feature_id": "f317c851-0ef2-4d7a-8e3c-e8a29df676ed",
        "entitlementName": "1Example",
        "sourceId": "31b22d42-ce50-47ea-8da0-553fd0a8a869",
        "internal_credit_feature_id": "e6b730c5-64ec-4232-8fd2-a24ce9a6b5c9",
        "creditName": "1Example",
        "units": "1",
        "amount": "1",
        "pricing": [
          {
            "internal_credit_feature_id": "e6b730c5-64ec-4232-8fd2-a24ce9a6b5c9",
            "internal_metered_feature_id": "977890b8-84f9-4320-8e7b-f6b142cf2d15",
            "dimension": "1Example",
            "counterKey": "1Example",
            "cycleStart": "2026-10-03T12:00:00.000Z",
            "unitCost": "1",
            "units": "1",
            "amount": "1",
            "tier": 1
          }
        ],
        "properties": {}
      }
    ],
    "nextCursor": {
      "at": "2026-10-03T12:00:00.000Z",
      "id": "82072b10-12fb-46f6-83a9-1e51025445ed",
      "position": 0
    }
  }
}
```

<a id="parameters"></a>

## Body parameters

**application/json**

- `from` (date-time, required): Range start (ISO 8601).
- `to` (date-time, required): Range end (ISO 8601).
- `entityId` (uuid, optional): Entity ID within the current customer scope, for configured Entity and license Features.
- `snapshotAt` (date-time | null, required): Statement snapshot time; pass the first page's value when paging, `null` for the first page.
- `after` (object | null, required): Pagination cursor: pass the value from the previous page; `null` for the first page.
- `after.at` (date-time, required): Cursor field: occurrence time (ISO 8601) of the last row on the previous page. Pass the previous `nextCursor` unchanged.
- `after.id` (uuid, required): Cursor field: ID of the last row on the previous page (the entry `id` in a ledger, the `operationId` in a credit statement). Pass the previous `nextCursor` unchanged.
- `after.position` (integer, required): Position. min: 0 · max: 9007199254740991
- `limit` (integer, required): Maximum records per page, subject to the contract limit. min: 1 · max: 100
- `customerId` (uuid, optional): The Customer's UUID.

<a id="response"></a>

## Response fields

Every successful response includes `requestId` (this request's ID, for support) and `scope` (App and environment).

**HTTP 200 · application/json**

- `requestId` (uuid, required): UUID the server generated for this HTTP request; include it when reporting a problem. It is not your business requestId.
- `scope` (object, required): The App and environment of this response. Headers only verify scope; they cannot switch key scope.
- `scope.projectId` (string, required): App ID bound to the credential. minLength: 1
- `scope.environment` (enum, required): Separate data scope: sandbox or live. Values: `"sandbox"`, `"live"`.
- `statement` (object, required): Credit statement over [`from`, `to`) as of `snapshotAt`, covering the Customer's own usage or, with `entityId`, that Entity's usage. It holds totals per credit Feature and a page of usage operations that drew credits.
- `statement.customerId` (uuid, required): The Customer's UUID.
- `statement.entityId` (uuid | null, required): Entity ID within the current customer scope, for configured Entity and license Features.
- `statement.from` (date-time, required): Range start (ISO 8601).
- `statement.to` (date-time, required): Range end (ISO 8601).
- `statement.snapshotAt` (date-time, required): Statement snapshot time; pass the first page's value when paging, `null` for the first page.
- `statement.totals` (array, required): Totals per credit Feature for the whole range, not just this page. maxItems: 1000
- `statement.totals.internal_credit_feature_id` (uuid, required): credit Feature ID.
- `statement.totals.name` (string, required): Display name; not a unique identifier.
- `statement.totals.consumed` (string, required): Credits deducted in the range by consumption and confirmed reservations; decimal string. pattern: ^(0|[1-9]\d{0,12})(\.\d{1,12})?$
- `statement.totals.refunded` (string, required): Refunded portion. pattern: ^(0|[1-9]\d{0,12})(\.\d{1,12})?$
- `statement.totals.net` (string, required): `consumed` minus `refunded`; decimal string. pattern: ^-?(0|[1-9]\d{0,17})(\.\d{1,12})?$
- `statement.rows` (array, required): Data rows. maxItems: 100
- `statement.rows.operationId` (uuid, required): Business operation UUID. Subscription execution references operationId from previewAttach; balance refunds reference the original consumption.
- `statement.rows.position` (integer, required): Position. min: 0 · max: 9007199254740991
- `statement.rows.kind` (enum, required): Kind; see the allowed values. Values: `"consume"`, `"confirm"`, `"refund"`.
- `statement.rows.originalId` (uuid | null, required): original record ID.
- `statement.rows.occurredAt` (date-time, required): Timestamp (ISO 8601).
- `statement.rows.internal_feature_id` (uuid, required): Feature ID.
- `statement.rows.entitlementName` (string, required): Name of the Feature the usage was recorded against (its key when it has no name).
- `statement.rows.sourceId` (uuid, required): balance source ID.
- `statement.rows.internal_credit_feature_id` (uuid, required): credit Feature ID.
- `statement.rows.creditName` (string, required): Name of the credit Feature that was charged (its key when it has no name).
- `statement.rows.units` (string, required): Units as a decimal string. pattern: ^(0|[1-9]\d{0,17})(\.\d{1,12})?$
- `statement.rows.amount` (string, required): Credit or ledger amount, using the field’s decimal-string or integer type. pattern: ^(0|[1-9]\d{0,12})(\.\d{1,12})?$
- `statement.rows.pricing` (array, required): Pricing details. maxItems: 12
- `statement.rows.pricing.internal_credit_feature_id` (uuid | null, required): credit Feature ID.
- `statement.rows.pricing.internal_metered_feature_id` (uuid, required): metered Feature ID.
- `statement.rows.pricing.dimension` (string, required): Pricing dimension. minLength: 1 · maxLength: 64
- `statement.rows.pricing.counterKey` (string, required): Counter key. minLength: 1 · maxLength: 240
- `statement.rows.pricing.cycleStart` (date-time, required): Cycle start.
- `statement.rows.pricing.unitCost` (string, required): Unit cost. pattern: ^(0|[1-9]\d{0,11})(\.\d{1,6})?$
- `statement.rows.pricing.units` (string, required): Units as a decimal string. pattern: ^(0|[1-9]\d{0,11})(\.\d{1,6})?$
- `statement.rows.pricing.amount` (string, required): Credit or ledger amount, using the field’s decimal-string or integer type. pattern: ^(0|[1-9]\d{0,12})(\.\d{1,12})?$
- `statement.rows.pricing.tier` (integer | null, required): Price tier.
- `statement.rows.properties` (object, required): Validated pricing properties used to match dimensions and multipliers.
- `statement.nextCursor` (object | null, required): Next-page cursor; null means end. Pass unchanged and clear when filters change.
- `statement.nextCursor.at` (date-time, required): Occurrence time (ISO 8601) of the last row on this page; part of the cursor to pass unchanged as `after`.
- `statement.nextCursor.id` (uuid, required): ID of the last row on this page. Pass the whole `nextCursor` object back unchanged to read the next page.
- `statement.nextCursor.position` (integer, required): Position. min: 0 · max: 9007199254740991

<a id="errors"></a>

## Errors

Failures return an error object; handle them by `error.code` and `error.recovery`. The table lists the errors that follow from this operation's credential, scope and idempotency fields; depending on the request it can also return `NOT_FOUND` (a referenced resource doesn't exist), `NOT_CONFIGURED` (a required integration isn't connected) or `PAYLOAD_TOO_LARGE`. Some refusals, such as insufficient balance, are not errors but a `reason` in a successful response.

**Possible errors**

| code | HTTP | When | recovery |
| --- | --- | --- | --- |
| `INVALID_REQUEST` | 400 | The request doesn't match this page's parameters. A missing or malformed protocol header returns `UNSUPPORTED_PROTOCOL_VERSION` or `INVALID_PROTOCOL_VERSION` instead. | `fix_request` |
| `UNAUTHENTICATED` | 401 | The credential is missing, invalid, expired or revoked. | `authenticate` |
| `FORBIDDEN` | 403 | The credential lacks `credits:read`. | `check_permissions` |
| `SCOPE_MISMATCH` | 403 | `X-Indiana-Project` or `X-Indiana-Environment` doesn't match the credential's App and environment. | `check_scope` |
| `RATE_LIMITED` | 429 | Too many requests; wait for `Retry-After` and retry the same request. | `retry_same_request` |
| `SERVICE_UNAVAILABLE` | 503 | The service is temporarily unavailable; retry the same request. | `retry_same_request` |
| `INTERNAL_ERROR` | 500 | The outcome is unknown; retry later. | `recover_operation` |

- [Error codes and recovery](https://www.longplayai.com/docs/api/errors.md)
- [Request conventions](https://www.longplayai.com/docs/api.md)
- [All operations](https://www.longplayai.com/docs/api/operations.md#credits)
