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

# Pagination

> Page through customers, conversations and messages.

Lists come in two styles.

## Page numbers: customers and conversations

Use `page` and `limit`.

| Parameter | Default | Range |
| - | - | - |
| `page` | `1` | 1 or more |
| `limit` | `20` | 1 to 100 |

`meta` describes the page:

```json
{
  "meta": {
    "totalItems": 134,
    "itemCount": 20,
    "itemsPerPage": 20,
    "totalPages": 7,
    "currentPage": 1
  }
}
```

```javascript
async function* allConversations() {
  for (let page = 1; ; page++) {
    const res = await fetch(
      `https://api.usecerium.com/v1/conversations?page=${page}&limit=100`,
      { headers: { Authorization: `Bearer ${process.env.CERIUM_API_KEY}` } },
    );
    const { data, meta } = await res.json();
    yield* data;
    if (page >= meta.totalPages) return;
  }
}
```

## Cursor: messages

Messages use a cursor, because new messages arrive while you page. Pass the id of the **oldest message you hold** as `before`.

```json
{ "meta": { "hasMore": true, "nextBefore": "msg_5c90" } }
```

```javascript
async function allMessages(conversationId) {
  const messages = [];
  let before;

  do {
    const url = new URL(
      `https://api.usecerium.com/v1/conversations/${conversationId}/messages`,
    );
    url.searchParams.set("limit", "100");
    if (before) url.searchParams.set("before", before);

    const res = await fetch(url, {
      headers: { Authorization: `Bearer ${process.env.CERIUM_API_KEY}` },
    });
    const { data, meta } = await res.json();

    messages.push(...data);
    before = meta.nextBefore;
  } while (before);

  return messages;
}
```

Stop when `meta.nextBefore` is `null`.

> [!TIP]
>
> For a chat screen, load the newest page (`order=desc`, the default) and fetch older ones with `before` as the person scrolls up.
