跳到导航

Configure auto-pagination

以 Markdown 格式查看
You're viewing the legacy SDK docs

These pages cover SDK generation configured with generators.yml. New projects use sdk-config.yml, so see the Current version of this page for up-to-date guidance. To move an existing project, follow the SDK Config migration guide, which walks through fern sdk migrate, and review the sdk-config.yml reference.

Fern’s auto-pagination supports offset, cursor, URI, and path-based pagination schemes, providing SDK users with simple iterators to loop through all results instead of managing pagination complexity manually.

Generated SDK behavior

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> implements the AsyncIterable interface, allowing your users to use it in a for await loop.

const response = await client.users.list();
for await (const user of response) {
console.log(user);
}

Setting up auto-pagination

Define your pagination scheme and specify where your results are located:

...
paths:
/plants:
x-fern-pagination:
offset: $request.page_number
results: $response.results
...

For full configuration details, see Pagination in OpenAPI.