max_tokens). A spend cap turns that
price into a rule: a run whose cost floor is above the cap never starts.
spend.mts
The rules, on the local engine
maxCostUsd is the run’s budget over metered spend, in USD, at the
catalog’s list prices.
- Before the run. A cost floor above the cap makes
run()throwNikaOperationErrorwith codeNIKA-1709(status2). - A cloud model the catalog cannot price is refused before any call
too, with or without
maxCostUsd: the engine cannot bound spend it cannot meter, and an unpriced model never counts as$0. The engine names no code for this refusal, socodeis the SDK’srun_refused,statusis 3 and the message startsprice unknown:. The engine your app starts has no terminal to ask;nika runin an interactive terminal asks once for a cost review instead. - During the run. The call that crosses the cap completes and counts,
nothing new starts, unstarted tasks are cancelled, and
run.result()resolvesfailedwithNIKA-1704and no outputs. - Local and mock models are never blocked. They are unpriced, not free:
the settlement reports them as
unpriced. - Without
maxCostUsd, theceiling:in the project’snika.yamlapplies;maxCostUsdwins over it. - The floor is an output-token estimate (
max_tokens× output price). Prompt tokens are not priced statically, and a wide wave of parallel tasks can overshoot by up to that wave’s spend before the crossing is seen:max_parallel:narrows that window.
model replaces only the default
The model option replaces the workflow’s envelope model: only. A task that
pins its own infer.model, and a child workflow it invokes, keep their models:
model: 'mock/echo' does not make those calls offline. Keep maxCostUsd: 0
next to it, so a priced pin is refused (NIKA-1709) instead of spending. A
local-model pin still runs.
On nika serve
There is no per-run maxCostUsd over HTTP: the SDK refuses it with
NikaCompatibilityError (capability: 'runOptions') instead of dropping it.
The server bounds spend itself:
nika serve --run-cost-ceiling <USD>caps every job your code submits: 1 USD by default;noneremoves the cap explicitly.- A job whose floor exceeds it is admitted and then settles
failedwitherror.codeNIKA-1709;run()does not throw. - A schedule carries its own
maxCostUsd, which must be positive (Schedules).
nika check
reads them.
Which version is this?
Which version is this?
Results
How a budget stop reads in the settlement.
CI gate
Rehearse on the mock model before a protected job spends.