docs/docs/Develop/configuration-global-variables.mdx
import Icon from "@site/src/components/icon"; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Use global variables to store and reuse credentials and generic values across all of your flows. Global variables are typically used by components in flow, and you can use them in any field with the <Icon name="Globe" aria-hidden="true"/> global variable icon.
In contrast, environment variables, like LANGFLOW_PORT or LANGFLOW_LOG_LEVEL, are generally for broader settings that configure how Langflow runs.
However, Langflow can also source global variables from environment variables.
Langflow stores global variables in its internal database, and it encrypts the values using a secret key.
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. However, Generic variables aren't masked in the visual editor, whereas Credential variables are masked. Session ID fields don't accept Credential (masked) 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 <Icon name="Globe" aria-hidden="true"/> Globe icon.
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.
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 <Icon name="Trash2" aria-hidden="true"/> Delete.
The global variable is deleted from the database.
Langflow can source custom global variables from your runtime environment. For information about how Langflow detects and applies environment variables, see Langflow environment variables.
Langflow automatically generates global variables based on constants.py if it detects any matching environment variables.
For example, if you set OPENAI_API_KEY in your runtime environment, Langflow automatically generates a global variable using that value.
You can declare additional variables in LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT.
For example, LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=WATSONX_PROJECT_ID,WATSONX_API_KEY creates global variables named WATSONX_PROJECT_ID and WATSONX_API_KEY in Langflow's database.
Then, you can use these variables wherever they are needed in your component settings.
If you installed Langflow locally, set LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT in your Langflow .env file:
Create or edit your Langflow .env file.
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:
# Option 1: Comma-separated string (no spaces)
LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=VARIABLE1,VARIABLE2
# Option 2: JSON list format
LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=["VARIABLE1", "VARIABLE2"]
Replace VARIABLE1,VARIABLE2 with your additional variables that you want Langflow to source from the environment, such as CUSTOM_API_KEY,INTERNAL_SERVICE_URL or ["CUSTOM_API_KEY", "INTERNAL_SERVICE_URL"].
Save and close the file.
Start Langflow with the .env file:
uv run langflow run --env-file .env
Alternatively, you can set environment variables directly in the command line:
VARIABLE1="VALUE1" VARIABLE2="VALUE2" uv run langflow run --env-file .env
The command-line variables override matching variables 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, there are two ways that you can set LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT:
On the command line:
docker run -it --rm \
-p 7860:7860 \
-e LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT="VARIABLE1,VARIABLE2" \
-e VARIABLE1="VALUE1" \
-e VARIABLE2="VALUE2" \
langflowai/langflow:latest
In your .env file:
docker run -it --rm \
-p 7860:7860 \
--env-file .env \
-e VARIABLE1="VALUE1" \
-e VARIABLE2="VALUE2" \
langflowai/langflow:latest
The list in LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT includes only the variable names.
You must ensure that these environment variables are defined in your Docker environment, such as with -e or otherwise.
After starting Langflow, go to your Langflow Settings to confirm that the variables were created.
Only the Name and Value are taken from the environment. You can edit the variables in your Langflow Settings if you want to configure additional options, such as the Apply To Fields option.
Global variables sourced from the environment are assigned the Credential type, which masks the values in the visual editor. However, Langflow automatically encrypts all global variables stored in the database.
By default, Langflow stores global variables encrypted in its database at langflow.db.
When running Langflow in Kubernetes, you can switch to storing global variables in Kubernetes Secrets, to keep sensitive credentials out of the Langflow database entirely.
When Kubernetes secrets are enabled, each user's global variables are stored in a dedicated Opaque Secret in the langflow namespace, named after the user's UUID.
Credentials are stored with a credential_ prefix on the secret key.
:::tip
If you're deploying with the Langflow Helm chart, the chart creates a ServiceAccount automatically. Skip the ServiceAccount block above, and set subjects[0].name in the RoleBinding to the name of the Helm-generated ServiceAccount instead. To find the ServiceAccount name, run kubectl get serviceaccount -n langflow.
:::
Create a manifest for the ServiceAccount, Role, and RoleBinding resources, and save it as langflow-rbac.yaml:
apiVersion: v1
kind: ServiceAccount
metadata:
name: langflow
namespace: langflow
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: langflow-secret-manager
namespace: langflow
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: langflow-secret-manager
namespace: langflow
subjects:
- kind: ServiceAccount
name: langflow
namespace: langflow
roleRef:
kind: Role
name: langflow-secret-manager
apiGroup: rbac.authorization.k8s.io
Apply the resources to your cluster:
kubectl apply -f langflow-rbac.yaml
Set serviceAccountName and the LANGFLOW_VARIABLE_STORE environment variable in your Deployment:
spec:
serviceAccountName: langflow
containers:
- name: langflow
image: langflowai/langflow:latest
env:
- name: LANGFLOW_VARIABLE_STORE
value: "kubernetes"
To apply the updated Deployment, and then confirm the pod found the service account, run:
kubectl apply -f langflow-deployment.yaml
kubectl describe pod -n langflow -l app.kubernetes.io/name=langflow | grep "Service Account"
Log in to Langflow, navigate to Settings > Global Variables, and then create a global variable.
To confirm that Langflow created a corresponding Kubernetes Secret, run:
kubectl get secrets -n langflow
The output should include a Secret named after the user's UUID.
Inspect the Secret's keys to confirm your variable was stored, replacing YOUR_USER_ID with the user's UUID:
kubectl get secret uuid-YOUR_USER_ID -n langflow -o jsonpath='{.data}' | python3 -m json.tool
Credential-type variables appear with a credential_ prefix.
Generic-type variables use the variable name directly as the key.
:::warning
Do not read or modify Secret values directly with kubectl. Editing Secrets outside of Langflow can cause variables to become unreadable.
:::
If you want to explicitly prevent Langflow from sourcing global variables from the environment, set LANGFLOW_STORE_ENVIRONMENT_VARIABLES=False in your .env file.
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.
For example, assume you have the following Langflow .env configuration, and your flow has a component that expects a WATSONX_API_KEY global variable:
LANGFLOW_FALLBACK_TO_ENV_VAR=True
WATSONX_PROJECT_ID=your_project_id
WATSONX_API_KEY=your_api_key
When you run the flow, if there is no global variable named WATSONX_API_KEY, Langflow looks for an environment variable named WATSONX_API_KEY.
In this example, Langflow uses the WATSONX_API_KEY value from the .env to run the flow.