Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add aj-geddes/useful-ai-prompts --skill api-pagination -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/api-pagination/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/api-pagination/

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

Similar skills

Everything for Backend and APIs →

From the same set118

api-reference-documentation A skill that walks the agent through writing API reference docs: endpoints, auth, request and response examples, OpenAPI specs. CX Codex +1 494installs database-performance-debugging A skill that walks your agent through finding slow SQL queries and reading their execution plans. Useful when the app drags or the database burns CPU. CX Codex +1 493installs code-documentation A skill that makes the agent write documentation inside your code: JSDoc, Python docstrings, JavaDoc, inline comments and API notes. Useful when functions and classes need describing, not rewriting. CX Codex +1 492installs reactive-programming A skill for reactive streams in RxJS: observables, operators, backpressure. Useful when a project leans on async data and events. CX Codex +1 491installs nosql-database-design Guides the agent through NoSQL schema work: MongoDB collections, DynamoDB tables, embedding vs referencing, indexes. Useful before the schema hardens in code. CX Codex +1 486installs database-indexing-strategy A skill for planning indexes: picks the type, builds composite and partial ones, covers maintenance. Useful when queries slow down. CX Codex +1 486installs uptime-monitoring A skill that walks your coding agent through uptime checks, a public status page and incident tracking. Useful when you need to know which dependency actually broke. CX Codex +1 484installs api-response-optimization A coding-agent skill that trims payloads, adds caching and compression, and gives you a checklist for slow API endpoints. CX Codex +1 484installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor