Pagination logo

Pagination

Organization
api-platform
pagination

Configures collection pagination in API Platform — page-based (default), items-per-page, client-controlled page size, maximum items, disabling, partial pagination, and cursor-based pagination. Use whenever the user mentions pagination, page size, itemsPerPage, paginating a collection, "too many results", slow COUNT queries on large tables, infinite scroll, cursor pagination, or returning a Paginator from a custom provider — even if they don't say "pagination" explicitly.

Overview

Publisherapi-platform
Repositoryskillset
Skill namepagination
Stars
29
Forks
1
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by api-platform on GitHub. Read the source before you install it.

Installation

Install the Pagination AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/api-platform/skillset/tree/main/skills/pagination
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/api-platform/skillset.git /tmp/skillset
mkdir -p .claude/skills
cp -r /tmp/skillset/skills/pagination .claude/skills/pagination
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Pagination in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Pagination on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Pagination is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Pagination

Pagination is enabled by default on every collection, 30 items per page, page number in the page query parameter. The Hydra response carries a PartialCollectionView with first/last/next/previous links and totalItems. Most tuning is done with pagination* attributes on #[ApiResource] or a single operation — operation-level wins over resource-level wins over global config.

Items per page

php
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;

#[ApiResource(paginationItemsPerPage: 20)]            // resource default
#[GetCollection(paginationItemsPerPage: 100)]         // override one operation
class Book {}

Global default:

yaml
# config/packages/api_platform.yaml
api_platform:
    defaults:
        pagination_items_per_page: 30

Letting the client choose the page size

Off by default (a client could otherwise ask for a million rows). Opt in, then cap it with paginationMaximumItemsPerPage so the client can't DoS the database:

php
#[ApiResource(
    paginationClientItemsPerPage: true,
    paginationMaximumItemsPerPage: 100,
)]
class Book {}

GET /books?itemsPerPage=50 now works (clamped to 100). The parameter name is itemsPerPage by default; change it under collection.pagination.items_per_page_parameter_name.

Letting the client toggle pagination on/off

php
#[ApiResource(paginationClientEnabled: true)]
class Book {}

GET /books?pagination=false returns the full collection. The value goes through PHP's FILTER_VALIDATE_BOOLEAN, so false/0/no all disable it.

Disabling pagination

Per resource or per operation:

php
#[ApiResource(paginationEnabled: false)]
#[GetCollection(paginationEnabled: false)]
class Book {}

Globally under defaults.pagination_enabled: false. Only do this for collections you know stay small — an unbounded collection is an availability risk.

Partial pagination

Default pagination issues a COUNT query to compute totalItems and the last page. On huge tables that COUNT dominates the request. Partial pagination skips it: you lose totalItems and last, but keep a next link (computed by fetching one extra row). This is the right mode for "infinite scroll" UIs that only need "is there more?".

php
#[ApiResource(paginationPartial: true)]
#[GetCollection(paginationPartial: true)]
class Book {}

Client-controlled variant: paginationClientPartial: true enables GET /books?partial=true.

Cursor-based pagination

Page-based pagination drifts when rows are inserted/deleted between requests (an item can appear twice or be skipped). Cursor-based pagination anchors on a unique, ordered field instead. It requires partial pagination plus a RangeFilter and an OrderFilter on the cursor field:

php
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;

#[ApiResource(
    paginationPartial: true,
    paginationViaCursor: [
        ['field' => 'id', 'direction' => 'DESC'],
    ],
)]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(OrderFilter::class, properties: ['id' => 'DESC'])]
class Book {}

The response's view then contains cursor links (id[lt]=…) instead of page=N. Use the ODM filter namespace (ApiPlatform\Doctrine\Odm\Filter\…) for MongoDB.

Doctrine ORM paginator tuning

The ORM PaginationExtension inspects the QueryBuilder to decide two Doctrine Paginator settings. Override the guesses when the query is unusual:

  • paginationFetchJoinCollection — set true when the query joins a collection-valued association (Doctrine then runs an extra query to count distinct roots correctly). API Platform usually detects this; force it when a to-many join produces a wrong totalItems.
  • paginationUseOutputWalkers — output walkers are required for some queries (e.g. HAVING); they cost performance. Set false to disable when you know the query is simple, true when a complex query throws.
