Skip to content

Pagination

The Chainabit API supports two pagination strategies: offset-based and cursor-based. Most list endpoints use offset-based pagination. Cursor-based pagination is used by specific endpoints where consistent ordering across pages is critical (e.g., notification history, audit logs).

Offset-Based Pagination

Query Parameters

ParameterTypeDefaultRangeDescription
limitinteger201 -- 50Number of records to return per page.
offsetinteger00+Number of records to skip before returning results.

Example Request

http
GET /api/v1/chains?limit=10&offset=20
Authorization: Bearer <accessToken>

Example Response

json
{
  "data": [
    { "id": "chain_001", "name": "Morning Run" },
    { "id": "chain_002", "name": "Read 20 Pages" }
  ],
  "meta": {
    "requestId": "req_abc123",
    "durationMs": 15,
    "limit": 10,
    "offset": 20,
    "total": 47,
    "hasNextPage": true
  }
}

Iterating Through Pages

Use offset and limit to walk through the full result set:

Page 1: GET /chains?limit=20&offset=0   → records 1-20
Page 2: GET /chains?limit=20&offset=20  → records 21-40
Page 3: GET /chains?limit=20&offset=40  → records 41-47

Stop iterating when hasNextPage is false or when offset + limit >= total.

Cursor-Based Pagination

Cursor-based pagination uses an opaque token to mark the position in the result set. This ensures stable pagination even when records are added or removed between requests.

Query Parameters

ParameterTypeDefaultDescription
limitinteger25Number of records to return per page.
cursorstring(none)Opaque pagination token from a previous response. Omit for the first page.
http
GET /api/v1/notifications?limit=10
Authorization: Bearer <accessToken>

Example Response

json
{
  "data": [
    { "id": "ntf_001", "type": "ai_run_completed", "read": false },
    { "id": "ntf_002", "type": "workspace_invite", "read": true }
  ],
  "meta": {
    "requestId": "req_def456",
    "durationMs": 22,
    "limit": 10,
    "hasNextPage": true,
    "nextCursor": "eyJpZCI6Im50Zl8wMDIifQ=="
  }
}

Example Request (Next Page)

http
GET /api/v1/notifications?limit=10&cursor=eyJpZCI6Im50Zl8wMDIifQ==
Authorization: Bearer <accessToken>

Iterating Through Pages

  1. Make the initial request without a cursor.
  2. If hasNextPage is true, make another request with cursor set to nextCursor from the previous response.
  3. Repeat until hasNextPage is false.
javascript
let cursor = undefined;

do {
  const params = new URLSearchParams({ limit: '25' });
  if (cursor) params.set('cursor', cursor);

  const response = await fetch(
    `https://api.chainabit.com/api/v1/notifications?${params}`,
    { headers: { Authorization: `Bearer ${token}` } }
  );
  const { data, meta } = await response.json();

  // Process data...

  cursor = meta.hasNextPage ? meta.nextCursor : undefined;
} while (cursor);

Response Meta Fields

Both pagination strategies include metadata in the response meta object:

FieldTypePresent InDescription
limitintegerBothThe page size used for this request.
offsetintegerOffset onlyThe number of records skipped.
totalintegerOffset onlyTotal number of records matching the query.
hasNextPagebooleanBothWhether more records exist beyond this page.
nextCursorstringCursor onlyThe token to pass as cursor for the next page.

Which Endpoints Use Which Strategy

StrategyEndpoints
Offset-basedMost list endpoints: chains, chainies, bits, boards, cards, agents, workflows, etc.
Cursor-basedNotification history, audit logs, and other ordered list endpoints.

The pagination strategy for each endpoint is documented in the individual endpoint reference.

Built with purpose.