api-pagination — Claude Code skill: paginate large API results
A skill that tells the agent how to page through big collections: offset/limit, cursors, keyset. Useful when a user list or search result set outgrows one response.
npx skills add aj-geddes/useful-ai-prompts --skill api-pagination -a claude-codeWhat api-pagination does
The skill covers three pagination approaches, each in its own guide under references/. There are files for offset/limit, cursor-based and keyset pagination, plus separate ones for search and response formats. Python projects get a SQLAlchemy version. The agent picks the guide that matches your stack and writes the code.
SKILL.md opens with a Node.js example: page and limit come from query params, the limit is capped at 100, and the response carries data plus a pagination block with the total count and a next-page flag. Then come the do and don't lists — sort on indexed fields, don't allow unlimited page sizes, don't count rows on every request.
One rule stands out: don't mix strategies inside a single API. Switch from offset to cursors halfway through a list and the client loses its place. Worth settling on one approach before the first list endpoint ships.
What it helps with
- return a user list page by page
- build infinite scroll in the UI
- speed up queries against a table with millions of rows
- add paging to search results
- pick between offset and cursors for a new API
Example prompts for the agent
- add pagination to the /api/users endpoint, limit 20
- rewrite this list using keyset pagination
- show me the cursor response format for search
How to install api-pagination
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill api-pagination -a claude-code2Manually: put the files in place
~/.claude/skills/api-pagination/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/api-pagination/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill api-pagination -a codex2Manually: put the files in place
.agents/skills/api-pagination/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill api-pagination -a cursor2Manually: put the files in place
.cursor/skills/api-pagination/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install aj-geddes/useful-ai-prompts api-pagination2Manually: put the files in place
.github/skills/api-pagination/SKILL.md1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill api-pagination -a gemini-cli2Platform CLI
gemini skills install https://github.com/aj-geddes/useful-ai-prompts --path skills/api-paginationManually: put the files in place
.devin/skills/api-pagination/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill api-pagination -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about api-pagination
How do I install api-pagination in Claude?
Run npx skills add aj-geddes/useful-ai-prompts --skill api-pagination -a claude-code. The skill lands in ~/.claude/skills/api-pagination/SKILL.md.
What does api-pagination do?
It gives the agent ready-made pagination patterns: offset/limit, cursor-based and keyset. Six reference guides hold code samples and a list of common mistakes.
How is keyset different from offset?
Keyset walks an indexed column and never recounts skipped rows, so deep pages stay fast. Offset gets more expensive with every page on a large table.
Source text
SKILL.md · MIT
---
name: api-pagination
description: >
Implement efficient pagination strategies for large datasets using
offset/limit, cursor-based, and keyset pagination. Use when returning
collections, managing large result sets, or optimizing query performance.
---
# API Pagination
## Table of Contents
- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)
## Overview
Implement scalable pagination strategies for handling large datasets with efficient querying, navigation, and performance optimization.
## When to Use
- Returning large collections of resources
- Implementing search results pagination
- Building infinite scroll interfaces
- Optimizing large dataset queries
- Managing memory in client applications
- Improving API response times
## Quick Start
Minimal working example:
```javascript
// Node.js offset/limit implementation
app.get('/api/users', async (req, res) => {
const page = parseInt(req.query.page) || 1;
const limit = Math.min(parseInt(req.query.limit) || 20, 100); // Max 100
const offset = (page - 1) * limit;
try {
const [users, total] = await Promise.all([
User.find()
.skip(offset)
.limit(limit)
.select('id email firstName lastName createdAt'),
User.countDocuments()
]);
const totalPages = Math.ceil(total / limit);
res.json({
data: users,
pagination: {
page,
limit,
total,
totalPages,
hasNext: page < totalPages,
// ... (see reference guides for full implementation)
```
## Reference Guides
Detailed implementations in the `references/` directory:
| Guide | Contents |
|---|---|
| [Offset/Limit Pagination](references/offsetlimit-pagination.md) | Offset/Limit Pagination |
| [Cursor-Based Pagination](references/cursor-based-pagination.md) | Cursor-Based Pagination |
| [Keyset Pagination](references/keyset-pagination.md) | Keyset Pagination |
| [Search Pagination](references/search-pagination.md) | Search Pagination |
| [Pagination Response Formats](references/pagination-response-formats.md) | Pagination Response Formats |
| [Python Pagination (SQLAlchemy)](references/python-pagination-sqlalchemy.md) | Python Pagination (SQLAlchemy) |
## Best Practices
### ✅ DO
- Use cursor pagination for large datasets
- Set reasonable maximum limits (e.g., 100)
- Include total count when feasible
- Provide navigation links
- Document pagination strategy
- Use indexed fields for sorting
- Cache pagination results when appropriate
- Handle edge cases (empty results)
- Implement consistent pagination formats
- Use keyset for extremely large datasets
### ❌ DON'T
- Use offset with billions of rows
- Allow unlimited page sizes
- Count rows for every request
- Paginate without sorting
- Change sort order mid-pagination
- Use deep pagination without cursor
- Skip pagination for large datasets
- Expose database pagination directly
- Mix pagination strategies
- Ignore performance implications
© aj-geddes · MIT · aj-geddes/useful-ai-prompts