Global Variables
This page may contain outdated information. It will be updated as soon as possible.
Global Variables are a useful feature of Langflow, allowing you to define reusable variables accessed from any Text field in your project.
TL;DR
- Global Variables are reusable variables accessible from any Text field in your project.
- To create one, click the 🌐 button in a Text field and then + Add New Variable.
- Define the Name, Type, and Value of the variable.
- Click Save Variable to create it.
- All Credential Global Variables are encrypted and accessible only by you.
- Set
LANGFLOW_STORE_ENVIRONMENT_VARIABLES
totrue
in your.env
file to add all variables inLANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
to your user's Global Variables.
Create and Add a Global Variable
To create and add a global variable, click the 🌐 button in a Text field, and then click + Add New Variable.
Text fields are where you write text without opening a Text area, and are identified with the 🌐 icon.
For example, to create an environment variable for the OpenAI component:
- In the OpenAI API Key text field, click the 🌐 button, then Add New Variable.
- Enter
openai_api_key
in the Variable Name field. - Paste your OpenAI API Key (
sk-...
) in the Value field. - Select Credential for the Type.
- Choose OpenAI API Key in the Apply to Fields field to apply this variable to all fields named OpenAI API Key.
- Click Save Variable.
You now have a openai_api_key
global environment variable for your Langflow project.
Subsequently, clicking the 🌐 button in a Text field will display the new variable in the dropdown.
You can also create global variables in Settings > Variables and Secrets.
To view and manage your project's global environment variables, visit Settings > Variables and Secrets.
Configure Environment Variables in your .env file
Setting LANGFLOW_STORE_ENVIRONMENT_VARIABLES
to true
in your .env
file (default) adds all variables in LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
to your user's Global Variables.
These variables are accessible like any other Global Variable.
To prevent this behavior, set LANGFLOW_STORE_ENVIRONMENT_VARIABLES
to false
in your .env
file.
You can specify variables to get from the environment by listing them in LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT
, as a comma-separated list (e.g., VARIABLE1, VARIABLE2
).
The default list of variables includes the ones below and more:
- ANTHROPIC_API_KEY
- ASTRA_DB_API_ENDPOINT
- ASTRA_DB_APPLICATION_TOKEN
- AZURE_OPENAI_API_KEY
- AZURE_OPENAI_API_DEPLOYMENT_NAME
- AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME
- AZURE_OPENAI_API_INSTANCE_NAME
- AZURE_OPENAI_API_VERSION
- COHERE_API_KEY
- GOOGLE_API_KEY
- GROQ_API_KEY
- HUGGINGFACEHUB_API_TOKEN
- OPENAI_API_KEY
- PINECONE_API_KEY
- SEARCHAPI_API_KEY
- SERPAPI_API_KEY
- UPSTASH_VECTOR_REST_URL
- UPSTASH_VECTOR_REST_TOKEN
- VECTARA_CUSTOMER_ID
- VECTARA_CORPUS_ID
- VECTARA_API_KEY