Skip to main content

Global Variables

info

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 to true in your .env file to add all variables in LANGFLOW_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:

  1. In the OpenAI API Key text field, click the 🌐 button, then Add New Variable.
  2. Enter openai_api_key in the Variable Name field.
  3. Paste your OpenAI API Key (sk-...) in the Value field.
  4. Select Credential for the Type.
  5. Choose OpenAI API Key in the Apply to Fields field to apply this variable to all fields named OpenAI API Key.
  6. 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.

tip

You can also create global variables in Settings > Global Variables.

To view and manage your project's global environment variables, visit Settings > Global Variables.

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.

info

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

Precautions

Global variables are stored in the database, and their values are protected by encryption using a secret key. To preserve access to your global variables and avoid losing them, you should take a few precautions:

  1. Keep your secret key safe: Even if your database is secure, it won’t be of much use if you can't decrypt the values. Ideally, you can set your own secret key using the LANGFLOW_SECRET_KEY environment variable. If you don't provide a custom value for the secret key, one will be generated randomly and saved in the Langflow installation directory.

  2. We use SQLite as the default database, and Langflow saves the database file in the installation directory. To ensure the security of your data, it’s a good practice to regularly back up this file. If needed, you can also change the database location by setting the LANGFLOW_SAVE_DB_IN_CONFIG_DIR environment variable to true and configuring LANGFLOW_CONFIG_DIR to point to a directory of your choice. Alternatively, you can opt to use an external database such as PostgreSQL, in which case these configurations are no longer necessary.

For your convenience, if you’re running Langflow directly on your system or in a virtual environment via a pip installation, you can set these values by providing Langflow with a .env file containing these environment variables, using the following command:


_10
langflow run --env-file .env

If you’re running Langflow in a Docker container, you can set these values by providing Langflow with:


_10
docker run \
_10
--privileged \
_10
--user 1000:0 \
_10
-p 7860:7860 \
_10
-e LANGFLOW_SECRET_KEY=<YOUR_SECRET_KEY_VALUE> \
_10
-e LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true \
_10
-e LANGFLOW_CONFIG_DIR=/app/container_path \
_10
-v $(PWD)/your_path:/app/container_path \
_10
langflowai/langflow:latest

or


_10
docker run \
_10
--privileged \
_10
--user 1000:0 \
_10
-p 7860:7860 \
_10
--env-file .env \
_10
-v $(PWD)/your_path:/app/container_path \
_10
langflowai/langflow:latest

Hi, how can I help you?