Pagination
Instance search uses cursor-based pagination (keyset), not page/offset. This gives consistent results even when instances are being created or updated between pages.
Request
{
"page": {
"limit": 50,
"cursor": null
}
}
limit: Results per page. Default:50, maximum:200.cursor: Opaque string from the previous page'snextCursor. Omit or passnullfor the first page.
Response
{
"results": [ ... ],
"nextCursor": "eyJzdGFydGVkQXQiOiIyMDI2...",
"stats": {
"returned": 50,
"limit": 50
}
}
results: Current page of instances.nextCursor: Pass ascursoron the next request.nullwhen there are no more results.
Iterating all pages
let cursor = null;
do {
const response = await fetch('/v1/instances/search', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
filter: { "variables.status": "in_review" },
page: { limit: 200, cursor },
}),
}).then(r => r.json());
for (const instance of response.results) {
// process instance
}
cursor = response.nextCursor;
} while (cursor !== null);
Why not offset?
Offset-based pagination (page=2, offset=100) has two problems at scale:
- Inconsistency: A new instance inserted while you're reading shifts pages — you may skip records or see duplicates
- Performance:
OFFSET 10000forces the database to scan and discard 10,000 rows on every request
Cursor pagination avoids both by resuming exactly from where it left off using an indexed key comparison.