Pagination
In this guide, we will look at how to work with paginated responses when querying the NexusGPT API. By default, all responses limit results to 10. However, you can go as high as 100 by adding a perPage
parameter in the query of your requests. The page
(which starts at 1) query parameter will allow to select the page you want retrieve.
When an API response returns a list of objects, no matter the amount, pagination is supported. In paginated responses, you will find a data
attribute containing the list of objects and a meta
attribute that indicates where you stand in the pagination.
Example
In this example, we request the first page of all the chats the user has created. We also limit the number of results to 2 per page.
- Name
perPage
- Type
- integer
- Description
The number of results you want to retrieve per page.
- Name
page
- Type
- integer
- Description
The page number you want to retrieve.
Request
curl -G "https://api.gpt.nexus/api/public/v1/chats?page=1&perPage=2" \
-H "api-key: {your_api_key}"
Paginated response
{
"data": [
{
// first item
},
{
// second item
}
],
"meta": {
"total": 59,
"lastPage": 30,
"currentPage": 1,
"perPage": 2,
"prev": null,
"next": 2
}
}