State Variables

> Save values during a flow and read them later -- useful for passing data between distant parts of your flow.

State variables let you store a value at one point in your flow and retrieve it at another point, without needing to wire them directly together.

For new routes and functions, prefer Local Variables. Local variables are typed, listed in the detail panel, and generate stable Get / Set nodes. State variables are still useful when the variable name must be computed dynamically at runtime.

Set Variable

The Set Variable node stores a value under a name.

| Input | Type | Description | |-------|------|-------------| | value | Any | The value to store | | variableName | String | The name to store it under (default: myVar) |

After this node runs, the value is available to any Get Variable node later in the same flow execution.

Get Variable

The Get Variable node retrieves a previously stored value.

| Input | Type | Description | |-------|------|-------------| | variableName | String | The name of the variable to retrieve |

| Output | Type | Description | |--------|------|-------------| | value | Any | The stored value |

When to use state variables

State variables are useful when:

  • Long flows -- You need a value from the beginning of the flow deep inside a nested branch.
  • Loops -- You want to accumulate a result across loop iterations.
  • Multiple branches -- You set a value in one branch and read it in another that runs later.

Example: dynamic runtime key

1. Build a variable name from request data, for example cart_${userId}. 2. Use Set Variable with that computed name. 3. Use Get Variable with the same computed name later in the run.

For simple data passing, prefer wiring node outputs directly to inputs. For named typed state, prefer Local Variables. Use state variables when direct wiring is not practical and the name must be dynamic.

Variables and secrets

State variables take priority over secrets with the same name. If you set a variable called MY_KEY in your flow, any {MY_KEY} placeholder will resolve to the variable value instead of the secret.

What's next?

| Topic | Description | |-------|-------------| | Local Variables | Typed variables declared on a route or function | | Visual Editor | Builder interface reference | | Secrets | Store persistent values across flows | | Logic Nodes | Conditional branching |