Skip to content
Back to skills

Api Pagination Design

ASecurity

Picks cursor or offset pagination for a list endpoint, then implements stable ordering, hard limits and next links that never skip or repeat rows.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 15, 2026
ai-agentsapidatabase

Works with

  • cursor
  • cli
  • api

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill api-pagination-design --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Api Pagination Design?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Api Pagination Design
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-api-pagination-design/badge)](https://www.skillsdirectory.com/skills/workspace-templates-api-pagination-design)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: api-pagination-design
description: Picks cursor or offset pagination for a list endpoint, then implements stable ordering, hard limits and next links that never skip or repeat rows.
---

# API pagination design

Choose with evidence, then make paging deterministic.

## Steps

1. Read the endpoint, the table and its indexes. Note the expected size, whether rows are inserted while clients page, and whether users need to jump to page N.
2. Choose. Use cursor (keyset) pagination for feeds, logs and anything large or changing. Use offset only for small, stable lists where a page number is a real feature, and cap the maximum offset.
3. Make the order total. Sort by a column plus a unique tiebreaker, for example `ORDER BY created_at DESC, id DESC`. Without the tiebreaker, equal timestamps cause skipped rows.
4. For keyset, filter with a row comparison: `WHERE (created_at, id) < (:c, :i)`. Fetch `limit + 1` rows to learn whether a next page exists.
5. Encode the cursor as opaque base64 of the sort values. Never let clients build it.
6. Add a composite index that matches the sort and filters. Run `EXPLAIN` and show that it avoids a sort step.
7. Enforce a default and a maximum limit (for example 25 and 100). Reject larger values with a 400.
8. Return `items`, `next` (a URL or null) and, when cheap, no total. Counting millions of rows on every request is a bug.

## Rules

- Never paginate without a deterministic order.
- Never expose raw database ids or timestamps in the cursor contract.
- Tests must insert a row between page 1 and page 2 and assert no duplicates and no gaps.

## Report

The choice and why, the index added, the query plan before and after, and the response shape.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.