> ## Documentation Index
> Fetch the complete documentation index at: https://docs.platform.toloka.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Pagination

> Fetch one page at a time or iterate through all matching resources.

Use [`listPage`](https://docs.platform.toloka.ai/docs/sdk/reference/projects/list) when you need a page boundary, a total count, or a saved offset. Use [`listAll`](https://docs.platform.toloka.ai/docs/sdk/reference/projects/list) with `for await` when you want to process every result without writing the paging loop.

The examples use `client.ts` from the [quickstart](https://docs.platform.toloka.ai/docs/sdk/quickstart.md#2-create-a-client).

## Read one page

```ts theme={null}
import { client } from "./client";

const page = await client.projects.listPage({ limit: 20, offset: 0 });

for (const project of page.projects) {
  console.log(project.id, project.name);
}

console.log(page.pagination);
```

The collection key depends on the method: `projects`, `datasets`, `fields`, `items`, or another resource name. A projects page has this shape:

```json theme={null}
{
  "projects": [],
  "pagination": {
    "total": 0,
    "limit": 20,
    "offset": 0,
    "hasMore": false
  }
}
```

| `pagination` field | Meaning |
| - | - |
| `total` | Total matching results reported by this request |
| `limit` | Requested page size |
| `offset` | Number of results skipped before this page |
| `hasMore` | Whether more matching results remain |

Most paginated methods accept an integer `limit` from 1 to 100 and default to 20. [`audience.specializations.listPage`](https://docs.platform.toloka.ai/docs/sdk/reference/audience/list-specializations) and [`audience.specializations.listAll`](https://docs.platform.toloka.ai/docs/sdk/reference/audience/list-specializations) accept 1 to 1000 and default to 1000.

`offset` is a nonnegative integer and defaults to 0. To request the next page, add the returned `pagination.limit` to `pagination.offset` while `hasMore` is `true`.

## Iterate through all results

```ts theme={null}
import { client } from "./client";

for await (const project of client.projects.listAll({ limit: 100 })) {
  console.log(project.id, project.name);
}
```

[`listAll`](https://docs.platform.toloka.ai/docs/sdk/reference/projects/list) returns an async generator, not an array or a promise of an array. It fetches pages as you iterate and yields one resource at a time. Its `limit` sets the page size, not the total number yielded. Pass `offset` to start partway through a list; stop the loop with `break` when you have enough results.

Filters and resource IDs stay the same across requests. Page offsets advance using the server's returned pagination values.

## Method names

Collections nested under a resource use names such as [`datasets.listFieldsPage`](https://docs.platform.toloka.ai/docs/sdk/reference/datasets/list-fields) / [`datasets.listAllFields`](https://docs.platform.toloka.ai/docs/sdk/reference/datasets/list-fields), [`datasets.listItemsPage`](https://docs.platform.toloka.ai/docs/sdk/reference/datasets/list-items) / [`datasets.listAllItems`](https://docs.platform.toloka.ai/docs/sdk/reference/datasets/list-items), and [`models.listVersionsPage`](https://docs.platform.toloka.ai/docs/sdk/reference/models/list-versions) / [`models.listAllVersions`](https://docs.platform.toloka.ai/docs/sdk/reference/models/list-versions). Token pages use [`projects.listTokens`](https://docs.platform.toloka.ai/docs/sdk/reference/projects/list-tokens) / [`projects.listAllTokens`](https://docs.platform.toloka.ai/docs/sdk/reference/projects/list-tokens).

Some lists, such as [`datasets.listSlicesPage`](https://docs.platform.toloka.ai/docs/sdk/reference/datasets/list-slices), have only a page method. Others, such as [`files.list`](https://docs.platform.toloka.ai/docs/sdk/reference/files/list), return an array without pagination. Check the [client method index](https://docs.platform.toloka.ai/docs/sdk/reference/client-methods.md) for the method you need.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.