Skip to main content
Use these snippets as a reference for the generated Komga API client. All endpoint parameters are flat; the configured client is passed in the optional second argument.

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

The generated signatures used above are:
  • getBookById({ bookId: string }, options?)
  • getLibraries(options?)
  • getBooks({ unpaged?, page?, size?, sort?, bookSearch }, options?)
Operations with no endpoint parameters accept only their options object. Do not use the removed grouped { path, query, body } call shape.

Nonthrowing results

By default, each call resolves to fields containing data, error, request, and response:
The success and error branches are discriminated by 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:
Use the nonthrowing form for local branching and unwrap where an exception is the intended application boundary. A successful 204 No Content operation unwraps to undefined. getBooks sends page, size, sort, and unpaged as query parameters while bookSearch is the generated request body:
Use unpaged: true only for bounded datasets:
Collections and read lists use generated query names rather than BookSearch:

Common reads and mutations

Mutation responses commonly have 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:
Use 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:
Use 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:
The SDK has no built-in retries, caching, timeout policy, or logging. Implement those policies around Fetch or operation calls, and redact auth headers and cookies from logs.

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.