# Channel Pagination

The channel query endpoint allows you to paginate messages, watchers, and members for a channel. Messages use ID-based pagination for consistency, while members and watchers use offset-based pagination.

## Message Pagination

Message pagination uses ID-based parameters rather than simple offset/limit. This approach improves performance and prevents issues when the message list changes while paginating.

For example, if you fetched the first 100 messages and want to load the next 100, pass the ID of the oldest message (when paginating in descending order) or the newest message (when paginating in ascending order).

### Pagination Parameters

| Parameter   | Description                                        |
| ----------- | -------------------------------------------------- |
| `id_lt`     | Retrieve messages older than (less than) the ID    |
| `id_gt`     | Retrieve messages newer than (greater than) the ID |
| `id_lte`    | Retrieve messages older than or equal to the ID    |
| `id_gte`    | Retrieve messages newer than or equal to the ID    |
| `id_around` | Retrieve messages around a specific message ID     |

```ruby label="Ruby"
require 'getstream_ruby'
Models = GetStream::Generated::Models

# Get the ID of the oldest message on the current page
last_message_id = messages[0]['id']

# Fetch older messages
result = client.chat.get_or_create_channel('messaging', 'general',
  Models::ChannelGetOrCreateRequest.new(
    messages: Models::MessagePaginationParams.new(limit: 50, id_lt: last_message_id)
  )
)

# Fetch messages around a specific message
result = client.chat.get_or_create_channel('messaging', 'general',
  Models::ChannelGetOrCreateRequest.new(
    messages: Models::MessagePaginationParams.new(limit: 50, id_around: message_id)
  )
)
```

## Member and Watcher Pagination

Members and watchers use `limit` and `offset` parameters for pagination.

| Parameter | Description                 | Maximum |
| --------- | --------------------------- | ------- |
| `limit`   | Number of records to return | 300     |
| `offset`  | Number of records to skip   | 10000   |

```ruby label="Ruby"
require 'getstream_ruby'
Models = GetStream::Generated::Models

# Paginate members and watchers
result = client.chat.get_or_create_channel('messaging', 'general',
  Models::ChannelGetOrCreateRequest.new(
    members: Models::PaginationParams.new(limit: 20, offset: 0),
    watchers: Models::PaginationParams.new(limit: 20, offset: 0)
  )
)

result = client.chat.get_or_create_channel('messaging', 'general',
  Models::ChannelGetOrCreateRequest.new(
    state: true,
    members: Models::PaginationParams.new(limit: 110, offset: 0)
  )
)
```

<Admonition type="info">

To retrieve filtered and sorted members in a channel use the [Query Members](https://getstream.io/chat/docs/ruby/query-members/) API

</Admonition>


---

This page was last updated at 2026-08-11T17:19:21.566Z.

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/ruby/channel-pagination/](https://getstream.io/chat/docs/ruby/channel-pagination/).