Skip to main content
  • Status: Approved
  • Updated: 2026-11-28
Consistent list pagination lets callers, generated SDKs, CLIs, and automated agents traverse any paginated collection with one shared iteration loop instead of endpoint-specific cursor names, wrapper objects, or termination heuristics. This standard is part of Photon API Design Standards and uses the keywords MUST, MUST NOT, SHOULD, and MAY as described in RFC 2119.

Scope

This standard defines the request parameters, response shape, bounds validation, token opacity, error contract, and ordering guarantees for paginated GET collection endpoints across Photon public HTTP APIs. Related concerns are governed by separate standards:
  • Resource identifier fields (id, <resource>Id) and URL path parameter naming ({<resource>Id}) are defined in ADS-0001.
  • Top-level JSON object collection responses (prohibiting bare top-level arrays) are defined in ADS-0002.
  • Standard collection GET semantics and collection-to-item read symmetry are defined in ADS-0005.

Normative Rules

1. Forward opaque token pagination (AIP-158)

Paginated GET collection endpoints MUST use forward opaque token pagination modeled on Google AIP-158:
  • Request query parameters:
    • pageSize (optional integer): maximum number of items to return in the current page.
    • pageToken (optional string, minLength: 1): opaque continuation token received as nextPageToken from a previous page response.
  • Response field:
    • nextPageToken (optional string, minLength: 1): direct top-level property alongside the collection array (per ADS-0002), omitted on the final page.
  • nextPageToken MUST be placed directly at the top level of the 200 OK JSON response object and MUST NOT be nested inside a wrapper object such as page, pagination, pageInfo, listMetadata, or meta.
  • Pagination contracts MUST be symmetric on GET operations: any GET endpoint declaring pageSize, pageToken, or top-level nextPageToken MUST declare all three.
  • New endpoints MUST NOT use non-standard pagination query parameters (cursor, limit, offset, page, perPage, per_page, page_size, page_token, pageNumber, page_number, after, before, startingAfter, endingBefore, starting_after, ending_before, nextToken, next_token, continuationToken, or continuation_token) or non-standard pagination response fields (nextCursor, prevCursor, previousCursor, prevPageToken, previousPageToken, nextPage, hasMore, hasNextPage, hasPreviousPage, pageInfo, pagination, listMetadata, or their snake_case equivalents).
  • Ordering direction and sort criteria MUST be expressed through explicit sort query parameters (such as order or orderBy), not bidirectional cursors (after/before, startingAfter/endingBefore, or prevPageToken).

2. End-of-list termination and partial or empty pages

  • When there are no more items to return, the server MUST omit nextPageToken from the response JSON object.
  • Responses MUST NOT serialize "nextPageToken": null or "nextPageToken": "" to indicate the final page.
  • In OpenAPI, nextPageToken MUST be optional (absent from required), non-nullable type: string, and declare minLength: 1.
  • A response MAY return fewer than pageSize items—or 0 items—while still returning a non-empty nextPageToken (for example, when server-side authorization or filtering removes entries from an internal storage slice).
  • Clients MUST continue paginating strictly until nextPageToken is absent from the response, and MUST NOT terminate early because items.length < pageSize or because a page array is empty.

3. pageSize bounds, strict validation, and cross-page resizing

  • pageSize MUST be an optional, non-nullable integer query parameter declaring an explicit minimum of at least 1 and an explicit reasonable maximum:
    • 100 is recommended for standard resource collections.
    • Up to 200 is recommended for high-throughput event or message streams.
    • OpenAPI schemas MUST NOT omit minimum or maximum, accept 0 or negative values, or use unbounded pseudo-maxima (such as MAX_SAFE_INTEGER or values above 1000).
  • Servers MUST document their default page size (for example 20 or 50) in the pageSize parameter description.
  • Servers MUST reject out-of-range values (0, negative integers, or integers above maximum) and non-integer values with 422 Unprocessable Content (RFC 9110 §15.5.21; RFC 9457 Problem Details, VALIDATION_FAILED) rather than silently clamping values or treating 0 as the default.
  • Callers MAY change pageSize on subsequent requests while passing a pageToken; the updated pageSize applies to that request’s page only. Servers MUST NOT bind pageSize into pageToken validation or reject a valid pageToken solely because pageSize changed between pages.

