# Read usage batch results

Operation / SDK: `readUsageBatch` · `read_usage_batch` · `ReadUsageBatch`

Page through the per-item results of a usage batch.

Last updated: 2026-11-05

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

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

## Request

- **Credential**: Server Key with `credits:read`. Call from your backend only.
- **SDK**: JavaScript `createLongplayServer().readUsageBatch` · Python `read_usage_batch` · Go `ReadUsageBatch`
- **Success**: HTTP 200

The response shows example data.

**cURL: request.sh**

```bash
curl -X POST "$LONGPLAY_API_URL/api/v1/usage/batch/read" \
  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \
  -H "X-Indiana-Protocol: 0.10" \
  -H "Content-Type: application/json" \
  -d '{
  "batchId": "f9bad959-aa86-4e4a-801f-11c26e67bddd",
  "after": -1,
  "limit": 50
}'
```

**TypeScript: readUsageBatch.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 readUsageBatch() {
  return longplay.readUsageBatch({
    batchId: "f9bad959-aa86-4e4a-801f-11c26e67bddd",
    after: -1,
    limit: 50,
  });
}
```

**Request body: request.json**

```json
{
  "batchId": "f9bad959-aa86-4e4a-801f-11c26e67bddd",
  "after": -1,
  "limit": 50
}
```

**Response: response.json**

```json
{
  "requestId": "44f5fcb8-6ed8-41b8-818f-7571941c5fd5",
  "scope": {
    "projectId": "df5426d6-b335-403c-8f3e-b0f73d2e3511",
    "environment": "sandbox"
  },
  "batch": {
    "batchId": "f9bad959-aa86-4e4a-801f-11c26e67bddd",
    "status": "queued",
    "total": 1,
    "processed": 0,
    "items": [
      {
        "position": 0,
        "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
        "idempotencyKey": "job-1042:consume",
        "status": "queued",
        "receipt": null,
        "errorCode": null
      }
    ],
    "nextAfter": null
  }
}
```

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

## Body parameters

**application/json**

- `batchId` (uuid, required): batch ID.
- `after` (integer, required): Read entries after this position. min: -1 · max: 999
- `limit` (integer, required): Maximum records per page, subject to the contract limit. min: 1 · max: 100

<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"`.
- `batch` (object, required): batch; fields below.
- `batch.batchId` (uuid, required): batch ID.
- `batch.status` (enum, required): Status; see the allowed values. Values: `"queued"`, `"complete"`.
- `batch.total` (integer, required): Total count; `null` when it is not computed. min: 1 · max: 1000
- `batch.processed` (integer, required): Number of items that have finished (`accepted`, `rejected` or `failed`); the batch is `complete` when it equals `total`. min: 0 · max: 1000
- `batch.items` (array, required): List items. maxItems: 100
- `batch.items.position` (integer, required): Position. min: 0 · max: 999
- `batch.items.customerId` (uuid, required): The Customer's UUID.
- `batch.items.idempotencyKey` (string, required): Stable business idempotency key. The same key and payload replay the result; do not randomize on retries. minLength: 1 · maxLength: 120
- `batch.items.status` (enum, required): Status; see the allowed values. Values: `"queued"`, `"accepted"`, `"rejected"`, `"failed"`.
- `batch.items.receipt` (object | null, required): The balance operation recorded for this item, in the same shape as a `mutateBalance` receipt; `null` while the item is queued or when it failed.
- `batch.items.receipt.id` (uuid, required): The receipt's ID.
- `batch.items.receipt.internal_feature_id` (uuid, required): Feature ID.
- `batch.items.receipt.kind` (enum, required): Kind; see the allowed values. Values: `"consume"`, `"reserve"`, `"confirm"`, `"refund"`, `"release"`, `"expire"`.
- `batch.items.receipt.originalId` (uuid | null, required): original record ID.
- `batch.items.receipt.quantity` (string, required): Quantity as a decimal string, avoiding floating-point error. pattern: ^(0|[1-9]\d{0,11})(\.\d{1,6})?$
- `batch.items.receipt.requestedQuantity` (string, optional): Original quantity for explicit cap/overflow. quantity is the quantity accepted or rejected by the operation. pattern: ^(0|[1-9]\d{0,11})(\.\d{1,6})?$
- `batch.items.receipt.overageBehavior` (enum, optional): cap accepts the largest permitted quantity, possibly zero. overflow requests the full quantity subject to overage permission, usage caps and cash budgets. Omission keeps all-or-nothing behavior. Values: `"cap"`, `"overflow"`.
- `batch.items.receipt.accepted` (boolean, required): Whether business rules accepted the operation. HTTP 200 does not imply accepted is true.
- `batch.items.receipt.reason` (enum | null, required): Rejection reason or ledger operation description; interpret with accepted and status.
- `batch.items.receipt.createdAt` (date-time, required): ISO 8601 UTC time when the record was created.
- `batch.items.receipt.reservationStatus` (enum | null, required): Reservation status; see the allowed values.
- `batch.items.receipt.expiresAt` (date-time | null, required): Expiry time (ISO 8601, UTC).
- `batch.items.receipt.allocations` (array, required): Balance allocations involved in this evaluation or ledger operation. maxItems: 500
- `batch.items.errorCode` (enum | null, required): Error code.
- `batch.nextAfter` (integer | null, required): Position of the last item on this page; pass it as `after` to read the next page. `null` when no more items follow.

<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)
