How API Pagination Works: Offset, Limit, and Pages

Quick summary: Public dataset APIs return records in bounded slices rather than dumping tens of thousands of rows in one HTTP response. Two parameters control each slice: offset (how many records to skip from the start) and limit (the maximum number of records to return in that page).
Editorial note: Data Khoj is an independent platform that indexes live metadata from data.gov.in. It is not affiliated with or endorsed by the Government of India.
Illustrative diagram showing Page 1 (offset=0, limit=20), Page 2 (offset=20, limit=20), and Page 3 (offset=40, limit=20)
Figure 1: Illustrative example of how offset and limit advance across consecutive pages with a page size of 20.

Core Pagination Parameters

To move from page N to page N + 1, add limit to the current offset. Data Khoj enforces a configurable maximum page size (default 100) to keep responses fast and respect upstream limits.

Page 1 (illustrative): ?offset=0&limit=20   -> rows 1 to 20
Page 2 (illustrative): ?offset=20&limit=20  -> rows 21 to 40
Page 3 (illustrative): ?offset=40&limit=20  -> rows 41 to 60

Why Unbounded Loops Are Dangerous

When a resource contains tens of thousands of rows, firing an unbounded sequence of rapid API calls can trigger rate limits (HTTP 429) or upstream timeouts (HTTP 504). Use reasonable page sizes, apply filters before paginating, and rely on bounded server-side caching when aggregating.

Illustrative table comparing pagination behavior when total is provided versus when total is null
Figure 2: Illustrative comparison of how pagination determines whether a next page exists when upstream total is present or null.

What Happens When total Is Unavailable?

Occasionally, an upstream data.gov.in resource omits or returns a non-numeric total value. In that situation, Data Khoj displays "Unavailable from upstream" rather than guessing. You can still page forward reliably: if a page returns fewer records than limit (or zero records), you have reached the end of the dataset.