Contributing a plan limit kind
A 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 upload ship with core. A plugin adds kinds of its
own with a limit_kinds: section; the plan editor's "Add limit" picker, the users list
columns, the user's usage view and the refusal all render from the kind, so a kind needs
no frontend code.
On this page
yaml
limit_kinds:
- key: credits.monthly # must be namespaced: <plugin>.<name>
label: Credits per month
short_label: Credits # optional, for usage rows and columns
description: Each submit spends one credit
value_type: count # bytes | count | usd
unit: per month # optional editor suffix
window: month # none (a level) | day | month
enforce_at: [submit] # submit and/or upload
ledger: true # count one event per accepted submit
measure_handler: limits.measure # optional when ledger: true
applies_handler: limits.applies # optional, narrow where the kind is asked
incoming_handler: limits.incoming # optional, what one request adds
refusal_code: credits_exhausted # optional, default <key>_exceeded
refusal_message: "You have used {used} of {limit} credits. {contact}"
admin_only_values: false # optional; usd kinds hide numbers from users by default
warn_at: 0.8measure_handler(context: MeasureContext) -> Usage | numberreturns the user's usage forcontext.user_idonly.context.window_startandcontext.window_endbound the current day or month (midnight in the instance timezone, an admin setting, UTC by default);context.eventsreads and writes this kind's ledger for the user (total(),record(units, ref_id),refund(ref_id)). Keep it fast: it runs on every submit or upload the kind applies to.ledger: truemakes core record one event per accepted submit (incoming_handlercan change the units) and refund it when the run is cancelled before it started or fails with no output. Without ameasure_handlerthe usage is the ledger total in the window. A ledger kind needs adayormonthwindow; events are kept 40 days. To count something else, callLimitEvents.record(user_id, kind, units, ref_id)yourself.applies_handler(request: AdmissionRequest) -> boolseespoint,user_id,incoming_bytes(uploads; the total of every file in the request),item_bytes(uploads; the size of each file, orNonewhen the caller passed only a total),engine,backend_idandpreset_id(submits).incoming_handler(request) -> number | None:Nonemeans unknown, and the kind refuses whenused >= limit; a number refuses whenused + incoming > limit.refusal_messagemay use{label},{used},{limit},{resets}and{contact}(the admin's contact line).
What the host guarantees#
- A refusal is one HTTP 403
limit_exceededcarrying the kind, its code, usage, limit and reset time. Running work is never stopped and nothing is ever deleted for the user. - Admins are exempt while "Admins are exempt" is on (the default); their usage is still measured.
- Disabling the plugin removes its kinds. Plans keep the limits, shown as inactive and never enforced, and they apply again when the plugin is back.
- A kind whose measure raises is skipped for that request (logged), never enforced as zero.