API Pagination: Cursors, Pages and Offsets in Practice
API pagination splits a large result set across several responses, and each response tells you how to ask for the next one. There are three common patterns: offsets (skip N items), page numbers (ask for page 2) and cursors or tokens (send back an opaque string the last response gave you). You can tell which one an endpoint uses from its parameters and response fields. This explainer reads all three in recorded responses from Indeed, Craigslist and Google Play, then builds one loop that stops correctly and costs what you planned.
What are the three kinds of API pagination?
The three kinds differ in what you send to get the next page. With offsets you send how many items to skip, with page numbers you send which page you want, and with cursors or tokens you send back a string the previous response handed you. Offsets and page numbers let you jump to any position; cursors only let you continue from where the last response ended.
| Pattern | You send | The response tells you | In the recordings below |
|---|---|---|---|
| Offset | How many items to skip, often with a limit | Sometimes a total count | None of the three |
| Page number | A page number, sometimes a page size | Current page, page size, total, whether more exist | Craigslist page, per_page, total, has_more |
| Cursor | The cursor from the last response | The next cursor and whether more exist | Indeed next_cursor, has_more |
| Page token | The token from the last response | The next token | Google Play next_page_token |
Offset and page-number schemes share a weakness when the list changes while you read it. If a new item lands at the top between your calls, everything shifts down one place, and the first item of your next page is the one that ended the last. A cursor or token is meant to mark a position in the result set rather than a count, but you can't see from the outside how a given server handles changes. Whatever the pattern, deduplicate by ID.
How does page-number pagination look in a real response?
Page-number pagination puts the bookkeeping in the response: where you are, how big a page is, how many items match and whether more exist. The Craigslist search endpoint returns all four. This is the recorded response for bikes in Portland between 50 and 300, trimmed to the paging fields and the first result:
curl "https://api.perceptlayer.com/v1/craigslist/search?site=portland&category=bia&query=bike&min_price=50&max_price=300" \
-H "X-API-Key: $API_KEY"
{
"success": true,
"data": {
"total": 821,
"page": 1,
"per_page": 360,
"has_more": true,
"results": [
{
"position": 1,
"id": "wnD16b4hEY7DaHprfGYGAg",
"posting_id": 7988730852,
"title": "21\" Specialized Sirrus A1 commuter",
"price": 250,
"currency": "USD",
…
},
…
]
},
…
}
The request sent no page, and the response reports page 1. The endpoint takes a page integer, so the next request is the same call with page=2. No recording shows page 2 yet, so check that it returns different listings before you depend on it. total lets you estimate the pull before you start: 821 ÷ 360 = 2.3, so 3 pages if every page but the last is full. Keep every filter identical across pages, or you are reading two result sets. The Craigslist Search endpoint page lists its parameters.
How do cursor and token pagination look?
Cursor and token pagination hand you an opaque string with each response and expect it back on the next request. You don't build it, read it or change it; you store it and send it. Indeed returns a cursor with a has_more flag next to it. This is the recorded response from GET /v1/indeed/jobs, trimmed:
curl "https://api.perceptlayer.com/v1/indeed/jobs?query=software+engineer&location=Berlin&country=DE&job_type=full_time&limit=20" \
-H "X-API-Key: $API_KEY"
{
"success": true,
"data": {
"jobs": [
{
"id": "61ac648a11df5cc6",
"title": "Product Designer",
"company": { "name": "Telli", … },
"date_published": "2025-07-21 05:00:00",
…
},
…
],
"pagination": {
"next_cursor": "ABQAAYEAFAAAAAAAAAAAAAAAAmYRNdcAMgEBAQcpfSGrk7wi9QBuLZ6BEihQwmDA0xA2nDAGrqtuJIdLnPZKyLE0IcnT2+IETfyRAAA=",
"has_more": true
},
"metadata": {
"total_results": 20,
"timestamp": "2026-10-21T13:25:37.233649Z"
}
}
}
The endpoint takes a cursor parameter, and its name matches pagination.next_cursor, so sending that value back as cursor is the obvious next request. No recording shows a cursor being passed back, so test it in the playground on the Indeed API page first. metadata.total_results is 20, the same as the limit sent, and the recording doesn't show whether it counts the page or every match, so don't size a pull from it.
Google Play's reviews endpoint uses a token and no flag. The recorded response from GET /v1/google-play/product-reviews for product_id=com.spotify.music, num=20, trimmed, with reviewers' names and avatars left out:
{
"search_parameters": { "product_id": "com.spotify.music", "store": "apps", "num": 20, … },
"reviews": [
{
"id": "6b8cd845-6fcd-4296-b05e-9e1b3feada62",
"rating": 1,
"snippet": "Spotify has a new, horrendous feature where the ending to the song that you are listening to gets cut off by the middle of the next song. …",
"date": "September 15, 2026",
…
},
…
],
"pagination": {
"next_page_token": "CrABIqcBAV8d1P3Y4jmqTOdZ4xBJ7QnJyYmH9-QZ8psto-gkJJgGAGdBmyMjzuevISIZC-cPmxGWGPNbx6bIhfWsgxAO49jzTgsGLftwszEwCFE3Fi_vfO00Nsb7-YIFPGW7ebKtcGy5BA2Ma_edk5CuQ5Z0N8VD…"
}
}
The endpoint takes next_page_token, the same name as the response field, and again no recording shows it passed back. Without a has_more flag, the only end signal is the token itself, and no recording shows a last page either. So treat a missing token as the end, and back it up with the guards below. The Google Play Product Reviews page has the parameters.
How do you write a pagination loop that stops correctly?
Write the loop around its exit conditions and keep the pattern-specific part small. A single loop can handle all three endpoints if each one supplies a function that takes the current position and returns the items, the next position and the credits the call used. The loop then stops on the first of six conditions and reports which one, so a partial pull is never mistaken for a full one.
import os
import time
import requests
API = "https://api.perceptlayer.com"
HEADERS = {"X-API-Key": os.environ["API_KEY"]}
def get(path, params):
r = requests.get(f"{API}{path}", params=params, headers=HEADERS, timeout=60)
if r.status_code != 200:
try:
code = r.json().get("error", {}).get("code")
except ValueError:
code = None
raise RuntimeError(f"{r.status_code} {code}")
return r.json(), int(r.headers.get("X-Credits-Used", 0))
def craigslist_page(page):
params = {"site": "portland", "category": "bia", "query": "bike",
"min_price": 50, "max_price": 300, "page": page or 1}
body, cost = get("/v1/craigslist/search", params)
data = body["data"]
nxt = data["page"] + 1 if data.get("has_more") else None
return data.get("results", []), nxt, cost
def indeed_page(cursor):
params = {"query": "software engineer", "location": "Berlin", "country": "DE",
"job_type": "full_time", "limit": 20}
if cursor:
params["cursor"] = cursor
body, cost = get("/v1/indeed/jobs", params)
paging = body["data"].get("pagination", {})
nxt = paging.get("next_cursor") if paging.get("has_more") else None
return body["data"].get("jobs", []), nxt, cost
def play_reviews_page(token):
params = {"product_id": "com.spotify.music", "store": "apps", "num": 20}
if token:
params["next_page_token"] = token
body, cost = get("/v1/google-play/product-reviews", params)
nxt = body.get("pagination", {}).get("next_page_token")
return body.get("reviews", []), nxt, cost
def paginate(fetch_page, max_pages=5, credit_ceiling=5):
seen, spent, position = {}, 0, None
for _ in range(max_pages):
if spent >= credit_ceiling:
return list(seen.values()), spent, "credit ceiling reached"
items, nxt, cost = fetch_page(position)
spent += cost
new = 0
for item in items:
if item["id"] not in seen:
seen[item["id"]] = item
new += 1
if not items:
return list(seen.values()), spent, "empty page"
if new == 0:
return list(seen.values()), spent, "page added no new IDs"
if nxt is None:
return list(seen.values()), spent, "no next page"
if nxt == position:
return list(seen.values()), spent, "next position repeated"
position = nxt
time.sleep(1) # free accounts get 1 request a second
return list(seen.values()), spent, "page cap reached"
for name, fetch in [("craigslist", craigslist_page), ("indeed", indeed_page),
("google play", play_reviews_page)]:
items, spent, reason = paginate(fetch)
print(f"{name}: {len(items)} items, {spent} credits, stopped: {reason}")
All three responses carry an id per item, which is the dedupe key. The "no new IDs" and "next position repeated" checks catch a cursor that isn't being applied: if the endpoint ignored it, you'd get the first page again, and the loop stops after paying for one repeat instead of running to its cap. The loop reads X-Credits-Used rather than assuming 1, so the ceiling holds if a price changes. For retries inside a pull, see Handle Web Data API Errors in Python; for a page loop with retries and a balance check, see Paginate a Web Data API in Python.
What does each extra page cost?
Each page is one call, and each successful call on these endpoints costs 1 credit, so the cost of a pull is its page count. Failed calls cost nothing and return X-Credits-Used: 0. A client timeout is the exception: requests have no idempotency key, so a page whose reply was lost may have been billed, and fetching it again costs another credit.
| Pull | Calculation | Credits |
|---|---|---|
| Craigslist, all 821 bike listings at 360 a page | 821 ÷ 360 = 2.3, so 3 pages × 1 credit | 3 |
| Craigslist, then each listing's posting details | 3 + 821 × 1 credit | 824 |
Indeed, 10 pages at limit=20 |
10 × 1 credit | 10 |
Google Play, 1,000 reviews at num=20 |
1,000 ÷ 20 = 50 pages × 1 credit | 50 |
The rows that divide assume full pages; the recordings show one page each, so the real count may be higher. The second row is the one to notice: paging through search results is cheap, and the detail call per item is where the credits go. Fetch details only for the items you keep. The 100 free credits on signup cover the first, third and fourth rows; the 824-credit detail pull needs a pack. See pricing for what credits cost and the credits docs for how balances work.
When you pull on a schedule, you rarely need every page again. Incremental API Data Pulls covers stopping at the first item you've already stored, which keeps a daily run to a page or two. More pipeline guides are in the data engineering category.
To see the three shapes for yourself, run the Craigslist search, the Indeed jobs call and the Google Play reviews call in the playgrounds on the Craigslist, Indeed and Google Play API pages, then pass the next page value back and compare the IDs.
APIs in this post
Frequently asked questions
Which is better, cursor or offset pagination?
Cursors suit lists that change while you read them, because they mark a position rather than a count. Offsets and page numbers let you jump to page 5 directly and estimate the total pages from a count. As a client you don't choose: you use what the endpoint takes. Deduplicate by ID either way.
How do I know when to stop paginating?
Stop at the first end signal the response gives: has_more false on Craigslist or Indeed, or no next_page_token on Google Play. Back that up with guards that don't trust the server: an empty page, a page with no new IDs, a page cap and a credit ceiling. Return the reason the loop stopped.
Can I fetch pages in parallel?
With page numbers you can, because each request names its page. With cursors and tokens you can't, because each request needs the value from the previous response. Within one pull, cursor paging is sequential; run different queries in parallel instead, within your rate limit, which the rate limit docs explain.
Do cursors expire?
None of these three endpoints documents a cursor or token lifetime, so don't store one for later and expect it to work. Treat a cursor as valid for the pull that produced it. If a resumed pull fails or returns the first page again, start over from the first page and let deduplication drop what you already have.
Does a failed page cost credits?
No. Only a successful response debits credits. A 429, 502 or 503 returns X-Credits-Used: 0, so retrying the same page after the Retry-After seconds costs nothing extra. If your balance runs out mid-pull, the next call returns insufficient_credits (402) and nothing more is debited.