librarian

API Surface

The FastAPI service exposes the same core workflows as the CLI. Requests above LIBRARIAN_API_MAX_REQUEST_BYTES are rejected before routing, either from Content-Length or while streaming the request body.

Documents

Imports

Example:

{
  "source_dir": "/data/input",
  "format": "md",
  "output_mode": "workspace",
  "recursive": true,
  "overwrite": false,
  "processing_mode": "queue"
}

processing_mode may be none, process, or queue.

output_mode may be workspace (default), new-directory, original, or subdirectory. The default workspace mode writes converted files under <data_dir>/converted so imports never create artifacts next to the source documents; directory imports get a per-source subdirectory there. new-directory requires output_dir, and output_dir is rejected for other modes.

The source_dir field accepts either a file path or a directory path under LIBRARIAN_API_IMPORT_ROOT. The name is kept for API compatibility.

Set manifest_path to a JSON file under LIBRARIAN_API_IMPORT_ROOT to persist incremental import progress. Existing manifest files must be Librarian import reports so unrelated JSON files are not overwritten. resume: true reuses successful records from that manifest. GET /imports/status?limit=500&offset=0 reads the same manifest and returns summary counts plus a bounded page of per-file records. Import manifest validation, resume, and status reads are capped by LIBRARIAN_API_MAX_IMPORT_MANIFEST_BYTES. Manifest paths must not be symlinks or cross symlinked parents, and manifest writes are atomic replacements. new-directory output paths are also validated before conversion starts and must not be symlinks or cross symlinked parents.

Runs

Search And Metadata

Errors

All HTTP responses, including text exports, Prometheus metrics, and server-sent event streams, carry the API security headers configured by the service.

JSON errors include the human-readable detail field and a stable machine-readable code field. The OpenAPI schema documents this shared error shape across API operations. Validation errors use code: "validation_error" and keep FastAPI’s structured validation detail. Unhandled server exceptions return code: "server_error" with a generic message so internal exception text and provider credentials are not exposed to API clients. When LIBRARIAN_API_RATE_LIMIT_PER_MINUTE is enabled, exhausted clients receive HTTP 429 with code: "rate_limited" and a Retry-After header. Unauthenticated rate limits use the socket peer IP unless LIBRARIAN_API_TRUSTED_PROXY_CIDRS explicitly trusts the connecting proxy; untrusted X-Forwarded-For headers are ignored. When scoped keys are configured with LIBRARIAN_API_KEYS=read:<key>,write:<key>, read-only keys can call GET, HEAD, OPTIONS, and search endpoints except operational /config, /metrics, and /metrics/prometheus; blocked writes or operational reads return HTTP 403 with code: "insufficient_scope". Use LIBRARIAN_API_KEY_SHA256 or scoped LIBRARIAN_API_KEY_HASHES to configure SHA-256 hashes instead of plaintext API keys. Clients still send the original key in x-api-key or Authorization: Bearer <key>. When API credentials are configured, /openapi.json itself requires authentication, and the generated schema advertises both authentication schemes on protected endpoints while leaving /health, /ready, and /version unauthenticated.

Example:

{
  "detail": "Document not found",
  "code": "not_found"
}

CLI Parity