Skip to main content

Environment variables

Langflow uses environment variables to configure certain settings. You can also import environment variables for use in your deployment, such as environment variables used by certain components in your flows.

You can set Langflow environment variables in your terminal, in .env, and with the Langflow CLI.

Precedence

If an environment variable is set in multiple places, the following hierarchy applies:

  1. Langflow CLI options override .env and terminal variables.
  2. .env overrides terminal variables.
  3. Terminal variables are used only if the variable isn't set in .env or Langflow CLI options.

For example, if you set LANGFLOW_PORT in .env and your terminal, then Langflow uses the value from .env. Similarly, if you run a Langflow CLI command with --port, Langflow uses that port number instead of the LANGFLOW_PORT in .env.

Configure environment variables

Langflow recognizes supported environment variables from the following sources:

  • Environment variables that you've set in your terminal.
  • Environment variables that you've imported from a .env file when starting Langflow or using the --env-file option in the Langflow CLI.

You can choose to use one or both sources. However, environment variables imported from a .env file take precedence over those set in your terminal.

Set environment variables in your terminal

Run the following commands to set environment variables for your current terminal session:


_10
export VARIABLE_NAME='VALUE'

When you start Langflow, it looks for environment variables that you've set in your terminal. If it detects a supported environment variable, then it automatically adopts the specified value, subject to precedence rules.

Import environment variables from a .env file

  1. If Langflow is running, quit Langflow.

  2. Create a .env file, and then open it in your preferred editor.

  3. Define Langflow environment variables in the .env file. For example:


    _30
    DO_NOT_TRACK=True
    _30
    LANGFLOW_AUTO_LOGIN=False
    _30
    LANGFLOW_AUTO_SAVING=True
    _30
    LANGFLOW_AUTO_SAVING_INTERVAL=1000
    _30
    LANGFLOW_BACKEND_ONLY=False
    _30
    LANGFLOW_BUNDLE_URLS=["https://github.com/user/repo/commit/hash"]
    _30
    LANGFLOW_CACHE_TYPE=async
    _30
    LANGFLOW_COMPONENTS_PATH=/path/to/components/
    _30
    LANGFLOW_CONFIG_DIR=/path/to/config/
    _30
    LANGFLOW_DATABASE_URL=postgresql://user:password@localhost:5432/langflow
    _30
    LANGFLOW_DEV=False
    _30
    LANGFLOW_FALLBACK_TO_ENV_VAR=False
    _30
    LANGFLOW_HEALTH_CHECK_MAX_RETRIES=5
    _30
    LANGFLOW_HOST=localhost
    _30
    LANGFLOW_LANGCHAIN_CACHE=InMemoryCache
    _30
    LANGFLOW_MAX_FILE_SIZE_UPLOAD=10000
    _30
    LANGFLOW_MAX_ITEMS_LENGTH=100
    _30
    LANGFLOW_MAX_TEXT_LENGTH=1000
    _30
    LANGFLOW_LOG_LEVEL=error
    _30
    LANGFLOW_OPEN_BROWSER=False
    _30
    LANGFLOW_PORT=7860
    _30
    LANGFLOW_REMOVE_API_KEYS=False
    _30
    LANGFLOW_SAVE_DB_IN_CONFIG_DIR=True
    _30
    LANGFLOW_SECRET_KEY=somesecretkey
    _30
    LANGFLOW_STORE=True
    _30
    LANGFLOW_STORE_ENVIRONMENT_VARIABLES=True
    _30
    LANGFLOW_SUPERUSER=adminuser
    _30
    LANGFLOW_SUPERUSER_PASSWORD=adminpass
    _30
    LANGFLOW_WORKER_TIMEOUT=60000
    _30
    LANGFLOW_WORKERS=3

    For additional examples, see the .env.example file in the Langflow repository.

  4. Save and close .env.

  5. Start Langflow with your .env file:


    _10
    python -m langflow run --env-file .env

    If your .env file isn't in the same directory, provide the path to your .env file.

On startup, Langflow imports the environment variables from your .env file, as well as any others that you set in your terminal, and then adopts their specified values.

Supported environment variables

The following table lists the environment variables supported by Langflow.

