📖 API Reference
LibreFolio provides a comprehensive RESTful API built with FastAPI.
🔗 Quick Links
- API Overview - Architecture and design patterns
- cURL Testing Guide - How to test APIs from terminal
🖥️ Interactive Documentation
When the server runs in debug mode (./dev.py server --debug), you can access the interactive documentation generated from the code. These pages allow you to explore the API endpoints, see the expected
request/response schemas, and even execute requests directly from your browser.
- 🚀 Swagger UI : Best for exploring and testing endpoints.
- 💻 ReDoc: Best for reading the documentation in a structured format.
Off on every other instance
/api/v1/docs, /api/v1/redoc and /api/v1/openapi.json exist only where the documentation is switched on: with ./dev.py server --debug, which sets LIBREFOLIO_API_DOCS=1, with that variable set by hand, or in test mode (the test lanes). Anywhere else, Docker and managed instances included, they answer 404 to a client ({"detail": "Not Found"}): an instance in use publishes no map of its API. A browser's page request to one of them, to any other unknown address under /api/ or to a missing /mkdocs/ page is redirected (302) to / instead, by address_not_found() in backend/app/services/platform/static_site.py: it looks at Sec-Fetch-Mode: navigate, or at an Accept that wants HTML when the header is missing. In the web app, frontend/src/routes/+error.svelte sends an unknown page back to the page the user came from, or to /dashboard. The links above therefore work on a debug server only.
The schema does not need the pages: ./dev.py api schema (and ./dev.py api sync, which adds the TypeScript client) builds it in process from the application, so it works whatever the instance serves (API & Frontend Communication). The pages are LibreFolio's own (backend/app/api/api_docs.py), with their libraries pinned and checked: see The Content-Security-Policy and Frame Protection.
🔀 Dynamic Route Generation
FastAPI generates the API routes dynamically at startup based on the Python function definitions. This ensures that the documentation is always perfectly in sync with the code.
The API is structured into routers, each handling a specific domain (all mounted under /api/v1 by backend/app/api/v1/router.py):
/auth: Authentication and the account's own actions. Sign-in and sign-out (/auth/login,/auth/logout): the session is a cookie that lastssession_ttl_hours, with no refresh token (Token Expiration). The current account (/auth/me), registration (/auth/register, with an invitation where the registration mode asks for one), the profile and the password (/auth/profile,/auth/change-password), and the deletion of one's own account (DELETE /auth/users/me, with its preview). The account's user carrieswhats_new, the changelog chapters left to show after an update, andPOST /auth/whats-new/seenrecords that the user closed them (What's new). The links an account receives: inspect a token (/auth/tokens/inspect), the password reset (/auth/password-reset) and the initial administrator's setup (/auth/setup). The Address Probe (/auth/address-probe)./users: User management./email: The instance's email: its state, a test email and the links an administrator sends (GET /email/status,POST /email/test,POST /email/links, administrators only), and, without a session, the «forgot password» email and the verification link (POST /email/password-reset,POST /email/verification/confirm,POST /email/verification/resend); see The API of the Email Service./security: The security checks of the instance, evaluated on demand (GET /security/checks, administrators only); see The Checks on Demand./settings: User settings, admin-managed global settings, scheduler state/logs, the cache admin routes (/settings/cache/status,/settings/cache/clear/{name},/settings/cache/clear-all— see Cache Registry & Admin), and the plugin settings (/settings/plugins— see Plugin Settings)./system: Server info (/system/info: the app version only without a session, everything with one), health check (/system/health), readiness (/system/ready, no session:200when the database answers and its schema is at the head revision,503otherwise, withmigrationsbehindorahead, the database'sdatabase_revisionand the runningapp_version: see System Information and Readiness), plugin diagnostics (/system/plugin-diagnostics), the connection and container-image checks, the public instance configuration (/system/instance, no session: see Public instance configuration), the block page (/system/block, signed-in users only: whether the hosting provider blocked the instance, its deletion date and, for an administrator, where the subscription is managed and whether a backup can still be downloaded; see Instance Block), the catch-up of the prices (GET /system/price-refresh, signed-in users only: whether the scheduler is catching up on prices now, for the web app's notice Updating prices…; see Catch-up Progress), and the scheduled wake-up (POST /system/wake-sync, with theLIBREFOLIO_WAKE_TOKENtoken instead of a session: it runs the scheduler's due jobs and streams their report). System Information and Readiness details/system/infoand/system/ready. One module per resource in thebackend/app/api/v1/system/package, whose__init__.pyonly composes the/systemrouter./uploads: File uploads and media serving./assets: Asset management (CRUD, price history) — includes/prices,/provider(search, live quotes),/events./transactions: Transaction management./brokers: Broker management and sharing — includes/import(BRIM broker report import)./backup: Backup & export./panel: The hosting panel's routes:GET /panel/metrics(get_panel_metrics, lot CL-M1), the read-only figures of the instance (PanelMetricsResponse: fifteen keys, always all present, eachnullwhen it cannot be measured, never a500; sizes in MiB, counts, the checks of the Security tab that are not ok asPanelConfigWarning, the failures of the last 24 hours counted from the scheduler's job log, which keeps 500 entries), opened by a signed ticket of scopemetricsonly (no token,404whileLIBREFOLIO_PANEL_PUBLIC_KEYSis not set), allowed on a blocked instance and on one awaiting a restore; and the status route,GET /panel/status(get_panel_status), with theLIBREFOLIO_PANEL_STATUS_TOKENtoken instead of a session: where the setup of the initial administrator stands, asadmin_setup_status()reads it. Its answer,PanelStatusResponse, holds exactly ten keys:admin_setup, one ofnone,pending,doneandexpired;setup_expires_at, when the setup link stops working, in UTC, only whilepending(nullotherwise);mode,normalorawaiting_restore; andrestore,PanelRestoreSummary(state,reason,waiting,backup_created_at,stage_id),nullwhen no restore was ever recorded (lot H-62); when the state of the restore cannot be read,stateisunreadablewithreasonio,not_a_fileorinvalid, still in a200(decision D7);stateiscommittedwithreasonowner_assignmentwhen the restore is done but the owner of the restored data has no account yet (CL-6);users_used, the places the users take, asuser_usage()counts them (lot H5-1);users_limit,LIBREFOLIO_MAX_USERS,nullwhen it is not set or cannot be used (the route never answers500because of it): two counts, never a name, an email address or an id;owner_email_change,pending,blockedornull, where the change of the owner's address a hosting provider started stands, asinstance_owner.owner_change_status()reads it (lot H5-4, workstream A's module): never the address; andinstance_key,okormismatch, whether the instance key is the one its data was written with (The Key Check, lot H5-7): never the fingerprint; andusers_over_limit, a boolean, true while the active accounts outnumber the limit of the plan, asuser_limit_service.over_limit_state()reads it (Over the limit, lot H5-8): a yes or no, never who; andowner_language,en,it,fr,esornull, the language the owner chose in their account settings (nullwithout an owner or without a chosen language, CL-9). Responses200,401,404(no token set: the route is off),429and503; it answers on a blocked instance too. Its OpenAPI tag is «Hosting panel», the only tag of the fourteen routes a hosting panel calls: the two/panelroutes, the four/backup/panel/jobs…routes, the seven/backup/panel/restore…routes (scopebackup:restore, a signed ticket only: see Awaiting Restore) andPOST /system/wake-sync. See The Hosting Panel's Access./portfolio: Portfolio analysis and metrics./fx: Foreign exchange operations — includes/fx/providersand/fx/currencies./signals: Domain-agnostic signal preview (POST /signals/preview)./risk: Risk analysis — analytics catalog, queries, scenario catalog, and per-asset eligibility for a period (POST /risk/eligibility). The Asset Detail risk view and the What if…? simulation still carry a beta notice./ai-export: Versioned AI Export datasets and analyses./tools: Atomic Tool calculations — catalog, batch compute (POST /tools/compute), and per-process diagnostics; see Tool plugins./utilities: Reference data (ISO currencies, etc.).
On an instance blocked by its hosting provider (LIBREFOLIO_BLOCKED), every route but a short list answers 423 Locked with detail.code instance_blocked to a signed-in user, and 401 to a caller without a valid session, the public routes outside the list included: see Instance Block.
While the hosting panel restores an instance (LIBREFOLIO_AWAIT_RESTORE), every route but the probes, /system/instance, the scheduled wake-up and the panel's routes answers 423 Locked with detail.code instance_awaiting_restore, to anyone, signed in or not: see Awaiting Restore.
When the process found the state of the restore (.restore/restore.json) unreadable at its start, the same routes answer, but the panel's backup start, which answers 409 backup_restore_interrupted once the panel's credential is checked, and every other one answers 423 Locked with detail.code instance_restore_interrupted, to anyone, until the administrator runs ./dev.py backup pending --recover previous and restarts LibreFolio; GET /system/instance then says restore_interrupted: true and restore_interrupted_reason: "restore_state". The same answers hold, with the reason owner_assignment, while the owner of an instance restored from the app has no account yet (./dev.py backup pending --recover owner when it could not be given): see A Restore Stopped Half Way.
When the instance key is not the one the data was written with (instance_key: "mismatch" in GET /panel/status), the instance keeps serving, and only two things of the hosting panel stop: its backup start answers 409 backup_instance_key_mismatch, once the panel's credential is checked, and POST /system/wake-sync runs no job and answers the status instance_key_mismatch: see The Key Check.
📋 Pydantic Schemas
The API uses Pydantic models for data validation and serialization. These schemas define the structure of the data exchanged between the frontend and backend. You can find the
schema definitions in the backend/app/schemas/ directory.