Skip to main content
createKomgaClient supports HTTP Basic credentials, Komga API keys, custom headers, and the platform Fetch credentials mode. Authentication is configured on the client; generated operations do not add a separate authentication layer.

Basic Auth

Use a Komga username and password for local development, scripts, or an integration that already has a protected server boundary.

API key

Use a revocable key for server-to-server jobs and long-running deployments. Keep it in a secret store and rotate it without changing application code.

Basic Auth

The client sends Authorization: Basic ... on each request and performs the UTF-8 Base64 encoding. Use HTTPS whenever credentials leave a local development machine. In a production Node environment, the SDK warns when Basic Auth is configured with an http: base URL; the warning does not make HTTP safe. Basic credentials are sent on every request made with this client. Create a separate client when a request must use a different account or server, rather than mutating shared credentials.

API-key authentication

Use an API key generated by Komga:
The client sends the key as X-API-Key on each request. Generate a key in Komga’s user settings, give it a descriptive purpose, and store it in an environment variable or secrets manager. Replace the deployment secret during rotation, verify the new key, then revoke the old key.

Unauthenticated or custom-header clients

auth is optional. Leave it out when the Komga server is unauthenticated or when your application owns authentication:
Headers supplied in headers are sent with every request except the auth-owned Authorization and X-API-Key headers. Configure auth for those mechanisms instead of trying to replace them manually. A per-operation headers option can add or override request metadata for that call.

Browser credentials and sessions

Pass the standard Fetch credentials mode when a browser application needs to include cookies for its Komga origin:
The SDK does not perform a login flow or exchange tokens. Your application must establish the session and configure the server’s cookie and CORS policies. For cross-origin browser requests, the server must allow the exact request origin and credentials; Access-Control-Allow-Origin: * cannot be used with credentials. Use a same-origin or server-side proxy when private credentials must not reach the browser. For integrations that receive a session through an X-Auth-Token header and need a cookie response, Komga exposes the generated operation below:
Do not expose a Set-Cookie value to untrusted browser code. Cookie storage and forwarding belong to the application boundary that owns the session.

Check a session and log out

Use generated operations for session checks and logout; there is no SDK-wide auth state:
postLogout1 is the generated POST operation for /api/logout. The generated postLogout operation is also present for Komga’s GET variant; prefer POST when the server and integration allow it.

Custom Fetch

The client accepts a Fetch implementation for wrappers, tracing, a proxy, or a different transport:
Treat input and init as potentially sensitive: do not log Authorization, X-API-Key, cookies, or response bodies in production. This is a native Fetch hook; the core client does not expose retry, timeout, or debug options.

Handle authentication failures

Generated operations return structured results instead of throwing by default. Inspect the response status and error body:
A 401 means the server did not accept the credentials or session. A 403 usually means the user is authenticated but lacks the required library or administrative role. Inspect the generated operation’s documentation and Komga permissions before retrying; retrying unchanged credentials will not repair either condition. If your application prefers exceptions, use unwrap and handle KomgaApiError:

Environment variables and deployment

.env
komga-client.ts
Do not commit .env files, put secrets in a public frontend bundle, or print the client configuration. Prefer an API key over a password for automation, grant the Komga account only the permissions the integration needs, and rotate or revoke credentials through Komga when a deployment or operator changes.

Next steps

Quickstart

Install the SDK and make a first request.

Fetch configuration

Review headers, credentials, custom Fetch, and generated options.

Quick reference

Review flat operation signatures and result handling.

Request customization

Observe and modify low-level request lifecycles safely.