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.
Credentials
Section titled “Credentials”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.
Configuration
Section titled “Configuration”

| Field | Type | Default | Description |
|---|---|---|---|
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_thresholdcompares an estimate of the request size, the agent’s system message plus the prompt, againsttokenThreshold. WiththresholdDirectionset toabove, the rule matches when the estimate is at or over the threshold; withbelow, when it is under.phasematches the phase of work the agent has announced:research,plan,scaffold,build,test, ordone. Only agents that track phases (such as the platform’s flow builder) ever announce one, so outside a phased run these rules never match.defaultalways 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.
Output
Section titled “Output”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.
Example
Section titled “Example”Send short prompts to a cheap model and long prompts to a stronger one (this mirrors the “Smoke / Model routing — rule router” flow template):
- Add a Rule Model Router node and connect its Model handle to the Agent’s Model handle.
- First rule:
conditionType=token_threshold,tokenThreshold=2000,thresholdDirection=above,provider=openai,model=gpt-4o. - 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.
Limitations
Section titled “Limitations”- Order matters: put specific rules first and the
defaultrule last, because the first match wins. - When no rule matches and there is no
defaultrule, 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.
Related
Section titled “Related”- Agent, the node this one attaches to.
- Cost Model Router picks by token price instead of rules.
- Llm Model Router routes on request content with a classifier.
- Static Model and Fallback Chain Model cover the no-routing cases.
- How to route between models is the task guide.