The Plugin API
src.plugin_api is the surface a plugin imports from. It is the only part of the
backend a plugin may import.
On this page
from src.plugin_api import User, get_current_active_user, generate_uliddb is the one export to import differently — inside the function that uses it,
never at your module's top level:
def list_rows():
from src.plugin_api import db
with db.get_cursor() as cursor:
...A module-level from src.plugin_api import db copies the database handle into your
module's namespace the first time your plugin is imported, and keeps that copy for the
life of the process. Anything that later swaps the application's database — a test
harness, most commonly — swaps the handle your module is no longer reading. Importing
inside the function resolves it fresh on every call.
Everything else under src/ is internal. It is refactored, renamed and moved as the
application changes, and none of those changes are announced. A plugin that imports an
internal path will keep working right up until it doesn't — and it will fail at load
time, in someone else's installation.
55 sections#
- What it guarantees
- What's importableEvery name below can be imported directly from src.plugin_api. They are also grouped into modules (src.plugin_api.providers, .chat, .backends, …) if…
- Examples
- Initializing your plugin: boot vs enable
- Choosing a plugin categorycategory: in manifest.yml decides which group the plugin appears under in Admin → Plugins. It describes what the plugin adds, not how it is built.
- Settings formA manifest's settings: list renders as the plugin's form in Admin → Plugins → Settings. Each entry has name, type (string, number, boolean), label…
- API keys on plugin routes
- WebSocket authenticationauthenticate_websocket(websocket) authenticates a plugin WebSocket by hand, before accept(). It reads a single-use ?ticket= (minted by POST…
- Login providersA login provider signs users in through an external identity source — an OIDC issuer, a company SSO, anything with a redirect and a verifiable…
- Contributing a cloud provider
- Showing admins the next setup stepA plugin that needs more than the enable switch (a backend with an API key, models turned on, presets installed and assigned) lists those steps…
- Contributing a chat mode
- Contributing an LLM configuration type
- Contributing automation templates
- Contributing Auto-organize facts and actionsAuto-organize lets each user write rules that file their own generations, Library uploads and models: "when a new image is made with Krea-2 at 1344…
- Contributing a plan limit kindA plan is a named list of limits, and each limit is one kind: storage space, generations per day, cloud spend per month and the largest single…
- Contributing a recipe (and recipe step kinds)A recipe is an ordered list of steps that takes an instance from "nothing installed" to "this preset generates". The first-run wizard runs one, and…
- Contributing a model layout profile
- Contributing LLM profile rows
- Contributing photo filters and filter opsA filter is a recipe of adjustment steps (plus an optional .cube LUT) the image editor and the server apply the same way; Photo Filters is the…
- Samplers and schedulesThe native engine's step algorithms (samplers) and sigma schedules are both registries. A plugin adds its own with two manifest roots and two plain…
- Contributing a model classifierPotionUI reads the header of every safetensors or GGUF file in a folder that has header scanning on, and decides the model type from what it finds…
- Contributing a model type
- Contributing a prompt resource source
- Contributing a prompt importer
- Writing a prompt for a presetsrc.plugin_api.prompts.write_prompt_for_preset(user_id, instruction, *, preset_id=None, mode=None, form_data=None, media=(), llm_id=None) asks a…
- Contributing a phrasebook batch tool
- Media toolsA media tool is one declaration of something that edits media: trim a clip, resize an image, loop a video. Core ships nineteen; a plugin adds its…
- Contributing an editor taskA plugin adds a job the Image editor can offer, such as "Colorize a region", with editor_tasks in manifest.yml. Disabling the plugin removes its…
- Extending the editorsThe image, video and audio editors take parts from plugins. A plugin declares each part in manifest.yml; the code that implements it is a built file…
- Reading model files and folders
- Contributing a model card action
- Contributing a Generation Details action
- Contributing an Admin tab with its own left menu
- Contributing modes to an existing preset
- Extending existing preset modes
- Contributing a compute provisioner
- Reading presetssrc.plugin_api.presets describes the presets of this instance, so a plugin can offer a user a choice of presets and fill a request for the one they…
- Running generations from a pluginsrc.plugin_api.generation is the supported way to start, follow and read generations from outside the Generate page. Each function takes the acting…
- Working with the user's mediasrc.plugin_api.media lets a plugin read the file of a media the user picked, take a frame out of a video, store a file it made in the user's Library…
- Image vectors and facessrc.plugin_api.media lends a plugin the image models of the application, so that it can compare images without loading models of its own. These…
- Driving native-engine generation directlyMost pipes just assemble existing pipes into a pipeline. A pipe that needs to run inference against the native (in-process) engine itself —…
- Contributing a tool tab
- Extending the image editor
- Overlays and z-index layeringEvery core modal, popover, dropdown and menu shares one open-order z-index stack ($lib/actions/overlayLayer.ts + $lib/actions/layerStack.ts)…
- Calling your plugin's backend from its page
- Keeping window shortcuts out of text fields
- Using the page header from a plugin page
- Keyboard shortcuts on a plugin page
- Using the app's UI components and Tailwind in a plugin frontendA plugin frontend is bundled on its own and cannot import $lib, but every shared UI component of the app is available through the host…
- Field components and the commit signal
- Building your plugin's frontend
- Publishing a plugin in a catalog
- Testing your plugin against a scratch databaseYour plugin's tests must never touch the application's database. scratch_database makes a throwaway one in a file of the test's temporary folder…
- Related