Global variables
Global variables let you store and reuse generic input values and credentials across your Langflow projects. You can use a global variable in any text input field that displays the Globe icon.
Langflow stores global variables in its internal database, and encrypts the values using a secret key.
Environment variables versus global variables
Environment variables like LANGFLOW_PORT
or LANGFLOW_LOG_LEVEL
configure how Langflow runs, while global variables are user-defined values stored in Langflow's database for reuse across flows, like OPENAI_API_KEY
.
Some environment variables are automatically converted to global variables when Langflow starts. For more information, see Default environment variables.
To add custom global variables, see Add custom global variables from the environment.
Create a global variable
To create a new global variable, follow these steps.
-
In the Langflow header, click your profile icon, and then select Settings.
-
Click Global Variables.
-
Click Add New.
-
In the Create Variable dialog, enter a name for your variable in the Variable Name field.
-
Optional: Select a Type for your global variable. The available types are Generic (default) and Credential.
Langflow encrypts both Generic and Credential type global variables. The difference is in how the variables are displayed in the visual editor:
- Global variables of the Generic type are displayed in a standard input field with no masking.
- Global variables of the Credential type are hidden in the visual editor and entered in a password-style input field that masks the value. This type isn't allowed in session ID fields where the value is exposed.
All default environment variables and variables sourced from the environment using
LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
are automatically set as Credential type. For more information, see Default environment variables. -
Enter the Value for your global variable.
-
Optional: Use the Apply To Fields menu to select one or more fields that you want Langflow to automatically apply your global variable to. For example, if you select OpenAI API Key, Langflow automatically applies the variable to any OpenAI API Key field.
-
Click Save Variable.
You can now select your global variable from any text input field that displays the Globe icon.
Edit a global variable
-
In the Langflow header, click your profile icon, and then select Settings.
-
Click Global Variables.
-
Click on the global variable you want to edit.
-
In the Update Variable dialog, you can edit the following fields: Variable Name, Value, and Apply To Fields.
-
Click Update Variable.
Delete a global variable
Deleting a global variable permanently deletes the value from the database. Flows that reference the deleted global variable will fail.
-
In the Langflow header, click your profile icon, and then select Settings.
-
Click Global Variables.
-
Click the checkbox next to the global variable that you want to delete.
-
Click Delete.
The global variable is deleted from the database.
Add custom global variables from the environment
You can use the LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
environment variable to source custom global variables from your runtime environment.
All global variables sourced from the environment are automatically set as Credential type global variables.
Langflow's default global variables are already included in this list and are automatically sourced when detected.
You can extend this list by setting LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
with your additional variables.
- Local
- Docker
If you installed Langflow locally, you must define the LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
environment variable in a .env
file.
-
Create a
.env
file and open it in your preferred editor. -
Add the
LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
environment variable as follows:You can specify the variables either as a comma-separated string with no spaces, or as a JSON list:
_10# Option 1: Comma-separated string (no spaces)_10LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=VARIABLE1,VARIABLE2_10_10# Option 2: JSON list format_10LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=["VARIABLE1", "VARIABLE2"]Replace
VARIABLE1,VARIABLE2
with your additional variables that you want Langflow to source from the environment, such asCUSTOM_API_KEY,INTERNAL_SERVICE_URL
or["CUSTOM_API_KEY", "INTERNAL_SERVICE_URL"]
. These are added to the default list of variables that Langflow already monitors, which includes common API keys likeOPENAI_API_KEY
,ANTHROPIC_API_KEY
, andGOOGLE_API_KEY
. -
Save and close the file.
-
Start Langflow with the
.env
file:_10uv run langflow run --env-file .envAlternatively, you can set environment variables directly in the command line:
_10VARIABLE1="VALUE1" VARIABLE2="VALUE2" uv run langflow run --env-file .envThe command-line variables will override any values in the
.env
file. Expose your environment variables to Langflow in a manner that best suits your own environment. -
Confirm that Langflow successfully sourced the global variables from the environment:
-
In the Langflow header, click your profile icon, and then select Settings.
-
Click Global Variables, and then make sure that your environment variables appear in the Global Variables list.
-
If you're using Docker, you can pass LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
directly from the command line or from a .env
file.
To pass LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
directly from the command line:
_10docker run -it --rm \_10 -p 7860:7860 \_10 -e LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT="VARIABLE1,VARIABLE2" \_10 -e VARIABLE1="VALUE1" \_10 -e VARIABLE2="VALUE2" \_10 langflowai/langflow:latest
To pass LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
from a .env
file:
_10docker run -it --rm \_10 -p 7860:7860 \_10 --env-file .env \_10 -e VARIABLE1="VALUE1" \_10 -e VARIABLE2="VALUE2" \_10 langflowai/langflow:latest
When adding global variables from the environment, the following limitations apply:
-
You can only source the Name and Value from the environment.
To add additional parameters, such as the Apply To Fields parameter, you must edit the global variables in your Langflow Settings.
-
Global variables that you add from the environment always have the Credential type.
Disallow global variables from the environment
If you want to explicitly prevent Langflow from sourcing global variables from the environment, set LANGFLOW_STORE_ENVIRONMENT_VARIABLES=False
in your .env
file.
Use environment variables for missing global variables
If you want to automatically set fallback values for your global variables to environment variables, set LANGFLOW_FALLBACK_TO_ENV_VAR=True
in your .env
file. When this setting is enabled, if a global variable isn't found, Langflow attempts to use an environment variable with the same name as a backup.
Global variables automatically set by environment variables
Langflow automatically detects and converts some environment variables into global variables of the type Credential, which are applied to the specific fields in components that require them.
The supported variables are listed in constants.py.
Configure global variable and environment variable handling
These environment variables configure how Langflow handles the relationship between environment variables and global variables.
Variable | Format | Default | Description |
---|---|---|---|
LANGFLOW_STORE_ENVIRONMENT_VARIABLES | Boolean | True | Whether to store environment variables as global variables in the database. |
LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT | String | Not set | Comma-separated list of environment variables to get from the environment and store as global variables. |
LANGFLOW_FALLBACK_TO_ENV_VAR | Boolean | True | If enabled, global variables set in your Langflow Settings can use an environment variable with the same name if Langflow can't retrieve the variable value from the global variables. |