php
#[ApiResource(paginationFetchJoinCollection: false)]
#[GetCollection(name: 'with_join', paginationFetchJoinCollection: true)]
class Book {}

Pagination in custom state providers

The Doctrine/Eloquent providers paginate for you. A custom provider (see state-provider) must return a paginator itself, or the collection comes back unpaginated with no Hydra view. Return one of:

  • ApiPlatform\State\Pagination\ArrayPaginator — you already have all results in memory and want a page sliced out.
  • ApiPlatform\State\Pagination\TraversablePaginator — you fetched exactly the current page (e.g. an external API that paginates server-side) and know the totals.

ArrayPaginator takes the full array plus offset/limit:

php
use ApiPlatform\State\Pagination\ArrayPaginator;
use ApiPlatform\State\Pagination\Pagination;
use ApiPlatform\State\ProviderInterface;
use ApiPlatform\Metadata\Operation;

final class BookProvider implements ProviderInterface
{
    public function __construct(private Pagination $pagination) {}

    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ArrayPaginator
    {
        $results = $this->fetchEverything();
        [$page, $offset, $limit] = $this->pagination->getPagination($operation, $context);

        return new ArrayPaginator($results, $offset, $limit);
    }
}

TraversablePaginator is for when you only hold one page and know the totals — its constructor is (\Traversable $items, float $currentPage, float $itemsPerPage, float $totalItems):

php
use ApiPlatform\State\Pagination\TraversablePaginator;

return new TraversablePaginator(
    new \ArrayIterator($pageItems),
    currentPage: $page,
    itemsPerPage: $limit,
    totalItems: $remoteTotalCount,
);

Inject ApiPlatform\State\Pagination\Pagination to resolve the effective page, offset and limit from the operation + request — don't read ?page off the request yourself, or you'll bypass the resource's paginationItemsPerPage/client toggles.

Both classes also implement HasNextPagePaginatorInterface (hasNextPage()), so a partial-style next link works without a total. Implement PartialPaginatorInterface directly only if you genuinely can't compute totals.

Laravel

The pagination* attributes (paginationItemsPerPage, paginationClientItemsPerPage, paginationMaximumItemsPerPage, paginationEnabled, paginationPartial, paginationClientEnabled/…Partial) and the Hydra view are the same. Differences:

  • Global defaults live in config/api-platform.php under defaults and pagination (pagination_items_per_page, page_parameter_name, items_per_page_parameter_name, etc.) — not YAML.
  • The Eloquent CollectionProvider paginates with paginate() (full) or simplePaginate() (partial), returning ApiPlatform\Laravel\Eloquent\Paginator / PartialPaginator. Custom Eloquent providers can still return the framework-neutral ArrayPaginator / TraversablePaginator.
  • Doctrine-only, no Eloquent equivalent: paginationViaCursor (cursor pagination) and the ORM paginator tuning (paginationFetchJoinCollection, paginationUseOutputWalkers).

Checklist

  • Default pagination left on for unbounded collections
  • paginationClientItemsPerPage paired with paginationMaximumItemsPerPage
  • paginationPartial used where the COUNT query is the bottleneck
  • Cursor pagination has both RangeFilter and OrderFilter on the cursor field
  • Custom providers return ArrayPaginator/TraversablePaginator, not a bare array
  • Page/offset/limit read via injected Pagination, not the raw request

Frequently asked questions

What does the Pagination AI skill do?

Configures collection pagination in API Platform — page-based (default), items-per-page, client-controlled page size, maximum items, disabling, partial pagination, and cursor-based pagination. Use whenever the user mentions pagination, page size, itemsPerPage, paginating a collection, "too many results", slow COUNT queries on large tables, infinite scroll, cursor pagination, or returning a Paginator from a custom provider — even if they don't say "pagination" explicitly.

Why use Pagination on TypingMind?

Because you install it once and use it with any model. Pagination is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Pagination in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/api-platform/skillset/tree/main/skills/pagination. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Pagination?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Pagination?

As many as you like. As long as a model supports skills, you can use Pagination with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Pagination AI skill free?

It is published on GitHub by api-platform. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