VariableFormatDefaultDescription
DO_NOT_TRACKBooleanFalseWhether to report Langflow telemetry data. If true, Langflow telemetry is disabled.
LANGFLOW_AUTO_LOGINBooleanTrueSee LANGFLOW_AUTO_LOGIN.
LANGFLOW_AUTO_SAVINGBooleanTrueEnable flow auto-saving.
LANGFLOW_AUTO_SAVING_INTERVALInteger1000Set the interval for flow auto-saving in milliseconds.
LANGFLOW_BACKEND_ONLYBooleanFalseRun only the Langflow backend service (no frontend).
LANGFLOW_BUNDLE_URLSList[String][]A list of URLs from which to load component bundles and flows. Supports GitHub URLs. If LANGFLOW_AUTO_LOGIN is enabled, flows from these bundles are loaded into the database.
LANGFLOW_CACHE_TYPEStringasyncSet the cache type for Langflow. Possible values: async, redis, memory, disk. If you set the type to redis, then you must also set the following environment variables: LANGFLOW_REDIS_HOST, LANGFLOW_REDIS_PORT, LANGFLOW_REDIS_DB, and LANGFLOW_REDIS_CACHE_EXPIRE.
LANGFLOW_COMPONENTS_PATHStringNot setPath to the directory containing custom components.
LANGFLOW_CONFIG_DIRStringVariesSet the Langflow configuration directory where files, logs, and the Langflow database are stored. Default path depends on your installation. See Flow storage and logs.
LANGFLOW_DATABASE_URLStringNot setSet the database URL for Langflow. If not provided, Langflow uses a SQLite database.
LANGFLOW_DATABASE_CONNECTION_RETRYBooleanFalseWhether to retry lost connections to the Langflow database. If true, Langflow tries to connect to the database again if the connection fails.
LANGFLOW_DB_POOL_SIZEInteger20DEPRECATED: Use LANGFLOW_DB_CONNECTION_SETTINGS instead. The number of connections to keep open in the connection pool.
LANGFLOW_DB_MAX_OVERFLOWInteger30DEPRECATED: Use LANGFLOW_DB_CONNECTION_SETTINGS instead. The number of connections to allow that can be opened beyond the pool size.
LANGFLOW_DB_CONNECT_TIMEOUTInteger30The number of seconds to wait before giving up on a lock to be released or establishing a connection to the database.
LANGFLOW_DB_CONNECTION_SETTINGSJSONNot setA JSON dictionary to centralize database connection parameters. Example: {"pool_size": 20, "max_overflow": 30}
LANGFLOW_DISABLE_TRACK_APIKEY_USAGEBooleanFalseWhether to track API key usage. If true, disables tracking of API key usage (total_uses and last_used_at) to avoid database contention under high concurrency.
LANGFLOW_ENABLE_SUPERUSER_CLIBooleanTrueAllow creation of superusers with the Langflow CLI command langflow superuser. Recommended to be disabled (false) in production for security reasons.
LANGFLOW_FALLBACK_TO_ENV_VARBooleanTrueIf 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.
LANGFLOW_FRONTEND_PATHString./frontendPath to the frontend directory containing build files. This is for development purposes only. See --frontend-path.
LANGFLOW_HEALTH_CHECK_MAX_RETRIESInteger5Set the maximum number of retries for the health check. See --health-check-max-retries.
LANGFLOW_HOSTStringlocalhostThe host on which the Langflow server will run. See --host.
LANGFLOW_LANGCHAIN_CACHEStringInMemoryCacheType of cache to use. Possible values: InMemoryCache, SQLiteCache. See --cache.
LANGFLOW_LOG_LEVELStringINFOSet the logging level for Langflow. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL.
LANGFLOW_LOG_FILEStringNot setPath to the log file. If this option isn't set, logs are written to stdout.
LANGFLOW_LOG_RETRIEVER_BUFFER_SIZEInteger10000Set the buffer size for log retrieval. Only used if LANGFLOW_ENABLE_LOG_RETRIEVAL is enabled.
LANGFLOW_MAX_FILE_SIZE_UPLOADInteger100Set the maximum file size for the upload in megabytes. See --max-file-size-upload.
LANGFLOW_MAX_ITEMS_LENGTHInteger100Maximum number of items to store and display in the visual editor. Lists longer than this will be truncated when displayed in the visual editor. Doesn't affect data passed between components nor outputs.
LANGFLOW_MAX_TEXT_LENGTHInteger1000Maximum number of characters to store and display in the visual editor. Responses longer than this will be truncated when displayed in the visual editor. Doesn't truncate responses between components nor outputs.
LANGFLOW_MCP_SERVER_ENABLEDBooleanTrueIf this option is set to False, Langflow doesn't enable the MCP server.
LANGFLOW_MCP_SERVER_ENABLE_PROGRESS_NOTIFICATIONSBooleanFalseIf this option is set to True, Langflow sends progress notifications in the MCP server.
LANGFLOW_NEW_USER_IS_ACTIVEBooleanFalseSee LANGFLOW_NEW_USER_IS_ACTIVE.
LANGFLOW_OPEN_BROWSERBooleanFalseOpen the system web browser on startup.
LANGFLOW_PORTInteger7860The port on which the Langflow server runs. The server automatically selects a free port if the specified port is in use.
LANGFLOW_PROMETHEUS_ENABLEDBooleanFalseExpose Prometheus metrics.
LANGFLOW_PROMETHEUS_PORTInteger9090Set the port on which Langflow exposes Prometheus metrics.
LANGFLOW_REDIS_CACHE_EXPIREInteger3600See LANGFLOW_CACHE_TYPE.
LANGFLOW_REDIS_DBInteger0See LANGFLOW_CACHE_TYPE.
LANGFLOW_REDIS_HOSTStringlocalhostSee LANGFLOW_CACHE_TYPE.
LANGFLOW_REDIS_PORTString6379See LANGFLOW_CACHE_TYPE.
LANGFLOW_REDIS_PASSWORDStringNot setPassword for Redis authentication when using Redis cache type.
LANGFLOW_REMOVE_API_KEYSBooleanFalseRemove API keys from the projects saved in the database.
LANGFLOW_SAVE_DB_IN_CONFIG_DIRBooleanFalseIf false (default), the Langflow database is saved in the langflow root directory. This means the database isn't shared between different virtual environments, and the database is deleted when you uninstall Langflow. If true, the database is saved in the LANGFLOW_CONFIG_DIR.
LANGFLOW_SECRET_KEYStringAutomatedSee LANGFLOW_SECRET_KEY.
LANGFLOW_STOREBooleanTrueWhether to enable the Langflow Store features.
LANGFLOW_STORE_ENVIRONMENT_VARIABLESBooleanTrueWhether to store environment variables as global variables in the database.
LANGFLOW_CREATE_STARTER_PROJECTSBooleanTrueWhether to create templates during initialization. If false, Langflow doesn't create templates, and LANGFLOW_UPDATE_STARTER_PROJECTS is treated as false.
LANGFLOW_UPDATE_STARTER_PROJECTSBooleanTrueWhether to update templates with the latest component versions when initializing after an upgrade.
LANGFLOW_SUPERUSERStringlangflowSee LANGFLOW_SUPERUSER and LANGFLOW_SUPERUSER_PASSWORD.
LANGFLOW_SUPERUSER_PASSWORDStringlangflowSee LANGFLOW_SUPERUSER and LANGFLOW_SUPERUSER_PASSWORD.
LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENTStringNot setComma-separated list of environment variables to get from the environment and store as global variables.
LANGFLOW_LOAD_FLOWS_PATHStringNot setPath to a directory containing flow JSON files to be loaded on startup. Note that this feature only works if LANGFLOW_AUTO_LOGIN is enabled.
LANGFLOW_WORKER_TIMEOUTInteger300Worker timeout in seconds.
LANGFLOW_WORKERSInteger1Number of worker processes.
LANGFLOW_SSL_CERT_FILEStringNot setPath to the SSL certificate file on the local system.
LANGFLOW_SSL_KEY_FILEStringNot setPath to the SSL key file on the local system.
LANGFLOW_SKIP_AUTH_AUTO_LOGINBooleanTrueSee LANGFLOW_AUTO_LOGIN.

