Skip to main content
skill CX Codex

api-pagination · secondsky — Claude Code skill: what it does, how to install

Implements offset, cursor, and keyset pagination for API endpoints. Useful for handling infinite scroll and optimizing collection queries.

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

What api-pagination does

The skill equips the agent with patterns for three pagination types. Offset and limit fit smaller collections with O(n) lookups. For large datasets and infinite scrolling, the skill applies cursor-based navigation with base64 identifiers or keyset pagination to maintain O(1) complexity.

Responses include a structured pagination payload alongside direct navigation links such as first, prev, next, and last. The instructions forbid unbounded page sizes and suggest capping batch limits at 100 items. Omitting indexes on sorted fields will break query efficiency on high-volume tables.

What it helps with

  • implement cursor pagination for infinite scrolling feeds
  • cap API batch limits to prevent unbounded database queries
  • speed up large collection queries without heavy COUNT operations
  • generate structured API responses with page metadata and navigation links

Example prompts for the agent

  • Create a cursor-based pagination route for posts using base64 tokens
  • Add pagination to the /products endpoint with a strict maximum limit of 100
  • Set up keyset pagination for our orders database query

How to install api-pagination

1Skills CLI (Vercel)

npx skills add secondsky/claude-skills --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 to install api-pagination in Claude Code?

Run npx skills add secondsky/claude-skills --skill api-pagination -a claude-code in your terminal.

What does api-pagination do?

It provides code templates and rules for offset, cursor, and keyset pagination strategies. The skill also enforces response standards with links and metadata.

What performance guidelines does the skill enforce?

It requires capping request limits at a safe threshold like 100 and indexing sorting fields. It also advises against executing full count queries on large tables.

Source text

SKILL.md · MIT
---
name: api-pagination
description: Implements efficient API pagination using offset, cursor, and keyset strategies for large datasets. Use when building paginated endpoints, implementing infinite scroll, or optimizing database queries for collections.
license: MIT
---

# API Pagination

Implement scalable pagination strategies for handling large datasets efficiently.

## Pagination Strategies

| Strategy | Best For | Performance |
|----------|----------|-------------|
| Offset/Limit | Small datasets, simple UI | O(n) |
| Cursor | Infinite scroll, real-time | O(1) |
| Keyset | Large datasets | O(1) |

## Offset Pagination

```javascript
app.get('/products', async (req, res) => {
  const page = parseInt(req.query.page) || 1;
  const limit = Math.min(parseInt(req.query.limit) || 20, 100);
  const offset = (page - 1) * limit;

  const [products, total] = await Promise.all([
    Product.find().skip(offset).limit(limit),
    Product.countDocuments()
  ]);

  res.json({
    data: products,
    pagination: {
      page,
      limit,
      total,
      totalPages: Math.ceil(total / limit)
    }
  });
});
```

## Cursor Pagination

```javascript
app.get('/posts', async (req, res) => {
  const limit = 20;
  const cursor = req.query.cursor;

  const query = cursor
    ? { _id: { $gt: Buffer.from(cursor, 'base64').toString() } }
    : {};

  const posts = await Post.find(query).limit(limit + 1);
  const hasMore = posts.length > limit;
  if (hasMore) posts.pop();

  res.json({
    data: posts,
    nextCursor: hasMore ? Buffer.from(posts[posts.length - 1]._id).toString('base64') : null
  });
});
```

## Response Format

```json
{
  "data": [...],
  "pagination": {
    "page": 2,
    "limit": 20,
    "total": 150,
    "totalPages": 8
  },
  "links": {
    "first": "/api/products?page=1",
    "prev": "/api/products?page=1",
    "next": "/api/products?page=3",
    "last": "/api/products?page=8"
  }
}
```

## Best Practices

- Set reasonable max limits (e.g., 100)
- Use cursor pagination for large datasets
- Index sorting fields
- Avoid COUNT queries when possible
- Never allow unlimited page sizes

© secondsky · MIT · secondsky/claude-skills

Similar skills

All skills for Backend and APIs →

api-pagination by other authors comes first.

From the same set128

app-store-deployment Provides build scripts, checklists, and CI/CD pipelines to publish mobile apps to the iOS App Store and Google Play. Helps automate code signing and release packaging. CX Codex +1 423installs recommendation-engine A skill for building recommendation systems: collaborative filtering, matrix factorization, hybrid approaches. Useful for product recommendations and personalization. CX Codex +1 423installs seo-keyword-cluster-builder Groups search queries into topical clusters, designs pillar-and-hub architectures, and plans bidirectional internal linking. CX Codex +1 422installs api-response-optimization A coding-agent skill that walks through payload trimming, HTTP caching and compression for API endpoints. Useful when responses feel slow. CX Codex +1 422installs api-filtering-sorting A skill that walks your coding agent through building API filtering and sorting: query parsing, validation, and injection safety. CX Codex +1 418installs bun-drizzle-integration A skill that walks your agent through wiring Drizzle ORM to the bun:sqlite driver: schema, migrations, CRUD and transactions. CX Codex +1 420installs drizzle-orm-d1 A skill that gives your agent working knowledge of Drizzle ORM on Cloudflare D1: schemas, typed queries, Drizzle Kit migrations and the usual D1 errors. CX Codex +1 416installs push-notification-setup A skill that walks your agent through push notification setup with Firebase Cloud Messaging and native services. Useful when you add notifications to an app or debug background messages. CX Codex +1 418installs

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