The Budget Block
estimate_usd— the author’s pre-run cost estimate, calculated by summingquoteStep()across all planned steps. Must be a non-negative number and must not exceedcap_usd.cap_usd— the hard spending ceiling. Any run whose live quote exceeds this value is rejected before a single provider call is made.
Enforcement Points
Budget enforcement happens at four distinct points in the Zap lifecycle: 1. CLI mock runs always quote $0.00 When running without--live, Zap executes in mock mode. All provider steps return deterministic zero-cost outputs. The planner still builds a full plan and prints the quote, but no real money is spent and no budget check is applied.
2. CLI live plans reject over-budget runs
When --live is passed, the planner calls planZapRun() to expand all steps (including video.extend repeats), sums per-step costs, and calls assertWithinBudget(). If the total quote exceeds cap_usd, the run is aborted with an error before any provider is contacted:
assertWithinBudget() check server-side, before the run job is enqueued for provider submission. This means a malformed client request cannot bypass the cap by skipping the CLI check.
4. Provider adapters attach observed cost to each run step
After a step completes, the provider adapter records the actual cost charged by the provider and attaches it to the run step record. This observed cost feeds into post-run reconciliation and is visible in the run history dashboard.
Model Rates
The Zap planner uses a built-in rate table to estimate costs. Rates are either per-request (flat fee regardless of duration) or per-second (multiplied byduration_s):
Models not in this table (including
mock-* models and any custom model strings) return a quote of $0.00. The stitch and keyframes step kinds are always local and always quote $0.00.
Cost Calculation
The total estimated cost for a recipe is:quoteStep works as follows:
- If the step is
stitchorkeyframes→$0.00(local, no provider cost) - If the model has a
perRequestrate → that flat rate - If the model has a
perSecondrate →rate × duration_s(defaults to 1 second ifduration_sis omitted) - If the model is unknown →
$0.00
fal-ai/flux/dev image step and two 5-second seedance-2-0-260128 video steps:
