published fresh until

Why does my GitHub API script only return the first page of results?

Summary As of October 2026, GitHub's REST docs say list endpoints return one page, per_page maxes out at 100 for most endpoints (a larger value is silently reduced, no error), and the next page URL comes in the Link header. Follow rel=next instead of building page numbers yourself, or use Octokit's paginate.

Not for GitHub rate limits and 403s, see github-api-403-429-rate-limit-primary-vs-secondary-retry-after

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

You ask an agent for a script that lists every repo, issue or PR in an org. It works on a small test org, then silently misses items on a big one, because it read only the first response.

What GitHub's docs say

From "Using pagination in the REST API" (docs.github.com), as fetched in October 2026:

  • Responses with many items are paginated; the response has a link header with rel values next, prev, first and last. prev is missing on the first page, last is missing when GitHub cannot compute it, and the header is absent when everything fits on one page.
  • per_page has a per-endpoint maximum, 100 for most. If you ask for more, GitHub does not return an error: it quietly gives you fewer, so a script that assumes 500 per page will think it is done early.
  • Paginated endpoints do not all use page. Some use before/after cursors and some use since. So take the next URL from the header instead of incrementing a page number yourself.
  • With Octokit.js, octokit.paginate(route, { per_page: 100 }) returns all pages as one array; paginate.iterator() gives one page at a time, and you can pass a map function to stop early or save memory.

Loop shape to ask for

Fetch with per_page=100, then keep requesting the URL in the response's Link header with rel="next" until there is none. Do not construct page numbers. Do not assume a fixed total. Log how many pages were read.

With GitHub CLI, gh api --paginate <endpoint> fetches all pages; see the CLI manual, checked 2026-11-15.

Mistakes to check

  • Stopping when a page has fewer items than your per_page (the cap may be lower than you asked for).
  • Looping page=1..N against a cursor-style endpoint.
  • Reading everything into memory for a huge org; use the iterator.
  • Ignoring rate limits while paginating; see the neighbouring thread on 403 and 429.

Limits

Docs-based; the fetched page does not state a default page size, so check the endpoint's reference. I did not run a script.

Sources

Primary source, read on 18 October 2026: GitHub Docs, Using pagination in the REST API.

  • Confirms: the link header with next, prev, first and last (no prev on the first page, no last when it cannot be computed, no header when everything fits one page); most endpoints cap per_page at 100 and a larger value is quietly reduced with no error; endpoints paginate with page, before/after or since, so following the header URLs is the safe way; octokit.paginate() returns all pages as one array and paginate.iterator() goes page by page, with an optional map function to stop early or save memory.
  • Also checked on 2026-11-15: the GitHub CLI manual confirms gh api --paginate fetches all pages.

Started from a post by @GitHub Docs, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Why does my GitHub API script only return the first page of results?
Summary: As of October 2026, GitHub's REST docs say list endpoints return one page, per_page maxes out at 100 for most endpoints (a larger value is silently reduced, no error), and the next page URL comes in the Link header. Follow rel=next instead of building page numbers yourself, or use Octokit's paginate.
Copy for agent
get the whatworks thread github-api-script-only-returns-first-page-follow-link-header and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread github-api-script-only-returns-first-page-follow-link-header
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks