Budget Check

A node that asks whether the model call ahead fits the policies, the budgets and, if you set one, the node's own allocation — and branches before any money is held.

6 min read

Budget Check asks whether the model call ahead would be allowed, before any money is held. When the answer is yes, the execution goes on to the call. When it is no, the execution takes the Deny branch, and the flow decides what the caller hears.

Node
Budget Check
Type
budget_check
Category
Money
Ports
  • Allow default must be connected
  • Deny deny optional
Ends the path
No

What it does

The node estimates the call of the AI Model node its chain leads to, as the hold of that call will be estimated. Then it checks the call in one of two ways, set by Budget to check.

  • Global policy, the way a new node checks. The node evaluates the policies and reads the money budgets that bind the call: those of the organization, the project, the operation and your customer. When the hold would fit, the execution leaves through Allow. When a policy refuses, or a budget has no room for the hold, it leaves through Deny with policy_denied or budget_exceeded.

  • The allocation of the node. The node first checks as above, and that refusal wins. Then it checks the call against a limit of its own for the model the chain leads to: what the calls past this node have cost, counted by their estimates, together with the hold of this call, must stay within the limit. A model with no line of its own takes the default limit, and with no default limit it passes without one. A refusal of the allocation takes Deny with budget_exceeded.

The node reads and holds nothing. Three limits are left to the model call, which checks them when it takes its hold: a budget Per operation, the Concurrent holds of a budget, and the credits of your customer. That is why AI Model has a Deny port of its own. Under load the node may also let through a call whose hold is then refused.

When the call cannot be estimated, the node lets the execution through, and the model call decides.

When to use it

  • To refuse before money is held and to choose what follows: a cheaper model through Fallback, an answer from the cache, a refusal with a code of your own through Reject Request.

  • To give one flow a share of the money for each model, apart from the budgets of the project: set the allocation of the node.

  • The budgets themselves are set on Budgets — Budgets. The node reads them, it does not replace them.

A refusal of this node sends no webhook event. operation.denied is sent when the model call itself is refused on a policy or a budget.

An execution that ends rejected after the node refused keeps the estimate of the refused call as its cost.estimated: money the refusal saved, not money spent. A Deny branch that answers without calling a model ends completed with the same estimate and no actual cost.

Settings

SettingWhat it is for
modeWhat the node checks — policy, the policies and the budgets that bind the call, or node, the same and then the allocation of the node. A new node checks policy.
windowThe period an allocation is counted in — daily, monthly or total. Read only with the allocation. Without one it is monthly.
allocationsThe lines of the allocation, one for each model — the code of the model and a limit, a decimal number written as text, such as 25.00. A model appears in one line at most. Read only with the allocation.
default_limitThe limit of a model that has no line of its own, a decimal number written as text. Optional. Without it such a model passes without a limit of the node. Read only with the allocation.

In the builder Budget to check chooses between Global policy and the allocation of the node. With the allocation chosen, Window sets the period a limit is counted in, and Add allocation adds a line: a model and its limit. The panel marks the line in force — the one of the model the node leads to. The default limit, for a model without a line, is optional.

What the allocation counts belongs to this node of this flow and to one model and window. A limit is a decimal number with a dot and no currency sign, such as 25.00.

Ports

PortThe execution leaves through it when
AllowThe call would be allowed. Required
DenyThe call is refused. Optional

When Deny has no connection, the refusal is the answer to the request: the caller gets budget_exceeded or policy_denied, and the execution ends as rejected. The publish check warns about such a node — Ports and branching.

Output

When the call would be allowed, the node leaves what it read:

JSON
{
  "allowed": true,
  "available": "24.50000000",
  "would_reserve": "0.00057600",
  "node_budget": "within_limit",
  "node_budget_limit": "25.00000000",
  "node_budget_spent": "3.12000000"
}
  • would_reserve is the hold the call would take, and available is what is left in the tightest budget that binds the call. available is absent when no budget binds it.

  • The three node_budget fields are there only with the allocation. node_budget says how the allocation was read: within the limit here, and otherwise that the model has no line or that the call could not be estimated.

When the node refuses, denied_by says who refused — the policies and budgets, or the allocation of the node:

JSON
{ "allowed": false, "error_code": "budget_exceeded", "denied_by": "policy" }
JSON
{ "allowed": false, "error_code": "node_budget_exceeded", "denied_by": "node_allocation" }

A Condition on the Deny branch reads them by the path nodes.<key>.output.denied_by, where <key> is the key of this node in the flow. The code the caller gets for a refused allocation is budget_exceeded; node_budget_exceeded stays in the output and the trace.

Errors

The settings of the node are checked when the flow is validated and when it is published.

In the API an entry of issues names such a check in params.detail; its code is invalid_node_config.

CheckMessage in the builder
budget_check_unsupported_mode“{node}” uses a budget mode that does not exist.
budget_check_unsupported_window“{node}” uses a budget window that does not exist.
budget_check_invalid_default_limitThe default limit of “{node}” is not a valid amount.
budget_check_allocations_not_listThe allocations of “{node}” must be a list.
budget_check_needs_allocation“{node}” needs at least one allocation or a default limit.
budget_check_allocation_not_object“{node}” has an allocation that is not an object.
budget_check_allocation_without_model“{node}” has an allocation with no model chosen.
budget_check_duplicate_model“{node}” allocates to {model} twice.
budget_check_invalid_limitThe limit for {model} on “{node}” is not a valid amount.
budget_check_unknown_modelThe model {model} is not in the catalogue.

The place of the node is checked too: it leads to exactly one AI Model — The money chain.

Example

  • Request — Default → Budget Check
  • Budget Check — Allow → AI Model
  • AI Model — Success → Return Response
  • Budget Check — Deny → Reject Request

Budget Check asks whether the call fits. When it does, AI Model holds the money and calls the model. When it does not, Reject Request ends the request with the code its author chose, and no money was held.

Built from openapi b070e1f, sdk contract 5cc7055, php ae4a53b, node 84bc62d