Introducing a new way to review your PRs.

Read the announcement

karakeep-app / karakeep

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

View on GitHub

21 documents · Updated Nov 23, 2026

docs / integration-operations-apis

Integration and operations APIs

Integration and operations APIs let people and connected systems manage account data, move bookmark collections into Karakeep, receive bookmark events, create recoverable copies, and maintain a running service. The API presents these capabilities through the shared tRPC router and selected REST routes, with access shaped by the user, an API key, or an administrator.

API surface

The API surface groups account and service actions around the same user-owned bookmark system. tRPC is the common contract for the web application and internal callers. REST exposes selected actions under /api/v1 and adds direct binary, public, health, metrics, and webhook routes. Mutation routes can be disabled when the service runs in demo or degraded read-only mode. The shared transport model is described in API and tRPC. packages/…/_app.ts• L1-42 packages/…/index.ts• L29-43 packages/…/readOnlyMode.ts• L7-14

The integration and operations areas provide these capabilities:

AreaPurpose
UsersRead the current identity and usage picture and manage account settings.
SubscriptionsShow plan state and quota use, manage billing, and support administrator-managed entitlements.
API keysCreate, list, replace, revoke, validate, and scope programmatic access.
AssetsUpload files, attach them to bookmarks, replace or detach them, and read them through protected or temporary links.
WebhooksRegister bookmark event destinations and deliver matching events outside Karakeep.
ImportsStage a collection, inspect its progress, pause or resume it, and finalize processing.
BackupsStart, inspect, download, and remove full account archives.
Public bookmarksRead published list metadata and bookmark contents without a user session.
AdministrationChange user access and limits and start repair or rebuild work for stored bookmark data.

References: packages/…/_app.ts• L21-42 packages/…/index.ts• L29-43 packages/…/readOnlyMode.ts• L7-14

Access control

Access control separates identity from the right to use a resource. A session identifies a signed-in user. An API key identifies that user for programmatic calls and can limit the call to a resource with read or readwrite access. Admin procedures add a role check after the relevant admin scope check. packages/…/index.ts• L33-59 packages/…/index.ts• L131-152 packages/…/index.ts• L177-226

Keys use least-privilege scopes where a client needs more control than the default full-access key. A readwrite grant also satisfies a read request for the same resource. Session-only actions cannot use API keys. Resource ownership checks protect user data even after the request has passed authentication. packages/…/apiKeys.ts• L3-19 packages/…/apiKeys.ts• L44-105 packages/…/actor.ts• L23-45

flowchart TD
    Request[Request] --> Identity{Identity}
    Identity --> Session[User session]
    Identity --> Key[API key]
    Session --> UserAccess[User-owned access]
    Key --> Scope[Resource scope]
    Scope --> UserAccess
    UserAccess --> Admin{Admin resource?}
    Admin -->|No| Operation[Run operation]
    Admin -->|Yes| Role[Require admin role]
    Role --> Operation

References: packages/…/index.ts• L131-226 packages/…/auth.ts• L9-59 packages/…/apiKeyScopes.ts• L14-38 packages/…/actor.ts• L7-45

User and subscription services

The user API gives an integration a stable view of the signed-in account and its use of Karakeep. REST exposes the current profile at /api/v1/users/me and usage statistics at /api/v1/users/me/stats; the wider tRPC user router also supports account settings, avatar selection, and account lifecycle actions for the application. Account creation applies the default free limits and establishes the initial administrator when no role is supplied. The first-user role decision and account creation use one protected operation. Account deletion cannot proceed while it has an active, trialing, or past-due Stripe subscription. The optional wrapped-stat views are currently disabled. packages/…/users.ts• L5-20 packages/…/users.ts• L26-125 packages/…/users.ts• L64-208

The subscription API connects account entitlements to Stripe when billing is configured. A user can inspect the current tier and quota use, start a monthly or yearly checkout, open the billing portal, or request a sync. An administrator can grant a named custom tier with its own limits when the account has no active Stripe plan. Stripe events are checked and then mapped to the local subscription and quota state. A manually granted tier remains in force until a real active Stripe subscription replaces it or an administrator removes the grant. When Stripe has overlapping plans, the active plan with the latest period end supplies the user’s entitlement. packages/…/subscriptions.ts• L201-239 packages/…/subscriptions.ts• L329-369 packages/…/subscriptions.ts• L411-550 packages/…/subscriptions.ts• L552-681

sequenceDiagram
    participant User
    participant API
    participant Stripe
    participant Account as Account state

    User->>API: Request checkout or billing status
    API->>Stripe: Create checkout or read billing data
    Stripe-->>API: Checkout link or subscription event
    API->>Account: Sync tier, status, and quotas
    Account-->>User: Return current plan and usage

References: packages/…/users.ts• L5-20 packages/…/users.ts• L60-127 packages/…/users.ts• L64-208 packages/…/users.ts• L74-125 packages/…/subscriptions.ts• L97-105 packages/…/subscriptions.ts• L201-239 packages/…/subscriptions.ts• L604-729

API key lifecycle

API keys provide durable credentials for scripts, extensions, and other clients that need to act as a user without a browser session. The key API creates keys with either full access or named scopes, lists key metadata without returning stored secrets, regenerates a key, and revokes it. A credential exchange also lets a trusted client trade user credentials for a new key. packages/…/apiKeys.ts• L27-101 packages/…/apiKeys.ts• L102-214

The REST API uses a Bearer token for its authenticated routes. Scope checks happen at the boundary before the operation runs, so a key can be limited to the data and actions needed by one integration. The extension is one known consumer of the credential exchange flow; browser capture behavior is described in Browser extension capture. Other client patterns are described in Developer tool integrations. packages/…/karakeep-openapi-spec.json• L1-6 packages/…/apiKeys.ts• L132-194

References: packages/…/apiKeys.ts• L35-214 packages/…/apiKeys.ts• L44-105 packages/…/apiKeyScopes.ts• L14-38 packages/…/common.ts• L3-11

Asset exchange

Assets are binary files that support bookmarks and backups. The asset API uploads a file, returns its identity and metadata, and lets a client attach, replace, or detach that asset from a bookmark through the shared asset operations. Upload is subject to type, size, storage quota, and service read-only checks. A client can download an owned asset with its Bearer token or ask for a short-lived signed URL when a direct download link is more useful. packages/…/assets.ts• L14-72 packages/…/upload.ts• L43-92 packages/…/assets.ts• L14-83

User avatars use the same asset store but follow a separate ownership rule. The selected asset must belong to the user, must not already belong to a bookmark, and must be an image. Replacing an unused old avatar removes that old asset, while an asset that supports a bookmark is kept. Clearing an avatar removes storage only when the previous value resolves to an unused asset row owned by that user; arbitrary image values such as an OAuth picture URL are not treated as storage keys. packages/…/users.ts• L287-389

Public delivery does not make an asset generally open. The public asset route accepts a signed token that names both the asset and its owner, checks its expiry and ownership, and then serves the file. This supports public bookmark views while keeping the underlying asset tied to the intended user. packages/…/assets.ts• L14-48

References: packages/…/assets.ts• L14-72 packages/…/assets.ts• L12-75 packages/…/upload.ts• L43-145 packages/…/assets.ts• L22-281 packages/…/users.ts• L287-389 packages/…/assets.ts• L14-83 packages/…/assets.ts• L14-48 packages/…/assets.ts• L21-136

Webhook delivery

Webhooks connect bookmark changes to an external system. A user registers a URL with one or more event types and can change or remove that registration. The returned webhook record reports whether a token exists without exposing the token itself. packages/…/webhooks.ts• L16-85 packages/…/webhooks.ts• L6-35

When a matching bookmark event occurs, Karakeep places delivery work on a queue. A worker sends a JSON request to each matching destination and can add the configured Bearer token. Delivery is independent from the bookmark request, so the source operation does not need to wait for the remote system. Failed calls are retried within the worker policy. packages/…/webhooks.service.ts• L77-95 apps/…/webhookWorker.ts• L86-184

flowchart LR
    Change[Bookmark change] --> Match[Match subscribed event]
    Match --> Queue[Webhook queue]
    Queue --> Worker[Delivery worker]
    Worker -->|Success| Destination[External destination]
    Worker -->|Failure| Retry[Retry within policy]
    Retry --> Destination

References: packages/…/webhooks.ts• L6-35 packages/…/webhooks.service.ts• L77-95 apps/…/webhookWorker.ts• L18-55 apps/…/webhookWorker.ts• L117-184

Import sessions

An import session is a durable workspace for moving an external bookmark collection into Karakeep. The client creates a session, stages valid link, text, or asset bookmark records in small batches, and finalizes the session so background work can process it. Session stats show total, pending, processing, completed, and failed records. packages/…/importSessions.ts• L54-162 packages/…/importSessions.ts• L6-45

