Skip to content
API Reference

Pagination

Cursor-based pagination for listing endpoints with code examples.

On this page

Pagination#

All list endpoints use cursor-based pagination for efficient traversal of large datasets. Each response includes a pagination object with a cursor for fetching the next page.

How It Works#

  1. Make a request with an optional limit parameter (default: 50, max: 100)
  2. Check pagination.hasMore in the response
  3. If true, pass pagination.cursor as the cursor query parameter for the next request
  4. Repeat until hasMore is false

Response Structure#

{
  "data": [ ... ],
  "pagination": {
    "cursor": "eyJpZCI6IjY1YTEyM...",
    "hasMore": true,
    "total": 1500
  },
  "meta": { "creditsConsumed": 1 }
}
FieldTypeDescription
cursorstring | nullOpaque cursor for the next page. null on the last page.
hasMorebooleanWhether more pages are available.
totalnumberTotal number of items in the collection.

Basic Usage#

# First page
curl "https://api.infinichat.dev/knowledge-bases/{kbId}/products?limit=50" \
  -H "X-API-Key: api_your_api_key"

# Next page (use cursor from response)
curl "https://api.infinichat.dev/knowledge-bases/{kbId}/products?limit=50&cursor=abc123" \
  -H "X-API-Key: api_your_api_key"

Iterating All Pages#

Use a loop to fetch all items across multiple pages:

// Iterate all pages
let cursor = undefined
const allProducts = []

do {
  const url = new URL("https://api.infinichat.dev/knowledge-bases/{kbId}/products")
  url.searchParams.set("limit", "100")
  if (cursor) url.searchParams.set("cursor", cursor)

  const res = await fetch(url, {
    headers: { "X-API-Key": process.env.GYDR_API_KEY },
  })
  const { data, pagination } = await res.json()

  allProducts.push(...data)
  cursor = pagination.hasMore ? pagination.cursor : undefined
} while (cursor)

We use cookies to run and improve Gydr.

Read our Cookie Policy