4. Opaque tokens and 400 INVALID_PAGE_TOKEN error contract

  • pageToken and nextPageToken are opaque strings (type: string, minLength: 1, optional, non-nullable). Clients MUST NOT parse, decode, construct, modify, or persist tokens long-term across sessions.
  • Servers SHOULD bind page tokens to the active filter parameters, sort parameters, and resource scope, and SHOULD protect both token integrity and confidentiality—for example using authenticated encryption or opaque server-side handles—so internal storage keys and query cursors are neither exposed nor forgeable (an HMAC signature alone protects integrity, not confidentiality).
  • Malformed, expired, tampered, or filter/sort-mismatched pageToken values MUST return 400 Bad Request with Content-Type: application/problem+json (RFC 9457 Problem Details) and error code INVALID_PAGE_TOKEN.

5. Deterministic ordering, consistency, and exact counts

  • Paginated collections MUST define a deterministic total order—such as a primary sort field paired with a unique id tie-breaker—so items with identical primary sort keys do not shift unpredictably between pages.
  • Pagination provides best-effort snapshot consistency across concurrent writes; callers that require strict uniqueness across pages SHOULD deduplicate items by their canonical id (ADS-0001).
  • Paginated collection responses MUST NOT include expensive inline total-count fields such as total or totalCount. When callers need an exact count, expose a dedicated count endpoint such as GET /v1/.../<collection>/count returning { "count": 42 } (per ADS-0002).

6. Exemptions and deprecation transitions

  • Unpaginated collections: Bounded static reference catalogs (such as supported countries, permission scopes, event types, or plan catalogs) and small fixed-cap sub-resources are NOT required to paginate. Unpaginated endpoints simply omit pageSize, pageToken, and nextPageToken.
  • Unbounded collections: Collections that grow per tenant, project, organization, or time period MUST implement pagination under this standard.
  • Migration transitions: When migrating an existing endpoint from a legacy pagination scheme, legacy query parameters and response properties explicitly marked deprecated: true in OpenAPI MAY coexist temporarily alongside canonical pageSize, pageToken, and nextPageToken until removed in a versioned release.

Examples

Canonical paginated collection OpenAPI contract

Good — optional pageSize (1..100, documented default), optional pageToken (minLength: 1), optional non-nullable top-level nextPageToken (minLength: 1), 400 RFC 9457 Problem Details for INVALID_PAGE_TOKEN, and 422 RFC 9457 Problem Details for invalid query parameters such as an out-of-range pageSize:

Multi-page traversal, cross-page resizing, and final page

Good — first page (pageSize=2), second page resizing pageSize to 50 and returning an empty filtered page that still carries nextPageToken, followed by the final page omitting nextPageToken:

Invalid, expired, or mismatched pageToken (400 INVALID_PAGE_TOKEN)

Good — malformed, expired, tampered, or filter-mismatched pageToken returns 400 Bad Request as RFC 9457 Problem Details:

Dedicated count endpoint and unpaginated static catalog

Good — exact counts use a dedicated /count endpoint instead of inline totalCount, and bounded static reference catalogs omit pagination fields completely:

Backward-compatible migration with deprecated: true

Good — legacy cursor / nextCursor fields marked deprecated: true alongside canonical pageSize, pageToken, and nextPageToken during a migration window:

Non-conformant patterns

Bad — legacy query parameters (limit, offset, cursor, startingAfter), required or unbounded pageSize, minimum: 0, nullable or required nextPageToken, hasMore, inline totalCount, and nested pagination / pageInfo wrappers:
Bad — returning "nextPageToken": null, "nextPageToken": "", hasMore, totalCount, or a nested pageInfo object on the wire:

Changelog

  • 2026-11-26: Approved and published as ADS-0006.
  • 2026-11-28: Aligned pageSize validation errors in §3 with 422 Unprocessable Content (VALIDATION_FAILED) while keeping 400 Bad Request (INVALID_PAGE_TOKEN) for invalid page tokens in §4.

Feedback

Found a Photon API that does not follow this standard, or have a suggestion to improve it? Open an issue in photon-hq/api-design-standards (we do not accept external pull requests).