The session state gives an import a controlled lifecycle. The client can inspect result pages, pause work that is pending or running, resume paused work, or delete the session. Each session belongs to its creator, and access checks occur before session actions. Completed sessions can later become archived. Archival records the final item counts and removes old detail rows as one protected operation, so the retained summary does not get separated from cleanup when more than one process handles the sweep. packages/…/importSessions.service.ts• L31-154 packages/…/importSessions.service.ts• L180-227 packages/…/importSessions.repo.ts• L100-187

The higher-level importer turns a source file into this session flow. It creates an import root list, rebuilds source list relationships, maps bookmark membership, stages records in batches, and finalizes the session. The result returns the root list and session identifiers so the caller can follow progress. packages/…/importer.ts• L56-94 packages/…/importer.ts• L151-227 packages/…/importer.ts• L260-286

flowchart TD
    File[Source file] --> Parse[Parse collection]
    Parse --> Structure[Create import lists]
    Structure --> Stage[Stage bookmark batches]
    Stage --> Finalize[Finalize session]
    Finalize --> Process[Background processing]
    Process --> Results[Inspect results and stats]
    Results --> Pause[Pause or resume when needed]

References: packages/…/importSessions.ts• L54-162 packages/…/importSessions.service.ts• L74-154 packages/…/importSessions.service.ts• L180-227 packages/…/importSessions.repo.ts• L100-187 packages/…/importer.ts• L88-149 packages/…/importer.ts• L260-286

Backup lifecycle

Backups preserve a full user account as a downloadable archive. The API creates a pending backup and starts background work, while later reads report whether the archive succeeded or failed. Users can list backups, inspect one, download a completed archive, or permanently remove the backup and its archive asset. packages/…/backups.ts• L14-59 packages/…/backups.ts• L5-42 packages/…/backups.ts• L3-14

sequenceDiagram
    participant Client
    participant API
    participant Queue
    participant Archive as Backup archive

    Client->>API: Create backup
    API->>Queue: Start background job
    API-->>Client: Pending backup
    Queue->>Archive: Build account archive
    Client->>API: Read backup status
    API-->>Client: Success or failure
    Client->>API: Download successful backup

References: packages/…/backups.ts• L14-59 packages/…/backups.ts• L43-79 packages/…/backups.ts• L14-42 packages/…/backups.ts• L23-164

Public bookmark access

Public bookmark APIs expose only lists that the owner has made public. A caller can read list metadata and page through its bookmarks without a user session. The same public list contents also support an RSS representation for feed readers. packages/…/publicBookmarks.ts• L15-76 packages/…/rss.ts• L12-55

The public surface is read-only. It uses list-level publication rules and optional list tokens where the route supports them. Asset content is delivered through a separate signed link, so publishing a list does not remove the access check from its files. For bookmark organization and related list actions, see Bookmark organization APIs. packages/…/publicBookmarks.ts• L16-75 packages/…/assets.ts• L14-48

References: packages/…/publicBookmarks.ts• L15-76 packages/…/rss.ts• L12-55 packages/…/assets.ts• L14-48

Administrative operations

Administrative APIs give an administrator tools to manage users, enforce limits, inspect account data, and recover service state. User actions can list or create users, update another user’s role, bookmark quota, storage quota, or browser-crawling setting, reset another user’s password, and view user-level usage totals. Admins can preview or enqueue removal of bookmarks above a user’s quota. Sensitive self-modification, self-password reset, and self-deletion actions are blocked. packages/…/admin.ts• L474-685 packages/…/users.ts• L26-58 packages/…/subscriptions.ts• L604-681 packages/…/admin.ts• L12-25

Maintenance actions turn repair requests into background work. An administrator can inspect bookmark debug data, recrawl links, rebuild the search index, rerun tagging or summarization, regenerate embeddings, reprocess assets, and run a named maintenance task. These actions can target one bookmark or a filtered set. The admin status API reports queue pressure and pending or failed work across the main background systems. The broader queue and job model is described in Automation, operations, and jobs. packages/…/admin.ts• L87-473 packages/…/admin.ts• L850-1090

Connection checks report whether the search engine, browser service, queue, and vector store are configured and reachable. A provider failure is reported for that provider instead of preventing the other connection results from being returned. Health and metrics routes serve different needs: health gives a simple service response, while metrics require a bearer token and expose operational measurements. Administrators can also request a direct Stripe sync for an account with a Stripe customer. packages/…/admin.ts• L697-848 packages/…/admin.ts• L1071-1090 packages/…/health.ts• L5-14 packages/…/metrics.ts• L26-30

