Skip to main content

Global Variables

warning

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 > Variables and Secrets.

Docusaurus themed imageDocusaurus themed image

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

For more on variables in HuggingFace Spaces, see Managing Secrets.

warning

All Credential Global Variables are encrypted and accessible only by you.

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.

tip

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.

Specify variables as a comma-separated list (e.g., "VARIABLE1, VARIABLE2") or a JSON-encoded string (e.g., '["VARIABLE1", "VARIABLE2"]').

The default list of variables includes:

  • 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

Hi, how can I help you?