Skip to main content
Generated list operations expose pagination as flat parameters. The server returns generated page types such as PageBookDto, PageCollectionDto, and PageReadListDto. Pagination state belongs in your application; the SDK does not keep a cursor or automatically fetch another page.

Page response fields

PageBookDto is generated as an object whose fields are optional because the OpenAPI response permits partial data:
Use ?? when rendering or iterating so a missing field does not become an unchecked runtime access. getLibraries is not paginated: it returns LibraryDto[] directly.

Fetch a page of books

getBooks accepts page, size, sort, and unpaged alongside its generated bookSearch body parameter. Page indexes are zero-based:
For UI state, preserve the search and sort values when moving pages and reset page to 0 when the user changes a filter:

Sorting

Pass server sort expressions in the generated sort array. The common Komga form is field,direction:
Sort strings are transported to Komga; the server determines which fields and directions are accepted for an endpoint. Use a stable tie-breaker such as title or id when exporting multiple pages, and keep sort order unchanged for the duration of the export.

Search parameters

BookSearch is the generated body type for getBooks:
Do not add the former service-layer fields such as tags, readStatus, or libraryId unless the generated BookSearch type for your SDK version includes them. TypeScript will identify fields that are not in the generated contract. Collections and read lists use query strings instead of BookSearch:
The generated parameter name library_id is intentional. Arrays are serialized by the generated client according to the OpenAPI contract; pass an array rather than joining ids into a comma-delimited string yourself.

Unpaged requests

List operations expose unpaged when the endpoint supports it:
Use unpaged requests only when the result size is bounded by your application. Large libraries can produce large response bodies, increase memory pressure, and make retries expensive.

Iterate through pages

This async generator stops on the generated last field and preserves the default non-throwing result contract:
If the server returns an incomplete page envelope, treating a missing last as a stop condition avoids an accidental unbounded loop. If you prefer typed API exceptions, replace the error branch with unwrap(await getBooks(...)) and catch KomgaApiError at the application boundary.

Parallel fetching and batch work

Parallel page fetching can reduce latency but increases load and can produce inconsistent snapshots while the library changes. First fetch page 0, read totalPages, then bound concurrency and keep filters and sort fixed:
Use sequential iteration for mutations, rate-limited servers, or an export that needs predictable load. Never assume page numbers remain valid after deleting or adding many matching records.

Next steps

Direct API functions

Learn the flat operation call shape.

Result handling

Handle generated errors or use unwrap.

Runtime validation

Add validation only when your application needs it.