---
title: "Pagination"
description: "How lists are paged: pages by offset for inboxes, threads and messages, pages by cursor for events and deliveries, polling the event log forward, every list that pages, and the iterators of each SDK."
url: https://doorman.fyi/docs/pagination
markdown: https://doorman.fyi/docs/pagination.md
area: "Guides"
section: "Conventions"
---

# Pagination

How lists are paged: pages by offset for inboxes, threads and messages, pages by cursor for events and deliveries, polling the event log forward, every list that pages, and the iterators of each SDK.

Source: https://doorman.fyi/docs/pagination

## Two kinds of page

A list that can grow answers one page at a time. `limit` is the page size on every one of them: 50 by default and 100 at most. What differs is how the next page is asked for.

- Pages by offset: `limit` and `offset`. The answer carries `data`, the `limit` and `offset` that were applied, and for most lists a `total`. The next page is `offset + data.length`. Right for a list a person scrolls or jumps around in.
- Pages by cursor: `limit` and `cursor`. The answer carries `data` and `nextCursor`, which is null on the last page. The next page is the same request with `cursor` set to it. Right for a log that grows while it is read.

A list that is bounded by a limit of the API, such as an inbox's rules or an account's endpoints, answers whole in one `data` array and takes neither parameter.

## Pages by offset

The second page of an inbox's threads:
```sh
curl -s "https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/threads?limit=50&offset=50" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

- Use the `limit` the answer carries, not the one you sent: it is the one that was applied.
- The last page is the first one with fewer items than its `limit`. An empty page is a last page too.
- Filters narrow the list before it is paged, and `total` counts what the filters left.
- A list read while it changes can shift under the offset: an item that arrives ahead of the offset pushes one already seen onto the next page, and a removal skips one. Where that matters, read the change from the [event log](https://doorman.fyi/docs/events.md) instead of listing again.

## Pages by cursor

The newest events, then the page before:
```sh
curl -s "https://api.doorman.fyi/v1/events?limit=50" \
  -H "authorization: Bearer $DOORMAN_API_KEY"

curl -s "https://api.doorman.fyi/v1/events?limit=50&cursor=1041" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

- Pass `nextCursor` back as it was given. It is a place in the list and nothing to compute with.
- A list paged by cursor answers the newest first, and a page holds what is older than its cursor. Something that arrives while you page is newer than every page still to come, so nothing is repeated and nothing is skipped.
- On the event log a cursor that is not a number answers `400 validation_error`.

## Polling forward