References: packages/…/admin.ts• L64-267 packages/…/admin.ts• L268-473 packages/…/admin.ts• L474-685 packages/…/admin.ts• L697-848 packages/…/admin.ts• L850-1090 packages/…/users.ts• L26-58 packages/…/subscriptions.ts• L604-681 packages/…/admin.ts• L12-80 packages/…/health.ts• L5-14 packages/…/metrics.ts• L26-30

API request flow

REST and tRPC routes share the same request context and core procedures. The API first builds a context, then selects the route family, checks identity and scope, and calls the shared router or operation. Binary downloads and inbound Stripe events use dedicated HTTP routes because they need raw files or the original signed request body. packages/…/trpc.ts• L8-29 packages/…/webhooks.ts• L8-42 packages/…/index.ts• L69-93

Most long-running actions return after they create background work. Callers should treat a pending backup, import, webhook, or maintenance request as an accepted job and use its status or downstream result to learn when the work finishes. Mutation requests can instead be rejected before work starts when demo or degraded read-only mode is active. This pattern keeps user requests separate from crawling, archive creation, event delivery, and repair work. packages/…/backups.ts• L45-59 packages/…/importSessions.ts• L117-136 packages/…/admin.ts• L268-473 packages/…/readOnlyMode.ts• L7-14

References: packages/…/index.ts• L69-93 packages/…/trpc.ts• L8-29 packages/…/webhooks.ts• L8-42 packages/…/readOnlyMode.ts• L7-14 packages/…/index.ts• L93-120

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the tRPC router names, REST route adapters, and OpenAPI descriptions aligned when an integration capability changes.
  • Keep API key resource names and admin resource names aligned with every scope check. A route can silently reject a valid key if the required scope name changes in only one layer.
  • Preserve the link between uploaded assets and their owner when changing signed URLs, public assets, bookmark attachments, avatar selection, or backup downloads. Treat user image values as references only after resolving an owned asset row.
  • Keep asset upload mutation routes behind the service’s read-only guard. A degraded or demo service must not accept a new file while other mutation paths are blocked.
  • Preserve import session state rules when changing staging, finalization, pause, resume, archival, or worker pickup. A state that no longer reaches pending can strand an import.
  • Keep archived import summary fields consistent with the status rows before detailed staging records are removed. Preserve the atomic archive-and-cleanup boundary when changing the archival sweep, so concurrent processing cannot leave a summary that does not match the removed detail.
  • Keep webhook event names aligned across registration, event creation, queue payloads, and worker matching. A spelling change can stop delivery without an API error.
  • Keep asynchronous response states aligned with the worker record states for backups, imports, and admin jobs so clients can distinguish pending work from failure.
  • Keep Stripe tier selection, custom tier overrides, quota values, and browser-crawling access aligned. A sync can silently replace the wrong entitlement when a customer has more than one Stripe subscription.
  • Review both user ownership and admin role checks when adding an operation that reads or changes another user’s data.
  • Keep account creation’s first-user role choice and default quota assignment within the same protected operation. A split check can create more than one initial administrator under concurrent registration.
  • Keep account deletion blocked until active, trialing, or past-due Stripe subscriptions are canceled. Deleting the account first can leave billing state without its user.
  • Keep admin quota purge results aligned with the quota value used by the queued maintenance task. A dry run must not enqueue deletion work.
  • Keep per-bookmark repair validation aligned with bookmark type. Link-only actions must not become available for text or asset bookmarks by accident.
  • Preserve per-provider error isolation in connection checks. One unreachable service must not hide the state of the other providers.

Important failure modes

