Skip to content
Back to skills

Pagination

ASecurity

How list endpoints page through results. Read before adding a list endpoint or a limit parameter.

  • 8,227 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 28, 2026
ai-agentsgoapi

Works with

  • cursor
  • cli
  • api

Security analysis

A100/100

Scanned November 28, 2026

npx -y skills add GetStream/Vision-Agents --skill pagination --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pagination?

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

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

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: pagination
description: How list endpoints page through results. Read before adding a list endpoint or a limit parameter.
---

# Pagination

Never use limit/offset. Lists take `limit` + `cursor`.

- Offset is slow: Postgres reads and discards every skipped row. A cursor is an indexed `WHERE`.
- Offset is wrong when data changes: an insert repeats a row on the next page, a delete skips one.

## Rules

- Response is `{items, has_more, next_cursor}`, like `SessionPage`. Never a bare array.
- Cursors are opaque base64url. Clients never build or parse them.
- Sort ends with `id` so the order is total. The cursor holds every sort key.
- Fetch `limit + 1` to set `has_more`. No counts.
- Filters are resent with every page; the cursor holds a position. It may also record the filters it was handed out for, and is then refused under others (a 400).
- A bad cursor is a 400.
- Index the sort keys behind the filter, e.g. `(customer_id, updated_at DESC, id DESC)`.
- A list that filters and sorts takes a body instead of query parameters: see the `query` skill.

## Example: querySessions

Spec: `SessionQuery` carries `limit` and `cursor` in the body, and `SessionPage` is the 200.

Position, in `internal/store/models.go`:

```go
type SessionPosition struct {
	UpdatedAt time.Time `json:"u"`
	ID        string    `json:"id"`
	Rank      float32   `json:"r,omitempty"`
}
```

Store, in `Sessions.Select`:

```go
if after := filter.Cursor; after != nil {
	query = query.Where("(updated_at, id) < (?, ?)", after.UpdatedAt, after.ID)
}
query = query.Limit(SessionLimit(filter.Limit) + 1)
```

Handler: `decodeCursor` and `encodeCursor` in `internal/api/cursor.go`; `page` trims the
extra row and says whether it was there. The session cursor also records which sort it
came from, so a cursor from one sort is refused by another.

Live sessions that nothing records get the same cut and sort in `Manager.find`, on their
`created`, which is truncated to microseconds (what Postgres keeps) so that a cursor from
one half does not repeat the other. A recorded live session is listed through its row.

A text search sorts by relevance, and its cursor adds the rank:
`(rank, updated_at, id) < (?, ?, ?)`.

Go SDK: list methods return the page and take a cursor; `Items.Unwind` follows it.

## Lists without a cursor yet

`listCalls`, `listSimulationRuns` and `getCallEvents` take a `limit` and no way to continue.
`listSimulationRuns` refuses a limit over 500, and `getCallEvents` one over the 10,000 decisions
a call keeps. `listCalls` answers 500 at most.

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.