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#
- Make a request with an optional
limitparameter (default: 50, max: 100) - Check
pagination.hasMorein the response - If
true, passpagination.cursoras thecursorquery parameter for the next request - Repeat until
hasMoreisfalse
Response Structure#
{
"data": [ ... ],
"pagination": {
"cursor": "eyJpZCI6IjY1YTEyM...",
"hasMore": true,
"total": 1500
},
"meta": { "creditsConsumed": 1 }
}| Field | Type | Description |
|---|---|---|
cursor | string | null | Opaque cursor for the next page. null on the last page. |
hasMore | boolean | Whether more pages are available. |
total | number | Total 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)