Skip to content
Docs

Rule Model Router

Rule Model Router chooses which model serves an Agent run using deterministic rules. Rules are evaluated top to bottom and the first match wins, so the decision costs nothing and is the same every time for the same input. You find it on the node picker’s AI shelf.

The node has a single output handle, Model. Connect it to the Agent’s Model handle. An agent reads one model node, so this node and the other model providers are alternatives rather than a stack.

Each rule (and each of its fallback targets) can name its own API key secret: a secret holding the key for that row’s provider. A row takes a secret, never a saved connection; name a connection on the Agent’s own credential field instead. Without a secret, the rule’s provider uses the workspace key (see AI models) and then the server’s key, so set one whenever a rule routes to a provider your workspace holds no key for.

The Rule Model Router node's settings form, with the fields described below
The Rule Model Router node's settings form, with the fields described below
FieldTypeDefaultDescription
Rules (rules)list (required) — The ordered routing rules, each mapping a condition (such as a token threshold) to a provider+model; the first matching rule wins.
Condition type (rules[].conditionType)string (required) —
Token threshold (rules[].tokenThreshold)integer (optional) —
Threshold direction (rules[].thresholdDirection)string (optional) —
Phase (rules[].phase)string (optional) —
Provider (rules[].provider)string (optional) openai
Model (rules[].model)string (optional) —
API key (rules[].apiKey)string (optional) —
Base URL (rules[].baseUri)string (optional) —
Temperature (rules[].temperature)number (optional) —
Max tokens (rules[].maxTokens)integer (optional) —
Fallbacks (rules[].fallbacks)list (optional) —

Each rule maps a condition to a provider and model, with optional temperature and maxTokens overrides. Three condition types exist:

  • token_threshold compares an estimate of the request size, the agent’s system message plus the prompt, against tokenThreshold. With thresholdDirection set to above, the rule matches when the estimate is at or over the threshold; with below, when it is under.
  • phase matches the phase of work the agent has announced: research, plan, scaffold, build, test, or done. Only agents that track phases (such as the platform’s flow builder) ever announce one, so outside a phased run these rules never match.
  • default always matches. End your list with one so every request finds a model.

A rule can also carry its own ordered fallbacks list. When the rule matches, the agent runs the rule’s model and fails over through the fallbacks on rate limits, overloads, and server errors, exactly as a Fallback Chain Model would. Routing and failover are independent choices; a rule without fallbacks selects a single model.

The node emits no output of its own and never runs as a step in the flow. Each answer it gives the agent is the matched rule’s provider and model, followed by that rule’s fallback targets when it has any. The agent asks when a run starts, and once per phase when the router is attached to a phase-tracking agent.

Send short prompts to a cheap model and long prompts to a stronger one (this mirrors the “Smoke / Model routing — rule router” flow template):

  1. Add a Rule Model Router node and connect its Model handle to the Agent’s Model handle.
  2. First rule: conditionType = token_threshold, tokenThreshold = 2000, thresholdDirection = above, provider = openai, model = gpt-4o.
  3. Second rule: conditionType = default, provider = openai, model = gpt-4o-mini.

Prompts estimated at 2000 tokens or more run on gpt-4o; everything else takes the cheap default.

  • Order matters: put specific rules first and the default rule last, because the first match wins.
  • When no rule matches and there is no default rule, the first rule’s model is used as written, even if its condition did not match.
  • The router sees the request’s estimated size and the announced phase, not the prompt’s content. To route on what the request is about, use Llm Model Router.