Configure Auto Pagination
Fern’s auto pagination supports offset-based and cursor-based pagination schemes, providing SDK users with simple iterators to loop through all results instead of managing pagination complexity manually.
This page describes how to configure auto pagination for your API endpoints.
How it works for SDK users
TypeScript
Python
Once you’ve configured pagination for an endpoint, Fern generates a TypeScript
SDK method that returns a Page<T>
where T
is the underlying data type. The
Page<T>
will implement the AsyncIterable
interface, allowing your users to
use it in a for await
loop.
Example generated method signature:
Example of how users would call the list
method:
Setting up auto pagination
Setting up auto pagination involves defining your pagination scheme and where your results are located.
OpenAPI
To set up auto pagination for OpenAPI:
- Annotate the desired paginated endpoint with the
x-fern-pagination
extension. - Specify the pagination scheme,
offset
orcursor
- Specify where your
results
are located, using dot-access notation.
How to find the location of your results
For example, if results of my_nested_object
are located in the subfield
inner_list
, the dot-access path would be results: $response.my_nested_object.inner_list
.
Fern Definition
To set up auto pagination for the Fern Definition:
- Annotate the desired paginated endpoint with the
pagination
field. - Specify the pagination scheme,
offset
orcursor
- Specify where your
results
are located, using dot-access notation.