Docs / Pagination
Pagination
/v1/items and /v1/search are keyset paginated: one opaque cursor, followed until it is null. Here is the walk in curl, Python and TypeScript, and the bounds that apply.
Keyset, not page numbers
Follow next_cursor until it is null. There is no total count and no page number. A cursor is opaque: send it back exactly as received.
A cursor walk in three languages
The same loop: request a page, keep its items, repeat with next_cursor until it comes back null. The cursor below is the one in the contract's own example, so the snippets and the documentation cannot drift apart.
# page 1: no cursor
curl -sS "https://vg.tempproject.online/v1/items?limit=2" \
-H "Authorization: Bearer $NEWS_KEY"
# page 2: the next_cursor from page 1
curl -sS "https://vg.tempproject.online/v1/items?limit=2&cursor=eyJwIjoiMjAyNi0xMS0wM1QxODowMDowMC4wMDAwMDBaIiwiaSI6IjExMTExMTExLTExMTEtNTExMS05MTExLTExMTExMTExMTExMSJ9" \
-H "Authorization: Bearer $NEWS_KEY"import json
import os
import urllib.parse
import urllib.request
BASE = "https://vg.tempproject.online"
KEY = os.environ["NEWS_KEY"]
def walk(locale: str) -> list[dict]:
items: list[dict] = []
cursor: str | None = None
while True:
query = {"limit": "200", "locale": locale}
if cursor:
query["cursor"] = cursor
url = BASE + "/v1/items?" + urllib.parse.urlencode(query)
req = urllib.request.Request(url, headers={"Authorization": f"Bearer {KEY}"})
with urllib.request.urlopen(req, timeout=15) as res:
page = json.loads(res.read().decode("utf-8"))
items.extend(page["items"])
cursor = page["next_cursor"]
if not cursor:
return items
if __name__ == "__main__":
print(len(walk("en")), "items")const BASE = "https://vg.tempproject.online";
const KEY = process.env.NEWS_KEY!;
export async function walk(locale: string): Promise {
const items: unknown[] = [];
let cursor: string | null = null;
do {
const url = new URL(`${BASE}/v1/items`);
url.searchParams.set("limit", "200");
url.searchParams.set("locale", locale);
if (cursor) url.searchParams.set("cursor", cursor);
const res = await fetch(url, { headers: { authorization: `Bearer ${KEY}` } });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const page = await res.json();
items.push(...page.items);
cursor = page.next_cursor;
} while (cursor);
return items;
} Both clients in clients/ ship this loop as an iterator (iterateItems / iter_items); the loop above is the same protocol with no dependency.
Cursor rules and bounds
Source: docs/API.md §6.
/v1/items, /v1/search and /v1/feed/{locale} use keyset pagination; the cursor is opaque base64url JSON. /v1/digest/* does not paginate.
| Parameter | Type | Default | Bounds / notes |
|---|---|---|---|
limit (/v1/items) | int | 50 | 1..200; outside is 400 |
limit (/v1/search) | int | 50 | 1..200; a larger value is clamped to 200 (not rejected); < 1 or non-integer is 400 |
cursor | string | none | Opaque base64url JSON. An empty string is treated as absent |
locale | string | none | Well-formed locale tag; not restricted to the policy locales |
category | string | none | One of the categories from /v1/meta, else 400 |
since / until | RFC3339 | none | since > until is 400 |
min_importance (/v1/items) | float | none | 0.0..1.0 |
/v1/items response envelope (measured, limit=2):
{
"items": [ ... ],
"next_cursor": "eyJwIjoiMjAyNi0xMS0wM1QxODowMDowMC4wMDAwMDBaIiwiaSI6IjExMTExMTExLTExMTEtNTExMS05MTExLTExMTExMTExMTExMSJ9",
"count": 2,
"disclaimers": {"en": "...", "zh-Hans": "..."}
}- Follow
next_cursoruntil it isnull; there is no total-count or page-number API. countis the number of items in this page, not a total./?locale=adds adisclaimerstring next todisclaimers, anddisclaimersthen holds only that locale.- A forged or truncated cursor is a clean
400:cursor is not valid base64url JSONorcursor payload must contain string keys 'p' and 'i'. /v1/searchcursors are bound to the exact query: reusing one with a differentq,locale,category,sinceoruntilis400 cursor was issued for a different query, and an index change between pages is400 cursor is stale: the index changed since it was issued; start from the first page./v1/searchechoes its query inquery, so a client can store the cursor plus query as one unit.
One route is paged by NUMBER instead of a cursor: GET /v1/site/topics/{slug} takes page (1-based, page 1 is the clean request) with limit as the page size (default 24, capped at
- and reports
pagination. It is the public subject archive, whose ordering is the store's
own keyset order (published_at newest first, id as the tie-break), so walking page=1,2,… visits every story exactly once. A page past the last one is a 200 with items: [] and out_of_range: true (a document answers 404); page=0 or a non-number is a 400. pagination.total is the measured matched, not a corpus claim — coverage.complete says whether that count is a lower bound of a bounded scan.