Skip to content

Pagination

recon paginate follows a paginated endpoint page by page, collects the records from every page, and works out which pagination style the API uses. It can write what it learned as a fetchkeel TOML manifest. Use it to explore an unfamiliar list endpoint or to bootstrap a data export.

The demo workspace’s offline sandbox has an endpoint that pages with an RFC 5988 Link header. Save a request for it, for example in collections/paged.http:

### Paged Students
# @name Paged Students
# @folder Campus SIS
GET {{base_url}}/v1/students-paged?per_page=2
Authorization: Bearer {{DEV_API_TOKEN}}
X-Client: recon-docs
Terminal window
recon paginate "Paged Students" --airlock --emit-fetchkeel out/fetchkeel.toml
Paginated Explorer: strategy=LinkHeader, pages=3, records=6, retries_429=0, airlock=true
{"email":"lucas.reynolds.3722@example.edu","full_name":"Sophie Holloway","gpa":3.92,"program":"MDiv","student_id":"007218"}
{"email":"micah.bishop.1899@example.edu","full_name":"Naomi Upton","gpa":3.74,"program":"MA","student_id":"004075"}
{"email":"eli.parrish.1773@example.edu","full_name":"Sarah Benson","gpa":3.88,"program":"ThM","student_id":"001242"}
{"email":"ruth.nolan.0370@example.edu","full_name":"Marcus Harlow","gpa":3.65,"program":"MDiv","student_id":"008444"}
{"email":"clara.dalton.6858@example.edu","full_name":"Violet Sutton","gpa":3.97,"program":"PhD","student_id":"009250"}
{"email":"evelyn.yates.6295@example.edu","full_name":"Eli Nolan","gpa":3.81,"program":"MAR","student_id":"006128"}

Human output is one summary line followed by every record as one line of JSON (JSONL). With --airlock, the names and emails are masked by the PII Airlock before they are collected.

--strategy value Aliases Style
auto (default) empty string Detect from each response.
link_header link, link-header Link: <url>; rel="next" response header.
cursor An opaque token in the body, sent back as ?cursor=.
page_number page, page-number ?page=N&per_page=M.
offset_limit offset, offset-limit ?offset=N&limit=M.

Values are case-insensitive. Anything else fails with pagination error: unknown pagination strategy `bogus` (expected auto, link_header, cursor, page_number, or offset_limit).

The query parameter names are fixed in the CLI: page, per_page, cursor, offset and limit.

After each page, Recon decides on the next URL in this order. The first rule that produces a URL wins.

0. Explicit stop. If the body has a boolean has_more, hasMore, pagination.has_more or meta.has_more set to false, pagination stops. This applies to every strategy, including link_header.

1. Link header (auto or link_header). Recon looks at every Link header, splits it on commas, and takes the first part containing rel="next" or rel=next. The URL between < and > is resolved against the current URL, so relative links work. With link_header, no next link means stop.

2. Cursor (auto or cursor). Recon looks for a non-empty string at --cursor-path if given. Otherwise it tries these body paths in order: next_cursor, nextCursor, next_page_token, cursor, meta.next_cursor, pagination.next_cursor. The token is set as the cursor query parameter on the current URL, replacing any existing value. With cursor, no token (or an empty string) means stop.

3. Offset/limit. This rule applies when the strategy is offset_limit, or when the current URL has an offset query parameter, or when the body has a top-level offset key. It applies to auto and also to page_number, so an offset signal takes priority over page numbers.

  • An empty page stops.
  • The page size is the URL’s limit parameter, else a numeric top-level limit in the body, else --per-page.
  • The next offset is the current offset plus the number of records on this page.
  • Recon continues if has_more is true; otherwise, if the body has a numeric top-level total, while the next offset is below total; otherwise, while the page was full (records at least the page size).
  • The next URL sets offset and limit.

4. Page number (auto or page_number).

  • An empty page stops.
  • The page size is the URL’s per_page parameter, else --per-page.
  • If the body has a numeric top-level next_page, Recon continues only if it is greater than the current page, and jumps to it.
  • Else, if the body has a numeric top-level total_pages, Recon continues while the current page is below it.
  • Else, if has_more is true, Recon continues.
  • Else, only with --strategy page_number, Recon continues while the page was full. In auto mode it stops.
  • The next URL sets page and per_page.

The starting page is the page value in the first URL, or 1. The starting offset is the offset value in the first URL, or 0.

With auto, the first rule that produces a next URL fixes the strategy for the rest of the run.

  • --max-pages pages have been fetched. If the strategy is still auto at that point, Recon guesses it from the last page, in this order: a Link next header, a cursor token, an offset (URL or body), then a page URL parameter or a body has_more, next_page or total_pages key.
  • The next URL is one that was already fetched in this run.
  • No rule produced a next URL. If this happens on the first page with auto, the reported strategy stays auto.
  • A 429 response is retried up to 3 times per page. Recon waits for the Retry-After value in whole seconds, clamped to between 5 ms and 2 s. A missing or non-numeric Retry-After waits 5 ms. Every retry adds 1 to retries_429.
  • If a response has an X-Rate-Limit-Remaining header with a value of 1 or less, Recon pauses 50 ms before the next page.