TriggerConsequenceGuard
API key lacks the resource or admin scopeThe request is rejected with a forbidden response before the operation runs.Create the key with the narrow scope required by the client and keep the scope check on the route.
A session-only procedure receives an API keyThe request is rejected even if the key has broad access.Use a user session for account-only actions such as key management.
A mutation runs while demo or degraded read-only mode is activeThe request is rejected with a forbidden response and no new mutation work starts.Send read requests only, or restore write mode before using uploads and other mutations.
A signed asset token is expired, names another asset, or names another ownerPublic asset delivery returns a forbidden response or not-found response.Treat signed asset URLs as temporary and request a new one when needed.
An asset has an unsupported type, exceeds the size limit, or exceeds storage quotaUpload is rejected and no usable asset is returned.Check supported types, configured size limits, and the account’s storage quota before upload.
An avatar asset belongs to another user, is attached to a bookmark, or is not an imageAvatar selection is rejected and the current avatar stays in place.Upload or select an unused image asset owned by the same user.
A stored avatar value is an arbitrary URL or another user’s storage path rather than an owned asset rowClearing the avatar removes the user reference but does not delete unrelated storage.Resolve the previous value to the same user’s unused asset row before deleting its asset and file.
An import is finalized outside stagingThe import is rejected and does not enter background processing.Stage all batches first, then finalize once.
An archived import is queried for item-level staging resultsThe session summary remains available, but the removed item records are not available for detail pages.Read detailed results before retention archives the completed session.
Concurrent import archival observes stale session stateOne archival attempt is skipped or an archival sweep can report less progress than expected.Treat archive as a retryable maintenance action and keep the status change and detail cleanup in one atomic operation.
A backup is read before its archive is readyThe caller sees pending or failure state instead of a downloadable archive.Poll backup status and download only after success.
A user or administrator tries to delete an account with an active, trialing, or past-due Stripe subscriptionAccount deletion is rejected until billing is no longer active or being retried.Cancel the subscription and wait for billing to stop, then retry deletion.
A manual tier is assigned to an unverified user or a user with an active Stripe subscriptionThe tier update is rejected and current entitlements remain unchanged.Verify the email and remove the active Stripe subscription before granting a custom tier.
A Stripe webhook has no signature or an invalid signatureBilling state is not updated.Send the raw request body with the Stripe signature header.
A webhook destination returns errors or times outThe delivery attempt fails and is retried within worker policy.Make the destination idempotent and monitor permanent delivery failures.
An administrator requests a broad repair jobWork is added to low-priority queues and can remain pending while other jobs run.Use status and modified-time filters when the repair does not need the full data set.
An administrator tries to update, reset, or delete their own account through an admin actionThe action is rejected instead of changing or removing the administrator’s own account.Use a separate account action where allowed, or have another administrator perform the action.
A wrapped-stat endpoint is called while the feature is disabledThe request returns a bad-request error instead of usage data.Use the current user stats endpoint until wrapped stats are enabled.
A quota purge targets a user without a bookmark quotaThe purge is rejected because there is no limit against which to compare.Set a bookmark quota first, then preview or enqueue the purge.
A connection provider is configured but unreachableThat provider is reported as configured and disconnected with an error while other checks continue.Read each provider result independently and restore the failed service before relying on it.
Concurrent registration checks the user count without protecting the role decisionMore than one account can receive the initial administrator role.Keep the first-user decision and account creation in one protected operation.

Key files

FileWhy to read it
packages/…/index.tsShows how REST, tRPC, public, webhook, health, and metrics route families meet at the API boundary.
packages/…/_app.tsShows the shared top-level capability map.
packages/…/index.tsDefines authentication, API key scope checks, admin checks, rate limits, and shared request behavior.
packages/…/readOnlyMode.tsShows how the service blocks selected mutations in demo or degraded mode.
packages/…/apiKeys.tsDefines the API key lifecycle and the credential exchange used by clients such as the extension.
packages/…/apiKeys.tsDefines the resource and admin scope vocabulary used across clients and routes.
packages/…/importSessions.tsDefines the import session lifecycle and progress queries.
packages/…/importSessions.repo.tsShows how completed import summaries are retained while old detail rows are archived as one protected operation.
packages/…/importer.tsShows how a source collection becomes lists, staged bookmark batches, and a processable session.
packages/…/webhooks.tsDefines webhook registration and ownership behavior.
apps/…/webhookWorker.tsShows how registered events become external HTTP deliveries and retries.
packages/…/backups.tsDefines backup creation and user-facing backup operations.
packages/…/assets.tsShows protected binary upload, download, signed URL access, and the read-only mutation guard.
packages/…/assets.tsDefines asset ownership, bookmark attachment rules, and signed asset links.
packages/…/users.tsDefines account creation, account lifecycle checks, avatar ownership, and the user identity and usage views.
packages/…/users.tsDefines user identity, settings, avatar, account deletion, and administrator user actions.
packages/…/subscriptions.tsDefines billing, quota reporting, Stripe synchronization, and administrator-managed tiers.
packages/…/admin.tsDefines administrator controls for users, quota enforcement, bookmark repair, queues, service connections, and Stripe sync.
packages/…/karakeep-openapi-spec.jsonProvides the generated REST contract and its shared authentication and pagination context.