ADS-0006: List Pagination
Forward opaque token pagination using pageSize, pageToken, and nextPageToken, strict bounds validation, end-of-list omission, deterministic ordering, and unified error contracts across Photon public HTTP APIs.
- 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 inADS-0001. - Top-level JSON object collection responses (prohibiting bare top-level arrays) are defined in
ADS-0002. - Standard collection
GETsemantics and collection-to-item read symmetry are defined inADS-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(optionalinteger): maximum number of items to return in the current page.pageToken(optionalstring,minLength: 1): opaque continuation token received asnextPageTokenfrom a previous page response.
- Response field:
nextPageToken(optionalstring,minLength: 1): direct top-level property alongside the collection array (perADS-0002), omitted on the final page.
nextPageTokenMUST be placed directly at the top level of the200 OKJSON response object and MUST NOT be nested inside a wrapper object such aspage,pagination,pageInfo,listMetadata, ormeta.- Pagination contracts MUST be symmetric on
GEToperations: anyGETendpoint declaringpageSize,pageToken, or top-levelnextPageTokenMUST 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, orcontinuation_token) or non-standard pagination response fields (nextCursor,prevCursor,previousCursor,prevPageToken,previousPageToken,nextPage,hasMore,hasNextPage,hasPreviousPage,pageInfo,pagination,listMetadata, or theirsnake_caseequivalents). - Ordering direction and sort criteria MUST be expressed through explicit sort query parameters (such as
orderororderBy), not bidirectional cursors (after/before,startingAfter/endingBefore, orprevPageToken).
2. End-of-list termination and partial or empty pages
- When there are no more items to return, the server MUST omit
nextPageTokenfrom the response JSON object. - Responses MUST NOT serialize
"nextPageToken": nullor"nextPageToken": ""to indicate the final page. - In OpenAPI,
nextPageTokenMUST be optional (absent fromrequired), non-nullabletype: string, and declareminLength: 1. - A response MAY return fewer than
pageSizeitems—or0items—while still returning a non-emptynextPageToken(for example, when server-side authorization or filtering removes entries from an internal storage slice). - Clients MUST continue paginating strictly until
nextPageTokenis absent from the response, and MUST NOT terminate early becauseitems.length < pageSizeor because a page array is empty.
3. pageSize bounds, strict validation, and cross-page resizing
pageSizeMUST be an optional, non-nullableintegerquery parameter declaring an explicitminimumof at least1and an explicit reasonablemaximum:100is recommended for standard resource collections.- Up to
200is recommended for high-throughput event or message streams. - OpenAPI schemas MUST NOT omit
minimumormaximum, accept0or negative values, or use unbounded pseudo-maxima (such asMAX_SAFE_INTEGERor values above1000).
- Servers MUST document their default page size (for example
20or50) in thepageSizeparameter description. - Servers MUST reject out-of-range values (
0, negative integers, or integers abovemaximum) and non-integer values with422 Unprocessable Content(RFC 9110 §15.5.21; RFC 9457 Problem Details,VALIDATION_FAILED) rather than silently clamping values or treating0as the default. - Callers MAY change
pageSizeon subsequent requests while passing apageToken; the updatedpageSizeapplies to that request's page only. Servers MUST NOT bindpageSizeintopageTokenvalidation or reject a validpageTokensolely becausepageSizechanged between pages.
4. Opaque tokens and 400 INVALID_PAGE_TOKEN error contract
pageTokenandnextPageTokenare 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
pageTokenvalues MUST return400 Bad RequestwithContent-Type: application/problem+json(RFC 9457 Problem Details) and error codeINVALID_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
idtie-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
totalortotalCount. When callers need an exact count, expose a dedicated count endpoint such asGET /v1/.../<collection>/countreturning{ "count": 42 }(perADS-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, andnextPageToken. - 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: truein OpenAPI MAY coexist temporarily alongside canonicalpageSize,pageToken, andnextPageTokenuntil 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:
paths:
/v1/projects/{projectId}/webhooks:
parameters:
- name: projectId
in: path
required: true
description: Unique identifier of the project.
schema:
type: string
get:
operationId: listWebhooks
summary: List project webhooks
parameters:
- name: pageSize
in: query
description: Maximum number of webhooks to return per page. Defaults to 20.
schema:
type: integer
minimum: 1
maximum: 100
- name: pageToken
in: query
description: Opaque continuation token returned by a previous page.
schema:
type: string
minLength: 1
- name: order
in: query
description: Sort direction applied to creation time with id tie-breaker.
schema:
type: string
enum:
- asc
- desc
responses:
"200":
description: A page of project webhooks.
content:
application/json:
schema:
type: object
required:
- items
properties:
items:
type: array
items:
$ref: "#/components/schemas/Webhook"
nextPageToken:
type: string
minLength: 1
description: Opaque token for fetching the next page. Omitted on the final page.
"400":
description: Invalid, expired, or mismatched pageToken (INVALID_PAGE_TOKEN).
content:
application/problem+json:
schema:
$ref: "#/components/schemas/ProblemDetails"
"422":
description: Invalid query parameter, such as an out-of-range pageSize (VALIDATION_FAILED).
content:
application/problem+json:
schema:
$ref: "#/components/schemas/ProblemDetails"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:
GET /v1/projects/prj_01h455vb4pex5vsknk084sn02q/webhooks?pageSize=2 HTTP/1.1
Host: api.photon.codes{
"items": [
{
"id": "whk_01h455vb4pex5vsknk084sn02u",
"projectId": "prj_01h455vb4pex5vsknk084sn02q",
"url": "https://webhooks.example.com/primary",
"enabled": true
},
{
"id": "whk_01h455vb4pex5vsknk084sn02v",
"projectId": "prj_01h455vb4pex5vsknk084sn02q",
"url": "https://webhooks.example.com/audit",
"enabled": true
}
],
"nextPageToken": "eyJjIjoiMjAyNi0xMS0yNiJ9"
}GET /v1/projects/prj_01h455vb4pex5vsknk084sn02q/webhooks?pageSize=50&pageToken=eyJjIjoiMjAyNi0xMS0yNiJ9 HTTP/1.1
Host: api.photon.codes{
"items": [],
"nextPageToken": "eyJjIjoiMjAyNi0xMS0yN19wMiJ9"
}GET /v1/projects/prj_01h455vb4pex5vsknk084sn02q/webhooks?pageSize=50&pageToken=eyJjIjoiMjAyNi0xMS0yN19wMiJ9 HTTP/1.1
Host: api.photon.codes{
"items": [
{
"id": "whk_01h455vb4pex5vsknk084sn02w",
"projectId": "prj_01h455vb4pex5vsknk084sn02q",
"url": "https://webhooks.example.com/archive",
"enabled": false
}
]
}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:
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json{
"type": "https://docs.photon.codes/errors/invalid-page-token",
"title": "Invalid page token",
"status": 400,
"code": "INVALID_PAGE_TOKEN",
"detail": "The supplied pageToken is malformed, expired, or does not match the current filter or sort parameters."
}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:
GET /v1/organizations/org_01h455vb4pex5vsknk084sn02s/projects/count HTTP/1.1
Host: api.photon.codes{
"count": 42
}GET /v1/scopes HTTP/1.1
Host: api.photon.codes{
"items": [
{
"name": "projects:read",
"description": "Read project metadata."
}
]
}Backward-compatible migration with deprecated: true
Good — legacy cursor / nextCursor fields marked deprecated: true alongside canonical pageSize, pageToken, and nextPageToken during a migration window:
paths:
/v1/projects/{projectId}/events:
get:
operationId: listProjectEvents
parameters:
- name: pageSize
in: query
description: Maximum number of events per page. Defaults to 50.
schema:
type: integer
minimum: 1
maximum: 200
- name: pageToken
in: query
description: Opaque continuation token from the previous page.
schema:
type: string
minLength: 1
- name: cursor
in: query
deprecated: true
description: Deprecated alias for pageToken.
schema:
type: string
responses:
"200":
description: Page of project events.
content:
application/json:
schema:
type: object
required:
- items
properties:
items:
type: array
items:
$ref: "#/components/schemas/Event"
nextPageToken:
type: string
minLength: 1
nextCursor:
type: string
deprecated: trueNon-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:
paths:
/v1/projects/{projectId}/webhooks:
get:
summary: Uses non-standard parameters and invalid bounds
parameters:
- name: limit
in: query
schema:
type: integer
- name: offset
in: query
schema:
type: integer
- name: pageSize
in: query
required: true
schema:
type: integer
minimum: 0
maximum: 9007199254740991
responses:
"200":
description: Non-conformant paginated response
content:
application/json:
schema:
type: object
required:
- items
- nextPageToken
- hasMore
properties:
items:
type: array
items:
$ref: "#/components/schemas/Webhook"
nextPageToken:
type:
- string
- "null"
hasMore:
type: boolean
pagination:
type: object
properties:
nextCursor:
type: stringBad — returning "nextPageToken": null, "nextPageToken": "", hasMore, totalCount, or a nested pageInfo object on the wire:
{
"items": [],
"nextPageToken": null,
"hasMore": false,
"totalCount": 1240,
"pageInfo": {
"hasNextPage": false
}
}Changelog
- 2026-11-26: Approved and published as
ADS-0006. - 2026-11-28: Aligned
pageSizevalidation errors in §3 with422 Unprocessable Content(VALIDATION_FAILED) while keeping400 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).