Client setup
baseUrl is required. auth is optional for an unauthenticated server or an application-owned session. Keep Basic credentials and API keys on a server-side boundary when a browser bundle is public.
Flat operation calls
getBookById({ bookId: string }, options?)getLibraries(options?)getBooks({ unpaged?, page?, size?, sort?, bookSearch }, options?)
{ path, query, body } call shape.
Nonthrowing results
By default, each call resolves to fields containingdata, error, request, and response:
error. request and response are optional because request construction and network failures may happen before Fetch creates either object. Use response?.status for HTTP handling and the generated error body for operation-specific details.
Throwing at an explicit boundary
unwrap returns data or throws KomgaApiError:
unwrap where an exception is the intended application boundary. A successful 204 No Content operation unwraps to undefined.
Pagination and search
getBooks sends page, size, sort, and unpaged as query parameters while bookSearch is the generated request body:
unpaged: true only for bounded datasets:
BookSearch:
Common reads and mutations
data: undefined because Komga returns 204 No Content; check error and response even when there is no data to print. Operation documentation and generated types are the source of truth for required roles and fields.
Binary, text, and void responses
Generated Fetch options can select the parser for an endpoint whose response is not JSON:arrayBuffer, blob, or text only when it matches the endpoint’s generated response. Always revoke browser object URLs after the image is no longer needed.
TypeScript types
Generated DTO types are available for annotations. They guide compile-time use and do not validate runtime responses:Awaited<ReturnType<typeof getBookById>> when a wrapper should follow the generated result contract instead of reproducing it manually.
Native Fetch customization
Configure headers, credentials, parser options, or a Fetch implementation when creating the client or per operation:Environment variables
Next steps
Direct API functions
See request mapping, binary results, and mutation examples.
Pagination
Iterate pages, sort results, and search safely.
Result handling
Handle API, network, and parsing failures.
Request customization
Add low-level Fetch lifecycle hooks.