The event log reads in the other direction too. [`GET /v1/events?after=<seq>`](https://doorman.fyi/docs/reference/events.md#events-list) answers what happened after a position, oldest first, as an [`EventPoll`](https://doorman.fyi/docs/reference/schemas.md#EventPoll): `data` and `latestSeq`, the position to ask from next. This is not paging back through history. It is how a program that wakes on a schedule learns what is new, and it is described in [Polling forward: after](https://doorman.fyi/docs/events.md#polling).

> Note: `after` and `cursor` cannot be combined: one request either pages back or polls forward.

## Every list that pages

| Operation | Pages by | Walked by |
| --- | --- | --- |
| [`inboxes.list`](https://doorman.fyi/docs/reference/inboxes.md#inboxes-list) | `offset` | [`client.inboxes.iterate`](https://doorman.fyi/docs/sdk/reference/inboxes.md#inboxes-iterate), [`client.inboxes.iterate`](https://doorman.fyi/docs/python/reference/inboxes.md#inboxes-iterate) in Python |
| [`inboxes.rules.runs`](https://doorman.fyi/docs/reference/inboxes.md#inboxes-rules-runs) | `offset` | [`client.inboxes.rules.iterateRuns`](https://doorman.fyi/docs/sdk/reference/inboxes.md#inboxes-rules-iterateRuns), [`client.inboxes.rules.iterate_runs`](https://doorman.fyi/docs/python/reference/inboxes.md#inboxes-rules-iterate-runs) in Python |
| [`inboxes.webhook.deliveries`](https://doorman.fyi/docs/reference/webhooks.md#inboxes-webhook-deliveries) | `cursor` | [`client.inboxes.webhook.iterateDeliveries`](https://doorman.fyi/docs/sdk/reference/webhooks.md#inboxes-webhook-iterateDeliveries), [`client.inboxes.webhook.iterate_deliveries`](https://doorman.fyi/docs/python/reference/webhooks.md#inboxes-webhook-iterate-deliveries) in Python |
| [`inboxes.threads.list`](https://doorman.fyi/docs/reference/mail.md#inboxes-threads-list) | `offset` | [`client.inboxes.threads.iterate`](https://doorman.fyi/docs/sdk/reference/mail.md#inboxes-threads-iterate), [`client.inboxes.threads.iterate`](https://doorman.fyi/docs/python/reference/mail.md#inboxes-threads-iterate) in Python |
| [`inboxes.threads.listBySeen`](https://doorman.fyi/docs/reference/mail.md#inboxes-threads-listBySeen) | `offset` | [`client.inboxes.threads.iterate_list_by_seen`](https://doorman.fyi/docs/python/reference/mail.md#inboxes-threads-iterate-list-by-seen) in Python |
| [`inboxes.messages.list`](https://doorman.fyi/docs/reference/mail.md#inboxes-messages-list) | `offset` | [`client.inboxes.messages.iterate`](https://doorman.fyi/docs/sdk/reference/mail.md#inboxes-messages-iterate), [`client.inboxes.messages.iterate`](https://doorman.fyi/docs/python/reference/mail.md#inboxes-messages-iterate) in Python |
| [`events.list`](https://doorman.fyi/docs/reference/events.md#events-list) | `cursor` | [`client.events.iterate`](https://doorman.fyi/docs/sdk/reference/events.md#events-iterate), [`client.events.iterate`](https://doorman.fyi/docs/python/reference/events.md#events-iterate) in Python |
| [`webhooks.deliveries`](https://doorman.fyi/docs/reference/webhooks.md#webhooks-deliveries) | `cursor` | [`client.webhooks.iterateDeliveries`](https://doorman.fyi/docs/sdk/reference/webhooks.md#webhooks-iterateDeliveries), [`client.webhooks.iterate_deliveries`](https://doorman.fyi/docs/python/reference/webhooks.md#webhooks-iterate-deliveries) in Python |
| [`services.list`](https://doorman.fyi/docs/reference/passport.md#services-list) | `offset` | [`client.services.iterate`](https://doorman.fyi/docs/sdk/reference/passport.md#services-iterate), [`client.services.iterate`](https://doorman.fyi/docs/python/reference/passport.md#services-iterate) in Python |
| [`inboxes.senders.list`](https://doorman.fyi/docs/reference/security.md#inboxes-senders-list) | `offset` | [`client.inboxes.senders.iterate`](https://doorman.fyi/docs/sdk/reference/security.md#inboxes-senders-iterate), [`client.inboxes.senders.iterate`](https://doorman.fyi/docs/python/reference/security.md#inboxes-senders-iterate) in Python |
| [`senderRules.list`](https://doorman.fyi/docs/reference/security.md#senderRules-list) | `offset` | [`client.senderRules.iterate`](https://doorman.fyi/docs/sdk/reference/security.md#senderRules-iterate), [`client.sender_rules.iterate`](https://doorman.fyi/docs/python/reference/security.md#sender-rules-iterate) in Python |
| [`inboxes.held.list`](https://doorman.fyi/docs/reference/security.md#inboxes-held-list) | `offset` | [`client.inboxes.held.iterate`](https://doorman.fyi/docs/sdk/reference/security.md#inboxes-held-iterate), [`client.inboxes.held.iterate`](https://doorman.fyi/docs/python/reference/security.md#inboxes-held-iterate) in Python |
| [`security.audit`](https://doorman.fyi/docs/reference/security.md#security-audit) | `offset` | [`client.security.iterateAudit`](https://doorman.fyi/docs/sdk/reference/security.md#security-iterateAudit), [`client.security.iterate_audit`](https://doorman.fyi/docs/python/reference/security.md#security-iterate-audit) in Python |
| [`inboxes.heldSends.list`](https://doorman.fyi/docs/reference/security.md#inboxes-heldSends-list) | `offset` | [`client.inboxes.heldSends.iterate`](https://doorman.fyi/docs/sdk/reference/security.md#inboxes-heldSends-iterate), [`client.inboxes.held_sends.iterate`](https://doorman.fyi/docs/python/reference/security.md#inboxes-held-sends-iterate) in Python |

## Iterators in the SDKs

Both clients have a method beside each list that walks every page for you. It asks for a page only when the loop reaches it, so leaving the loop early costs nothing more.

TypeScript:
```ts
// Every unread thread of an inbox, however many pages that is.
for await (const thread of client.inboxes.threads.iterate("inb_01jc4q7w9k2m5n8p3r6t1v4x7z", { isRead: false })) {
  console.log(thread.id, thread.subject);
}

// One page at a time, when you want the page itself.
const page = await client.inboxes.threads.list("inb_01jc4q7w9k2m5n8p3r6t1v4x7z", { limit: 25, offset: 50 });
```

Python:
```python
# Every unread thread of an inbox, however many pages that is.
for thread in client.inboxes.threads.iterate("inb_01jc4q7w9k2m5n8p3r6t1v4x7z", is_read=False):
    print(thread["id"], thread["subject"])

# One page at a time, when you want the page itself.
page = client.inboxes.threads.list("inb_01jc4q7w9k2m5n8p3r6t1v4x7z", limit=25, offset=50)
```

- An iterator takes the list's own filters, and starts from the `offset` or `cursor` you give it.
- The TypeScript iterators are async generators. An offset walk ends at the first page shorter than its limit, and a cursor walk when `nextCursor` is null.
- The Python iterators check each page as well: one whose offset or limit is not the one asked for, or whose cursor does not advance, raises `ApiError` with the code `unexpected_response` instead of looping.
- Neither retries a page that fails. The error is the one the list itself would have raised, and the items already yielded stay handled.

On the command line a list command takes `--limit` with `--offset` or `--cursor` and prints one page. An MCP tool takes the same inputs, and on the surface for a model an answer that was shortened says how to ask for the next items.
