# Pagination

> Cursors, page size and ordering.

List endpoints return a page and, when there is more, a `next_cursor`. Pass it back as `cursor` to get the next page.

```bash
curl "https://api.tikdataapi.com/v1/users/tiktok/videos?count=16" -H "x-api-key: $KEY"
# ... "next_cursor": "MTczMjk4NjEz..."
curl "https://api.tikdataapi.com/v1/users/tiktok/videos?count=16&cursor=MTczMjk4NjEz..." -H "x-api-key: $KEY"
```

| Endpoint | `count` default | `count` maximum | Order |
|---|---|---|---|
| `/v1/users/{user}/videos` | 16 | 50 | pinned videos first, then newest first |
| `/v1/videos/{id}/comments` | 20 | 50 | the order of TikTok: pinned first, then the most relevant |
| `/v1/videos/{id}/comments/{comment_id}/replies` | 20 | 50 | oldest first |
| `/v1/hashtags/{name}/videos` | 30 | 50 | the order of the hashtag page on TikTok: popular, not newest first |
| `/v1/search/videos` | 12 | 50 | the order of the general search of TikTok |
| `/v1/search/users` | 10 | 50 | the order of the account search of TikTok |
| `/v1/search/music` | 12 | 50 | the order of the sound search of TikTok |
| `/v1/search/live` | 12 | 50 | the order of the live search of TikTok |
| `/v1/users/{user}/followers` | 30 | 50 | newest first, as TikTok gives them |
| `/v1/users/{user}/following` | 30 | 50 | newest first, as TikTok gives them |
| `/v1/users/{user}/reposts` | 16 | 50 | the order of TikTok |
| `/v1/users/{user}/playlists` | 20 | 50 | the order of TikTok |
| `/v1/playlists/{id}/videos` | 30 | 50 | the order of the playlist |
| `/v1/music/{id}/videos` | 30 | 50 | the order of TikTok |
| `/v1/videos/{id}/related` | 16 | 16 | the order of TikTok; one page, no `next_cursor` |
| `/v1/trending/videos` | 16 | 50 | the explore feed of TikTok; no pages, no `next_cursor` |
| `/v1/search/hashtags` | 10 | 30 | most used first in the videos of the general search; no pages, no `next_cursor` |

- Cursors are opaque strings. Do not parse them or store them for longer than a session.
- A page without `next_cursor` is the last one.
- You are charged for the items you receive.
- TikTok decides how many items one of its pages holds: about 30 videos of an account,
  20 comments or replies, 30 videos of a hashtag, 12 videos of a video search, about 10 accounts of an account
  search (one page in our tests had 30), 30 accounts of a follower or following list, 12 sounds of a sound search
  and up to 12 rooms of a live search. The default `count`
  is one TikTok page, and for account search one call with the default `count` is one read of TikTok. The videos
  of an account are the exception: their default `count` of 16 is about half a TikTok page, so the next page comes
  mostly from cache at half price.
- A larger `count` fills the page from more TikTok pages in the same call, so the call takes longer. One
  call reads TikTok at most 6 times, and starts no new read after 8 seconds. A page can therefore hold fewer
  than `count` items while the list goes on. `next_cursor` then continues with no gap.
- A smaller `count` cuts a TikTok page. `next_cursor` then continues from the cut with no gap, and the rest of
  that TikTok page comes from cache at half price. Pass cursors back as they are.
- The video list of a private account is empty, and so are its reposts and playlists. The comment list of a
  video with comments turned off is empty too. All are free.
- Three lists have no pages. `/v1/videos/{id}/related` is one TikTok page of up to 16 videos. `/v1/trending/videos`
  is the explore feed of TikTok for a logged-out visitor: each read of TikTok gives a new set of about 16 videos,
  and a larger `count` reads more sets in the same call and drops repeated videos. `/v1/search/hashtags` ranks the
  hashtags of about 24 videos of the general search, up to 30. None of them takes a `cursor`.
- `POST /v1/users/videos/batch` gives the first page of up to 20 accounts at once, 1 to 16 videos for each.
  The `next_cursor` of an entry continues that list on `/v1/users/{user}/videos`. See
  [Batch reads](/docs/batch).