Configure .env, override.conf, and tasks.json files

The following examples show how to configure Langflow using environment variables in different scenarios.

The .env file is a text file that contains key-value pairs of environment variables.

Create or edit a .env file in the root directory of your application or Langflow environment, and then add your configuration variables to the file:


_30
DO_NOT_TRACK=True
_30
LANGFLOW_AUTO_LOGIN=False
_30
LANGFLOW_AUTO_SAVING=True
_30
LANGFLOW_AUTO_SAVING_INTERVAL=1000
_30
LANGFLOW_BACKEND_ONLY=False
_30
LANGFLOW_BUNDLE_URLS=["https://github.com/user/repo/commit/hash"]
_30
LANGFLOW_CACHE_TYPE=async
_30
LANGFLOW_COMPONENTS_PATH=/path/to/components/
_30
LANGFLOW_CONFIG_DIR=/path/to/config/
_30
LANGFLOW_DATABASE_URL=postgresql://user:password@localhost:5432/langflow
_30
LANGFLOW_DEV=False
_30
LANGFLOW_FALLBACK_TO_ENV_VAR=False
_30
LANGFLOW_HEALTH_CHECK_MAX_RETRIES=5
_30
LANGFLOW_HOST=localhost
_30
LANGFLOW_LANGCHAIN_CACHE=InMemoryCache
_30
LANGFLOW_MAX_FILE_SIZE_UPLOAD=10000
_30
LANGFLOW_MAX_ITEMS_LENGTH=100
_30
LANGFLOW_MAX_TEXT_LENGTH=1000
_30
LANGFLOW_LOG_LEVEL=error
_30
LANGFLOW_OPEN_BROWSER=False
_30
LANGFLOW_PORT=7860
_30
LANGFLOW_REMOVE_API_KEYS=False
_30
LANGFLOW_SAVE_DB_IN_CONFIG_DIR=True
_30
LANGFLOW_SECRET_KEY=somesecretkey
_30
LANGFLOW_STORE=True
_30
LANGFLOW_STORE_ENVIRONMENT_VARIABLES=True
_30
LANGFLOW_SUPERUSER=adminuser
_30
LANGFLOW_SUPERUSER_PASSWORD=adminpass
_30
LANGFLOW_WORKER_TIMEOUT=60000
_30
LANGFLOW_WORKERS=3