Terminal window
recon paginate http://127.0.0.1:4510/throttle
Paginated Explorer: strategy=Auto, pages=1, records=2, retries_429=1, airlock=false
{"id":1}
{"id":2}

For each page, Recon parses the body as JSON (after Airlock scrubbing when --airlock is set) and picks the records:

  1. If --data-path is given, it must point to a JSON array. A leading $ and . are optional (data, .data and $.data are the same). If it does not resolve to an array, the run fails with data_path `meta` did not resolve to a JSON array.
  2. If the body is an array, that array.
  3. If the body is an object, the first of items, data, results, records or students that holds an array.
  4. Otherwise, any other top-level key that holds an array (the first one Recon finds).
  5. Otherwise, the whole body counts as one record.

The detected path is reported as data_path and reused for later pages.

These runs use a small local test server. Cursor style, where the body has {"data": [...], "meta": {"next_cursor": "c3"}} and the last page has an empty next_cursor:

Terminal window
recon paginate http://127.0.0.1:4510/cursor
Paginated Explorer: strategy=Cursor, pages=3, records=7, retries_429=0, airlock=false
{"id":1,"name":"item-1"}
{"id":2,"name":"item-2"}
...
{"id":7,"name":"item-7"}

Offset style, where the body has results, offset, limit and total:

Terminal window
recon paginate 'http://127.0.0.1:4510/offset?offset=0&limit=3'
Paginated Explorer: strategy=OffsetLimit, pages=3, records=7, retries_429=0, airlock=false
{"id":1,"name":"item-1"}
...

Page-number style, where the body has items and has_more:

Terminal window
recon paginate 'http://127.0.0.1:4510/pages?page=1&per_page=3'
Paginated Explorer: strategy=PageNumber, pages=3, records=7, retries_429=0, airlock=false
{"id":1,"name":"item-1"}
...
Terminal window
recon paginate http://127.0.0.1:4510/cursor --max-pages 2 --per-page 3 --format json
{
"detected_strategy": "cursor",
"pages_fetched": 2,
"records_total": 6,
"retries_429": 0,
"data_path": "data",
"cursor_path": "meta.next_cursor",
"records_jsonl": "{\"id\":1,\"name\":\"item-1\"}\n{\"id\":2,\"name\":\"item-2\"}\n{\"id\":3,\"name\":\"item-3\"}\n{\"id\":4,\"name\":\"item-4\"}\n{\"id\":5,\"name\":\"item-5\"}\n{\"id\":6,\"name\":\"item-6\"}",
"records": [
{
"id": 1,
"name": "item-1"
},
...
],
"fetchkeel_manifest_toml": "# Generated by Recon Pagination Explorer (secret-free fetchkeel manifest)\n[source]\nname = \"get_http_127_0_0_1_4510_cursor\"\n...",
"airlocked": false
}
Field Meaning
detected_strategy auto, link_header, cursor, page_number or offset_limit. Human output prints the same value as Auto, LinkHeader, Cursor, PageNumber or OffsetLimit.
pages_fetched Pages fetched successfully.
records_total Number of records collected.
retries_429 429 retries across all pages.
data_path Path of the records array, or null for a root array.
cursor_path Path of the cursor token, or null.
records_jsonl All records, one JSON object per line.
records All records as an array.
fetchkeel_manifest_toml The generated manifest text.
airlocked true if --airlock was set.

Pagination runs are not written to the Flight Recorder.

Every run generates a TOML manifest in the format read by fetchkeel. --emit-fetchkeel <FILE> writes it to a file (parent directories are created). It is only written when the run succeeds. The manifest from the quick start:

# Generated by Recon Pagination Explorer (secret-free fetchkeel manifest)
[source]
name = "paged_students"
base_url_env = "PAGED_STUDENTS_BASE_URL"
auth = "bearer"
auth_env = "DEV_API_TOKEN"
timeout_secs = 15
max_retries = 4
base_backoff_ms = 250
rate_limit_min_remaining = 5.0
rate_limit_delay_ms = 500
[source.headers]
X-Client = "recon-docs"
[[streams]]
name = "paged_students_items"
path = "/_sandbox/local/v1/students-paged"
data_path = "students"
pagination = "link_header"
page_param = "page"
per_page_param = "per_page"
per_page = 25
cursor_param = "cursor"
offset_param = "offset"
limit_param = "limit"
output = "data/paged_students.jsonl"
[streams.params]
per_page = "2"
Key Value
name The request name, lowercased, with each run of non-alphanumeric characters turned into _ and leading or trailing _ removed. recon_api if nothing is left. For a raw URL target the name is GET <url>, so the slug looks like get_http_127_0_0_1_4510_cursor. Called the slug below.
base_url_env <SLUG>_BASE_URL in uppercase. The base URL itself is never written.
auth none, bearer, header or query. See the table below.
auth_env Name of the environment variable that should hold the credential.
auth_header Header name, for header-based auth.
auth_prefix Basic for Basic auth.
auth_query_param Query parameter name, for query-based API keys.
headers The request’s enabled headers, except Authorization, Proxy-Authorization, Cookie, X-Api-Key, the auth header, and any header whose value contains a {{ template.
timeout_secs The request timeout rounded up to whole seconds, at least 5.
max_retries, base_backoff_ms, rate_limit_min_remaining, rate_limit_delay_ms Fixed: 4, 250, 5.0, 500.

Auth mapping, based on the request’s auth configuration:

Request auth auth auth_env Other keys
Bearer token bearer template variable in the token, else <SLUG>_API_TOKEN
API key in a header header template variable in the value, else <SLUG>_API_KEY auth_header = key name
API key in the query query template variable in the value, else <SLUG>_API_KEY auth_query_param = key name
Basic header <SLUG>_AUTH_TOKEN auth_header = "Authorization", auth_prefix = "Basic "
OAuth 2.0 bearer <SLUG>_OAUTH_TOKEN
AWS SigV4 header <SLUG>_AWS_SIGV4 auth_header = "Authorization"
HMAC header <SLUG>_HMAC_KEY auth_header = the HMAC header name
None, with an Authorization: Bearer ... header bearer template variable in the header, else <SLUG>_API_TOKEN
None, with another Authorization header header same as above auth_header = "Authorization"
None, with an X-Api-Key header header template variable in the header, else <SLUG>_API_KEY auth_header = header name
None none

“Template variable” means the first {{name}} in the value, uppercased, with non-alphanumeric characters replaced by _. In the quick start, Bearer {{DEV_API_TOKEN}} became auth_env = "DEV_API_TOKEN".

One stream is written.

Key Value
name <slug>_items.
path Path of the first page URL.
params Query parameters of the first page URL, except api_key, token, access_token, secret and the auth query parameter.
data_path Detected or given records path. Omitted for a root array.
pagination link_header, cursor, page_number, offset, or none when the strategy stayed auto.
page_param, per_page_param, cursor_param, offset_param, limit_param page, per_page, cursor, offset, limit.
per_page --per-page (at least 1). This is not the page size seen in the URL; in the quick start the URL used per_page=2 (kept under params) while the stream says 25.
cursor_path Detected or given cursor path. Omitted when there is none.
output data/<slug>.jsonl.
Flag Default Description
<TARGET> required Saved request ID or name, or a raw http(s) URL (sent as GET).
--env <NAME> workspace default_env Environment for template variables.
--strategy <S> auto See Strategies.
--max-pages <N> 5 Maximum pages to fetch. Must be at least 1.
--per-page <N> 25 Page size used when the URL and body give none, and written to the manifest.
--data-path <PATH> none Path to the records array.
--cursor-path <PATH> none Path to the cursor token.
--airlock off Scrub each page through the PII Airlock before reading records.
--emit-fetchkeel <FILE> none Write the manifest to this file.

Global transport flags apply, and the cookie jar is saved after the run. Each page request goes through the Outbound Secret Firewall.

Exit code Cause
0 Run finished.
1 E_FIREWALL_BLOCKED: a page request was blocked by the firewall.
2 E_NOT_FOUND: the target is not a saved request or URL.
2 E_CLI_RUNTIME: any other error, listed below.

E_CLI_RUNTIME messages:

Message Cause
pagination error: max_pages must be >= 1 --max-pages 0.
pagination error: unknown pagination strategy ... Bad --strategy.
pagination error: upstream returned HTTP 500 on page URL `http://127.0.0.1:4510/broken` A page returned 400 or above (after 429 retries). Records from earlier pages are not printed.
pagination error: page N body is not valid JSON: ... A page body is not JSON.
pagination error: data_path `...` did not resolve to a JSON array --data-path points at something that is not an array.
  • Web Studio: the Paginate tab in the response inspector runs the selected request against the active environment. It has a strategy selector, Max Pages (default 5), Per Page (default 25), and a Zero-PII Airlock checkbox that is on by default. Results show the strategy, page and record counts, 429 retries, a fetchkeel.toml view with copy and download buttons (the download is named fetchkeel.toml), and the JSONL rows. See Web Studio.
  • HTTP API: POST /api/v1/paginate/run with body {request, env?, config?}. config accepts strategy, max_pages, per_page, data_path, cursor_path, airlock, and also the parameter names page_param, per_page_param, cursor_param, offset_param and limit_param, which the CLI does not expose. See HTTP API.
  • MCP: recon_paginate takes request or url, env, strategy, max_pages (clamped to 1..=20), per_page (clamped to 1..=100), data_path and cursor_path. The Airlock is always on, and every page URL is checked against the agent policy. See MCP Tools.