Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aj-geddes avatar

Api Pagination

  • 438 installs
  • 305 repo stars
  • Updated March 4, 2026
  • aj-geddes/useful-ai-prompts

api-pagination is an agent skill that implements cursor, offset, and keyset pagination with stable sort keys and next-link metadata for developers building scalable list API endpoints.

About

api-pagination is a Backend & APIs skill from aj-geddes/useful-ai-prompts for implementing scalable pagination on collection endpoints. It documents three strategies—offset/limit, cursor-based, and keyset pagination—with six detailed reference guides covering offset/limit, cursor, keyset, search pagination, response formats, and Python SQLAlchemy implementations. The quick-start example shows a Node.js /api/users route capping limit at 100, returning page, total, totalPages, and hasNext metadata alongside data arrays. Best practices warn against offset pagination on billions of rows, unlimited page sizes, and changing sort order mid-pagination. Developers reach for api-pagination when building search results, infinite scroll backends, or REST list endpoints that must stay performant at scale.

  • Compares offset, cursor, and keyset styles
  • Specifies next/prev link metadata
  • Defines stable sort and filter parameters
  • Prevents duplicate or skipped records

Api Pagination by the numbers

  • 438 all-time installs (skills.sh)
  • Ranked #999 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill api-pagination

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs438
repo stars305
Last updatedMarch 4, 2026
Repositoryaj-geddes/useful-ai-prompts

How do you implement cursor pagination in REST APIs?

Implement cursor, offset, or page-based list endpoints with stable sort keys, next-link metadata, and client-friendly pagination response shapes.

Who is it for?

Backend developers designing list or search endpoints who must choose between offset, cursor, and keyset pagination with consistent response shapes.

Skip if: GraphQL-only APIs using Relay cursors natively or endpoints returning small fixed-size collections that never paginate.

When should I use this skill?

User asks to paginate API responses, implement cursor or offset pagination, or optimize large dataset list queries.

What you get

Paginated API route handlers, response schemas with next-link metadata, and reference implementations for three pagination strategies.

  • paginated route handlers
  • pagination response schemas
  • strategy reference implementations

By the numbers

  • Covers 3 pagination strategies with 6 reference guides
  • Recommends maximum page limit of 100 items per request

Files

SKILL.mdMarkdownGitHub ↗

API Pagination

Table of Contents

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:

// 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:

GuideContents
Offset/Limit PaginationOffset/Limit Pagination
Cursor-Based PaginationCursor-Based Pagination
Keyset PaginationKeyset Pagination
Search PaginationSearch Pagination
Pagination Response FormatsPagination Response Formats
Python Pagination (SQLAlchemy)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

Related skills

How it compares

Use api-pagination when designing REST list endpoints rather than generic database skills that do not specify response metadata or strategy trade-offs.

FAQ

Which pagination strategies does api-pagination cover?

api-pagination covers offset/limit, cursor-based, and keyset pagination. It includes six reference guides with Node.js and SQLAlchemy examples, plus best practices for when to use cursors over offsets on large datasets.

What max page size does api-pagination recommend?

api-pagination recommends capping limit at 100 per request, returning pagination metadata including page, total, totalPages, and hasNext flags, and avoiding unlimited page sizes or full row counts on every request.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.