Overview
Paginator<T> is an async-iterable class returned by all collection methods on the Agent class (transactions, executions, logs, rewards). It provides three ways to consume paginated API results:
- Async iteration with
for await...of— automatically pages through all results. .first(count)— fetch the first N items as an array..page(num, opts)— fetch a specific page with metadata.
Paginator directly. It is returned by agent methods like agent.transactions(), agent.executions(), agent.rewards(), and others.
Usage Patterns
Pattern 1: Async Iteration
The paginator implementsAsyncIterable<T>, so you can use for await...of to iterate over all items across all pages. The paginator automatically fetches subsequent pages as needed.
Pattern 2: First N Items
Use.first(count) to get an array of the first N items. This fetches only the pages needed to fulfill the request.
.first() returns the first page of items using the configured page size.
Pattern 3: Specific Page
Use.page(num, opts) to fetch a specific page and get pagination metadata alongside the items.
Class Reference
Paginator<T>
Symbol.asyncIterator
Enablesfor await...of iteration. Automatically fetches pages until all items have been yielded.
Returns: AsyncIterableIterator<T>
page()
Fetch a specific page of results with pagination metadata.The 1-based page number to fetch.
Optional override for the page size.
Number of items per page. Defaults to the limit configured when the paginator was created (typically
20).Promise<PaginatedResponse<T>>
first()
Fetch the first N items as an array.Number of items to return. When omitted, returns the first page using the configured page size.
Promise<T[]>
PaginatedResponse<T>
The response object returned by.page().
| Field | Type | Description |
|---|---|---|
items | T[] | The items on this page |
total | number | Total number of items across all pages |
page | number | Current page number (1-based) |
limit | number | Items per page |
hasMore | boolean | Whether there are more pages after this one |
PageFetcher<T>
The internal type for the function that fetches a page of results. This is used internally by the SDK and is not needed for normal usage.Methods That Return Paginators
The followingAgent methods return Paginator instances:
| Method | Item Type | Reference |
|---|---|---|
agent.transactions() | Transaction | Transactions |
agent.executions() | ExecutionWithTransactionsDTO | Transactions |
agent.executionLogs(id) | LogDTO | Transactions |
agent.logs() | LogDTO | Transactions |
agent.rewards() | RewardDTO | Rewards |
agent.rewardHistory() | RewardDTO | Rewards |
PaginationOptions parameter:
Building a Paginated UI
This example shows how to use.page() to build a paginated list with navigation.