Set environment variables for Langflow Desktop

Environment variables set in your terminal aren't automatically available to GUI-based applications like Langflow Desktop when you launch them from the Windows or macOS GUI.

For Windows, this means any GUI-based app launched from the Start menu, desktop shortcuts, or Windows Explorer.

For macOS, this means any GUI-based app launched from Finder, Spotlight, Launchpad, or the Dock.

To set environment variables for Langflow Desktop, you need to use specific commands or files, depending on your OS.

Langflow Desktop for macOS cannot automatically use variables set in your terminal, such as those in.zshrc or .bash_profile, when launched from the macOS GUI.

To make environment variables available to GUI apps on macOS, you need to use launchctl with a plist file:

  1. Create the LaunchAgents directory if it doesn't exist:


    _10
    mkdir -p ~/Library/LaunchAgents

  2. In the LaunchAgents directory, create a .plist file called dev.langflow.env.

  3. Add the following content to dev.langflow.env.plist, and then add, change, or remove Langflow environment variables as needed for your configuration.

    This example sets multiple environmental variables for all GUI apps launched from the macOS GUI.


    _21
    <?xml version="1.0" encoding="UTF-8"?>
    _21
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    _21
    <plist version="1.0">
    _21
    <dict>
    _21
    <key>Label</key>
    _21
    <string>dev.langflow.env</string>
    _21
    <key>ProgramArguments</key>
    _21
    <array>
    _21
    <string>/bin/sh</string>
    _21
    <string>-c</string>
    _21
    <string>
    _21
    launchctl setenv LANGFLOW_CONFIG_DIR /Users/your_user/custom/config &&
    _21
    launchctl setenv LANGFLOW_PORT 7860 &&
    _21
    launchctl setenv LANGFLOW_HOST localhost &&
    _21
    launchctl setenv ARIZE_API_KEY ak-...
    _21
    </string>
    _21
    </array>
    _21
    <key>RunAtLoad</key>
    _21
    <true/>
    _21
    </dict>
    _21
    </plist>

  4. Load the file with launchctl:


    _10
    launchctl load ~/Library/LaunchAgents/dev.langflow.env.plist

Search