SDKsTypeScript

Pagination

How PagePromise works and the three iteration patterns available in the TypeScript SDK.

Every list method returns a PagePromise, which is both a promise and an async iterable. Await it to get a single Page, or iterate it with for await to walk every item across pages, fetching the next page only when the current one runs out.

// One page
const page = await bimpe.agents.list({ limit: 50 });
page.data;        // readonly Agent[]
page.meta;        // PaginationMeta | null
page.requestId;   // string | null
page.hasNextPage; // boolean
const next = await page.getNextPage(); // Page<Agent> | null

// Every item, fetching pages on demand
for await (const agent of bimpe.agents.list({ limit: 50 })) {
  console.log(agent.id);
}

// Page by page
for await (const page of bimpe.agents.list().pages()) {
  console.log(page.meta?.current_page);
}

PaginationMeta carries total_count, page_count, current_page, limit, has_next_page, and has_previous_page.