Logo van Pagination

Pagination

Organisatie
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.

Overzicht

Uitgeverapi-platform
Repositoryskillset
Skillnaampagination
Sterren
29
Forks
1
Meegeleverde bestanden
Alleen instructies
Links
  • Instructies in Markdown

    Een SKILL.md-bestand dat het model laadt wanneer nodig, zodat het alleen tokens kost als een verzoek er daadwerkelijk bij past.

  • Werkt met elk LLM

    AI-skills zijn gewone Markdown, geen aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • Compleet zonder extra bestanden

    Alles wat het model nodig heeft, staat in de instructies — geen extra bestanden om te synchroniseren.

  • Open source

    Gepubliceerd door api-platform op GitHub. Lees de broninhoud voordat je de skill installeert.

Installatie

Installeer de AI-skill Pagination in TypingMind om deze met elke LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map — het leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/api-platform/skillset/tree/main/skills/pagination
  4. Schakel de skill in elke chat in waarin je deze beschikbaar wilt hebben.
Plug-ins → Skills → Nieuwe skill → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die agent.

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
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Pagination in een willekeurige chat in TypingMind in en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek erbij past, laadt het model zelf de volledige instructies — je hoeft de skill nooit handmatig aan te roepen en deze kost pas tokens wanneer je de skill daadwerkelijk gebruikt.

Het model laadt Pagination automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Pagination niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

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

Veelgestelde vragen

Wat doet de AI-skill 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.

Waarom Pagination gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Pagination bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model, en je kunt midden in een chat van model wisselen zonder dat de skill niet meer werkt. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Pagination in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/api-platform/skillset/tree/main/skills/pagination. TypingMind leest het bestand SKILL.md en installeert het als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Pagination gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Pagination gebruiken?

Zoveel als je wilt. Zolang een model skills ondersteunt, kun je Pagination ermee gebruiken: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama en meer. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Pagination gratis?

Deze skill is door api-platform op GitHub gepubliceerd. Bekijk de repository voor de licentievoorwaarden. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. Deze volgt het open Agent Skills-formaat: een bestand met de naam SKILL.md met een naam en beschrijving, plus eventuele scripts, sjablonen of referentiebestanden die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Toon alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