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

# Pagination

> How cursor-based pagination works for search, timelines, followers and other list endpoints.

List endpoints return one page at a time, with two fields:

| Field | Meaning |
| - | - |
| `has_next_page` | `true` if there are more results. |
| `next_cursor` | Pass this as the `cursor` parameter to get the next page. |

Leave `cursor` empty (or omit it) for the first page. Stop when `has_next_page` is `false`, `next_cursor` is empty, or `next_cursor` is the same as the `cursor` you just sent (a page that returns nothing new).

```python Python theme={null}
import requests

def search_all(query, key, max_pages=10):
    url = "https://api.twitterapi.io/twitter/tweet/advanced_search"
    cursor, tweets = "", []
    for _ in range(max_pages):
        r = requests.get(url, headers={"x-api-key": key},
                         params={"query": query, "queryType": "Latest", "cursor": cursor}, timeout=30)
        r.raise_for_status()
        data = r.json()
        tweets += data.get("tweets", [])
        nxt = data.get("next_cursor")
        if not data.get("has_next_page") or not nxt or nxt == cursor:
            break
        cursor = nxt
    return tweets
```

```javascript Node.js theme={null}
async function searchAll(query, key, maxPages = 10) {
  const url = "https://api.twitterapi.io/twitter/tweet/advanced_search";
  let cursor = "", tweets = [];
  for (let i = 0; i < maxPages; i++) {
    const qs = new URLSearchParams({ query, queryType: "Latest", cursor });
    const data = await (await fetch(`${url}?${qs}`, { headers: { "x-api-key": key } })).json();
    tweets.push(...(data.tweets || []));
    if (!data.has_next_page || !data.next_cursor || data.next_cursor === cursor) break;
    cursor = data.next_cursor;
  }
  return tweets;
}
```

## Notes

* Each page is billed as its own request. See [Pricing](https://docs.twitterapi.io/pricing.md).
* Page sizes differ by endpoint: search and timelines return up to 20 tweets; followers / followings up to 200 users; follower IDs up to 5,000 IDs.
* Set a `max_pages` limit in your code so a bug can't page forever.
* On some endpoints X can report more results when there are none; you then get an empty page, often with the same cursor back. The stop rule above handles this.
* For "new tweets since last time", searching with a time window (for example `since_time:` / `until_time:` in the query) is usually cheaper than paging deep.


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